patches-mpvacious/force-japanese.patch
2024-07-24 23:39:05 -04:00

228 lines
9.6 KiB
Diff

Binary files mpvacious/.git/index and mpvacious-patched/.git/index differ
diff -ruN mpvacious/.git/logs/HEAD mpvacious-patched/.git/logs/HEAD
--- mpvacious/.git/logs/HEAD 2024-07-22 15:31:00.086132886 -0400
+++ mpvacious-patched/.git/logs/HEAD 2024-07-22 15:30:14.821186211 -0400
@@ -1 +1 @@
-0000000000000000000000000000000000000000 aa86597d5e65c9c40b12841a945be7a3cd0fb7b3 hashirama <noroi_harau@tutanota.com> 1721676660 -0400 clone: from https://github.com/Ajatt-Tools/mpvacious.git
+0000000000000000000000000000000000000000 aa86597d5e65c9c40b12841a945be7a3cd0fb7b3 hashirama <noroi_harau@tutanota.com> 1721676614 -0400 clone: from https://github.com/Ajatt-Tools/mpvacious.git
diff -ruN mpvacious/.git/logs/refs/heads/master mpvacious-patched/.git/logs/refs/heads/master
--- mpvacious/.git/logs/refs/heads/master 2024-07-22 15:31:00.086132886 -0400
+++ mpvacious-patched/.git/logs/refs/heads/master 2024-07-22 15:30:14.821186211 -0400
@@ -1 +1 @@
-0000000000000000000000000000000000000000 aa86597d5e65c9c40b12841a945be7a3cd0fb7b3 hashirama <noroi_harau@tutanota.com> 1721676660 -0400 clone: from https://github.com/Ajatt-Tools/mpvacious.git
+0000000000000000000000000000000000000000 aa86597d5e65c9c40b12841a945be7a3cd0fb7b3 hashirama <noroi_harau@tutanota.com> 1721676614 -0400 clone: from https://github.com/Ajatt-Tools/mpvacious.git
diff -ruN mpvacious/.git/logs/refs/remotes/origin/HEAD mpvacious-patched/.git/logs/refs/remotes/origin/HEAD
--- mpvacious/.git/logs/refs/remotes/origin/HEAD 2024-07-22 15:31:00.086132886 -0400
+++ mpvacious-patched/.git/logs/refs/remotes/origin/HEAD 2024-07-22 15:30:14.821186211 -0400
@@ -1 +1 @@
-0000000000000000000000000000000000000000 aa86597d5e65c9c40b12841a945be7a3cd0fb7b3 hashirama <noroi_harau@tutanota.com> 1721676660 -0400 clone: from https://github.com/Ajatt-Tools/mpvacious.git
+0000000000000000000000000000000000000000 aa86597d5e65c9c40b12841a945be7a3cd0fb7b3 hashirama <noroi_harau@tutanota.com> 1721676614 -0400 clone: from https://github.com/Ajatt-Tools/mpvacious.git
Binary files mpvacious/.git/objects/pack/pack-020c392851862423cb8bce6808896d817fd39b29.idx and mpvacious-patched/.git/objects/pack/pack-020c392851862423cb8bce6808896d817fd39b29.idx differ
Binary files mpvacious/.git/objects/pack/pack-020c392851862423cb8bce6808896d817fd39b29.pack and mpvacious-patched/.git/objects/pack/pack-020c392851862423cb8bce6808896d817fd39b29.pack differ
Binary files mpvacious/.git/objects/pack/pack-020c392851862423cb8bce6808896d817fd39b29.rev and mpvacious-patched/.git/objects/pack/pack-020c392851862423cb8bce6808896d817fd39b29.rev differ
Binary files mpvacious/.git/objects/pack/pack-7da0665222863ab22efcaeebb25779cd86662677.idx and mpvacious-patched/.git/objects/pack/pack-7da0665222863ab22efcaeebb25779cd86662677.idx differ
Binary files mpvacious/.git/objects/pack/pack-7da0665222863ab22efcaeebb25779cd86662677.pack and mpvacious-patched/.git/objects/pack/pack-7da0665222863ab22efcaeebb25779cd86662677.pack differ
Binary files mpvacious/.git/objects/pack/pack-7da0665222863ab22efcaeebb25779cd86662677.rev and mpvacious-patched/.git/objects/pack/pack-7da0665222863ab22efcaeebb25779cd86662677.rev differ
diff -ruN mpvacious/main.lua mpvacious-patched/main.lua
--- mpvacious/main.lua 2024-07-22 15:31:00.090132616 -0400
+++ mpvacious-patched/main.lua 2024-07-22 15:51:08.536987877 -0400
@@ -1 +1,2 @@
+require("utils.force-japanese")
require('subs2srs')
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-22 18:54:10.283179193 -0400
@@ -0,0 +1,80 @@
+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 phrase = phrases[math.random(#phrases)]
+ 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
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