true randomness
This commit is contained in:
parent
1f1aea6e95
commit
c6700e7474
|
@ -113,3 +113,116 @@ diff -ruN mpvacious/utils/force-japanese.lua mpvacious-patched/utils/force-japan
|
||||||
+if not mp.get_property_native("idle") then
|
+if not mp.get_property_native("idle") then
|
||||||
+ select_tracks()
|
+ select_tracks()
|
||||||
+end
|
+end
|
||||||
|
diff -ruN mpvacious/utils/force-japanese.lua mpvacious-patched/utils/force-japanese.lua
|
||||||
|
--- mpvacious/utils/force-japanese.lua 1969-12-31 20:00:00.000000000 -0400
|
||||||
|
+++ mpvacious-patched/utils/force-japanese.lua 2024-07-24 23:36:19.838359390 -0400
|
||||||
|
@@ -0,0 +1,109 @@
|
||||||
|
+local assdraw = require 'mp.assdraw'
|
||||||
|
+
|
||||||
|
+local preferred_alangs = {"jpn", "ja", "japanese"}
|
||||||
|
+local preferred_slangs = {"jpn", "ja", "japanese"}
|
||||||
|
+mp.command("set sid no")
|
||||||
|
+
|
||||||
|
+local phrases = {
|
||||||
|
+ "日本語オンリーで行こう!",
|
||||||
|
+ "これで完全に日本語モードです!",
|
||||||
|
+ "やったね!日本語が優先されました!",
|
||||||
|
+ "日本語が一番!",
|
||||||
|
+ "今、完全に日本語です!",
|
||||||
|
+ "日本語オンリー!",
|
||||||
|
+ "日本語モードに切り替えました!",
|
||||||
|
+ "日本語大革命!",
|
||||||
|
+ "完全に日本語オンリー!",
|
||||||
|
+ "日本語オンリーで生き抜く!",
|
||||||
|
+ "日本語の力で世界を征服!",
|
||||||
|
+ "新しい時代は日本語オンリー!",
|
||||||
|
+ "日本語オンリー!世界統一!",
|
||||||
|
+ "日本語オンリー!新しいスタート!",
|
||||||
|
+ "日本語オンリー!未来へ!",
|
||||||
|
+}
|
||||||
|
+
|
||||||
|
+local function find_japanese_audio(tracks)
|
||||||
|
+ local regex = ".*([Jj][Pp]|[Jj]a).*"
|
||||||
|
+ for _, track in ipairs(tracks) do
|
||||||
|
+ if track.type == "audio" and string.match(track.title or "", regex) then
|
||||||
|
+ return track.id
|
||||||
|
+ end
|
||||||
|
+ end
|
||||||
|
+ return nil
|
||||||
|
+end
|
||||||
|
+
|
||||||
|
+local function find_japanese_sub(tracks)
|
||||||
|
+ local regex = ".*([Jj][Pp]|[Jj]a).*"
|
||||||
|
+ for _, track in ipairs(tracks) do
|
||||||
|
+ if track.type == "sub" and string.match(track.title or "", regex) then
|
||||||
|
+ return track.id
|
||||||
|
+ end
|
||||||
|
+ end
|
||||||
|
+ return nil
|
||||||
|
+end
|
||||||
|
+
|
||||||
|
+
|
||||||
|
+local function find_best_match(tracks, preferred_langs, track_type)
|
||||||
|
+ for _, lang in ipairs(preferred_langs) do
|
||||||
|
+ for _, track in ipairs(tracks) do
|
||||||
|
+ if track.type == track_type and track.lang == lang then
|
||||||
|
+ return track.id
|
||||||
|
+ end
|
||||||
|
+ end
|
||||||
|
+ end
|
||||||
|
+ return nil
|
||||||
|
+end
|
||||||
|
+
|
||||||
|
+function select_tracks()
|
||||||
|
+ local tracks = mp.get_property_native("track-list")
|
||||||
|
+ local selected_aid = find_japanese_audio(tracks) or find_best_match(tracks, preferred_alangs, "audio")
|
||||||
|
+ local selected_sid = find_japanese_sub(tracks) or find_best_match(tracks, preferred_slangs, "sub")
|
||||||
|
+
|
||||||
|
+ if selected_aid then
|
||||||
|
+ mp.set_property("aid", selected_aid)
|
||||||
|
+ mp.add_timeout(3, show_phrase)
|
||||||
|
+ end
|
||||||
|
+
|
||||||
|
+ if selected_sid then
|
||||||
|
+ mp.set_property("sid", selected_sid)
|
||||||
|
+ mp.add_timeout(3, show_phrase)
|
||||||
|
+ else
|
||||||
|
+ mp.set_property("sid", "no")
|
||||||
|
+ mp.command("no-osd set sid no")
|
||||||
|
+ end
|
||||||
|
+end
|
||||||
|
+
|
||||||
|
+
|
||||||
|
+function show_phrase()
|
||||||
|
+ local f = io.open("/dev/urandom", "rb")
|
||||||
|
+ local random_bytes = f:read(4)
|
||||||
|
+ f:close()
|
||||||
|
+
|
||||||
|
+ local random_number = 0
|
||||||
|
+ for i = 1, #random_bytes do
|
||||||
|
+ random_number = random_number * 256 + string.byte(random_bytes, i)
|
||||||
|
+ end
|
||||||
|
+
|
||||||
|
+ -- Convert the random number to a float between 0 and 1
|
||||||
|
+ local random_float = random_number / 4294967296.0
|
||||||
|
+
|
||||||
|
+ -- Scale the random float to the range of the phrase table
|
||||||
|
+ local phrase_index = math.floor(random_float * #phrases) + 1
|
||||||
|
+
|
||||||
|
+ local phrase = phrases[phrase_index]
|
||||||
|
+
|
||||||
|
+ local ass = assdraw.ass_new()
|
||||||
|
+ ass:append("{\\an9\\fs20\\bord1\\shad0\\c&HFFFFFF&\\3c&H000000&}")
|
||||||
|
+ ass:append(phrase)
|
||||||
|
+ mp.set_osd_ass(0, 0, ass.text)
|
||||||
|
+ mp.add_timeout(2, function() mp.set_osd_ass(0, 0, "") end)
|
||||||
|
+end
|
||||||
|
+
|
||||||
|
+
|
||||||
|
+
|
||||||
|
+mp.register_event("file-loaded", select_tracks)
|
||||||
|
+
|
||||||
|
+-- Ensure the phrase shows up when MPV is not in idle mode
|
||||||
|
+if not mp.get_property_native("idle") then
|
||||||
|
+ select_tracks()
|
||||||
|
+end
|
Loading…
Reference in a new issue