Skip Navigation
mpv

MPV command line video player

  • Pyradion, internet radio TUI client, with recording functionality, written in Python

    cross-posted from: https://lemmy.world/post/8393990

    > https://gitlab.com/christosangel/pyradion > > Through the menus, the user can : > > - Select directly a station from the Favorites list (which is configurable). > > - Select a random station out of this list of Favorite stations. > > - Select a tag to pick a station from. > > - Select to pick a station from All Stations. > > - Select a random station out of this list of #tag stations. > > - ❌ Quit pyradion. > > --- > #### Recording > > Recording a radio stream in pyradion can be done easily, just by hitting r or R. > > !record.png > > The user will be notified through the status line of the recording taking place, and of the output file name. > > Editing the pyradion.config file, the user will be able to define output audio file directory. > > If the title is available by the stream, the file will take its name by it. > > If title is Not Available, the file will take a date/time for name. > > #### Output File Format > > In order for recording to work for mpv, output file format must be the same with stream format. > > Therefore stream format is recognised, and passed to the output file (e.g. mp3, ogg, aac). > > --- > > This project shares more or less the same logic with a previous project in Bash: > > https://gitlab.com/christosangel/radion > > although with this Python script some more features are available. > > > > ___ > > >

    0
  • My MPV lua script isn't reading my script-opts file. Why?

    Edit: I don't know why but specifying the filename of the script-opts file made it work even though the basenames are the same.

    Change:

    From:

    -- Define a table with default options local o = { memory_usage_percentage = 80, reserved_memory_gb = 6 }

    -- Read the options from the script-opts file options.read_options(o)

    -- Print the read options for debugging purposes msg.info("memory_usage_percentage: " .. o.memory_usage_percentage) msg.info("reserved_memory_gb: " .. o.reserved_memory_gb)

    To:

    -- Define a table with default options local opts = { memory_usage_percentage = 80, reserved_memory_gb = 6 }

    -- Read the options from the script-opts file (require 'mp.options').read_options(opts, "demuxer-max-bytes")

    -- Print the read options for debugging purposes msg.info("memory_usage_percentage: " .. opts.memory_usage_percentage) msg.info("reserved_memory_gb: " .. opts.reserved_memory_gb)

    Original post: I am making a lua script to adjust buffer size dynamically based on available ram. The script is working with the hardcoded values: memory_usage_percentage = 80, reserved_memory_gb = 6 but it is not reading the new values from my script-opts file. Do you see why?

    cat /home/cmysmiaczxotoy/.config/mpv/script-opts/demuxer-max-bytes.conf

    memory_usage_percentage=70 reserved_memory_gb=8

    cat /home/cmysmiaczxotoy/.config/mpv/scripts/demuxer-max-bytes.lua (Now edited with fix)

    -- Require the necessary modules local mp = require 'mp' local msg = require 'mp.msg'

    -- Define a table with default options local opts = { memory_usage_percentage = 80, reserved_memory_gb = 6 }

    -- Read the options from the script-opts file (require 'mp.options').read_options(opts, "demuxer-max-bytes")

    -- Print the read options for debugging purposes msg.info("memory_usage_percentage: " .. opts.memory_usage_percentage) msg.info("reserved_memory_gb: " .. opts.reserved_memory_gb)

    local function is_windows() return package.config:sub(1,1) == '\\' end

    local function set_memory_properties(free_mem_kib, total_mem_kib) -- Calculate the percentage of the total memory in KiB local allowed_mem_kib = total_mem_kib * (opts.memory_usage_percentage / 100) -- Convert reserved memory from GB to KiB local reserved_mem_kib = opts.reserved_memory_gb * 1024 * 1024 -- Calculate the amount of memory to use, leaving the reserved memory free local mem_to_use_kib = allowed_mem_kib - (total_mem_kib - free_mem_kib - reserved_mem_kib)

    -- Apply various checks and calculations to mem_to_use_kib if mem_to_use_kib > free_mem_kib - reserved_mem_kib then mem_to_use_kib = free_mem_kib - reserved_mem_kib end if mem_to_use_kib < 0 then mem_to_use_kib = free_mem_kib - reserved_mem_kib end if mem_to_use_kib < 0 then mem_to_use_kib = 1024 end

    -- Convert to bytes and round to nearest integer local mem_to_use_bytes = math.floor(mem_to_use_kib * 1024)

    -- Set demuxer-max-bytes to the calculated value mp.set_property("demuxer-max-bytes", tostring(mem_to_use_bytes)) mp.msg.info("Set demuxer-max-bytes to: " .. mem_to_use_bytes .. " bytes")

    -- Set cache-related properties mp.set_property("cache", "yes") mp.set_property("cache-pause", "yes") mp.set_property("force-seekable", "yes") mp.set_property("demuxer-readahead-secs", "30") end

    -- Function to gather memory info on Windows local function get_memory_info_windows() local ps_script = 'Get-CimInstance Win32_OperatingSystem | ' .. 'ForEach-Object { $.FreePhysicalMemory, $.TotalVisibleMemorySize }' local handle = io.popen('powershell -NoProfile -Command "' .. ps_script .. '"', 'r') local free_mem_kib = handle:read("*l") local total_mem_kib = handle:read("*l") handle:close()

    return tonumber(free_mem_kib), tonumber(total_mem_kib) end

    -- Function to gather memory info on Linux local function get_memory_info_linux() local total_mem_kib = 0 local free_mem_kib = 0 local meminfo = io.open("/proc/meminfo", "r") if meminfo then for line in meminfo:lines() do local key, value = line:match("(%w+):%s+(%d+)") if key == "MemAvailable" then free_mem_kib = tonumber(value) elseif key == "MemTotal" then total_mem_kib = tonumber(value) end end meminfo:close() end

    return free_mem_kib, total_mem_kib end

    -- This hook runs at the start of file loading mp.register_event("start-file", function() local free_mem_kib, total_mem_kib

    if is_windows() then free_mem_kib, total_mem_kib = get_memory_info_windows() else free_mem_kib, total_mem_kib = get_memory_info_linux() end

    if total_mem_kib > 0 then set_memory_properties(free_mem_kib, total_mem_kib) else mp.msg.error("Could not determine total memory.") end end)

    0
  • Radion, an internet radio CLI client, written in Bash.

    cross-posted from: https://lemmy.world/post/7130971

    cross-posted from: https://lemmy.world/post/7130937

    radion is an internet radio CLI client, written in Bash.

    https://gitlab.com/christosangel/radion

    Radion can be costumized as far as the station selecting program is concerned. The user can choose between:

    • read

    !read

    • fzf

    !fzf

    • rofi

    !rofi

    • dmenu

    !dmenu

    ---

    Update: Introduced new feature: costumizing prompt text for fzf dmenu and rofi.

    --- Update: Recording functionality added, with the use of another (you guessed it) bash script

    !icy

    Also options in read as Preferred selector are also case insensitive.

    Any feedback is appreciated!

    0
  • Script: Get MPV watch history from watch_later dir. Numbered selector to pick file to play

    cross-posted from: https://lemmy.world/post/1594575

    > This script will get MPV watch history from files watch_later dir and display them in reverse order of watch. The list is numbered and a prompt for a number will play the desired file in MPV > > Need line "write-filename-in-watch-later-config=yes" in mpv.conf > Deps rg (ripgrep) > > > #!/usr/bin/env bash > # Return mpv watch history oldest to newest. > # Need line "write-filename-in-watch-later-config=yes" in mpv.conf > # Deps rg > > watch_later_dir="$HOME/.config/mpv/watch_later/" > > SAVEIFS=$IFS > IFS=$'\n' > > if [ ! -d "$watch_later_dir" ]; then > echo "Specified dir doesn't exist: $watch_later_dir" > echo "Set var watch_later_dir to your watch later dir" > echo "also, mpv.conf should have line \"write-filename-in-watch-later-config=yes\"" > exit 1 > fi > > watch_later_files="$(find "$watch_later_dir" -type f -printf "%T@ %p\n" | sort | sed 's/^\([0-9]\+\.[0-9]\+\) //')" > > file_count=$(find "$watch_later_dir" -type f | wc -l) > > if [ "$file_count" -eq 0 ]; then > echo "no files found in \"$watch_later_dir\"" > exit 1 > fi > > watch_later_files=($watch_later_files) > > filepaths_not_echoed="$(for (( i=0; i<${#watch_later_files[@]}; i++ )) > do > cat "${watch_later_files[$i]}" | rg -o --color=never '(/|http).*' > done)" > > filepaths_not_echoed=($filepaths_not_echoed) > > # Reverse the order of array > length=${#filepaths_not_echoed[@]} > for ((i=0; i<length/2; i++)); do > temp="${filepaths_not_echoed[i]}" > filepaths_not_echoed[i]="${filepaths_not_echoed[length-i-1]}" > filepaths_not_echoed[length-i-1]="$temp" > done > > filepaths="$(for (( i=0; i<${#watch_later_files[@]}; i++ )) > do > echo -n "$(( $i - $file_count +1 )) " | sed 's/^-//' > cat "${watch_later_files[$i]}" | rg -o --color=never '/.*' > done)" > > #echo "$filepaths" | perl -pe 's/^(\d+ ).*\//$1/g' | rg \ > echo "$filepaths" | sed -E 's/^([0-9]+ ).*\//\1/g' | rg \ > --colors 'match:none' \ > --colors 'match:fg:0,200,0' \ > --colors 'match:bg:0,0,0' \ > --colors 'match:style:bold' \ > "[^0-9 ].*" > > IFS=$SAVEIFS > > read -p "Enter number to play " selection > > echo "${filepaths_not_echoed[$selection]}" > > setsid >/dev/null 2>&1 </dev/null \ > mpv "${filepaths_not_echoed[$selection]}" 2>&1 >/dev/null & > >

    0
1 Active user