mirror of
https://gitea.phreedom.club/localhost_frssoft/funkwlmpv
synced 2024-11-24 02:49:19 +02:00
Compare commits
No commits in common. "ea4dc5eeca5bec7f60e796267e1c66def5102308" and "10ccbecd9e70ec057fb85bb4c6f76b7ee789a78c" have entirely different histories.
ea4dc5eeca
...
10ccbecd9e
|
@ -7,12 +7,10 @@ from shutil import get_terminal_size
|
||||||
import mpv
|
import mpv
|
||||||
import time
|
import time
|
||||||
import sys
|
import sys
|
||||||
import re
|
|
||||||
|
|
||||||
fzf = FzfPrompt()
|
fzf = FzfPrompt()
|
||||||
|
|
||||||
player = mpv.MPV(cache=True, demuxer_max_bytes=25*1024*1024,
|
player = mpv.MPV(cache=True, demuxer_max_bytes=25*1024*1024)
|
||||||
scripts='src/mpv_scripts/mpv_cache.lua')
|
|
||||||
player.ytdl = False # Prevent attempts load track with yt-dlp
|
player.ytdl = False # Prevent attempts load track with yt-dlp
|
||||||
player.volume = get_config('mpv_volume')
|
player.volume = get_config('mpv_volume')
|
||||||
player.prefetch_playlist = get_config('prefetch_playlist')
|
player.prefetch_playlist = get_config('prefetch_playlist')
|
||||||
|
@ -27,15 +25,11 @@ class player_fw_storage:
|
||||||
@logger.catch
|
@logger.catch
|
||||||
def track_url_to_uuid(listen_url=None):
|
def track_url_to_uuid(listen_url=None):
|
||||||
'''Attempt get uuid from track listen url or current playing url'''
|
'''Attempt get uuid from track listen url or current playing url'''
|
||||||
hex = '[0-9a-fA-F]+'
|
|
||||||
find_uuid = f'{hex}-{hex}-{hex}-{hex}-{hex}'
|
|
||||||
|
|
||||||
if listen_url:
|
if listen_url:
|
||||||
uuid = re.findall(find_uuid, listen_url)
|
uuid = listen_url.split(r'/')[-2]
|
||||||
else:
|
else:
|
||||||
uuid = re.findall(find_uuid, player.stream_open_filename)
|
uuid = player.stream_open_filename.split(r'/')[-2]
|
||||||
|
return uuid
|
||||||
return uuid[0]
|
|
||||||
|
|
||||||
|
|
||||||
if track_activity_history:
|
if track_activity_history:
|
||||||
|
|
|
@ -1,50 +0,0 @@
|
||||||
local utils = require 'mp.utils'
|
|
||||||
local msg = require 'mp.msg'
|
|
||||||
local options = require 'mp.options'
|
|
||||||
|
|
||||||
|
|
||||||
function sleep(n)
|
|
||||||
os.execute("sleep " .. tonumber(n))
|
|
||||||
end
|
|
||||||
|
|
||||||
|
|
||||||
function createDir(dirname)
|
|
||||||
os.execute("mkdir -p -m 711 " .. dirname)
|
|
||||||
end
|
|
||||||
|
|
||||||
|
|
||||||
function file_exists(name)
|
|
||||||
local f = io.open(name, "r")
|
|
||||||
return f ~= nil and io.close(f)
|
|
||||||
end
|
|
||||||
|
|
||||||
|
|
||||||
function get_url_host(s)
|
|
||||||
return (s.."/"):match("://(.-)/")
|
|
||||||
end
|
|
||||||
|
|
||||||
|
|
||||||
function make_cache_track(url)
|
|
||||||
find_uuid = "%x+-%x+-%x+-%x+-%x+"
|
|
||||||
uuid = string.sub(url, string.find(url, find_uuid))
|
|
||||||
host = get_url_host(url)
|
|
||||||
cache_path_file = 'cache/' .. host .. '/' .. uuid .. ''
|
|
||||||
if false == file_exists(cache_path_file) then
|
|
||||||
createDir('cache/' .. host .. '/')
|
|
||||||
msg.verbose('Caching ' .. cache_path_file .. '')
|
|
||||||
os.execute('curl -s "' .. url .. '" -o "' .. cache_path_file .. '"')
|
|
||||||
mp.set_property("stream-open-filename", cache_path_file)
|
|
||||||
else
|
|
||||||
msg.verbose('Already cached ' .. cache_path_file .. '')
|
|
||||||
mp.set_property("stream-open-filename", cache_path_file)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
|
|
||||||
mp.add_hook("on_load", 11, function()
|
|
||||||
msg.verbose('reusable cache hook activated')
|
|
||||||
local url = mp.get_property("stream-open-filename", "")
|
|
||||||
if true == (url:find("https?://") == 1) then
|
|
||||||
make_cache_track(url)
|
|
||||||
end
|
|
||||||
end)
|
|
Loading…
Reference in New Issue