patches-mpvacious/force-japanese.patch

111 lines
5.9 KiB
Diff
Raw Normal View History

2024-07-22 19:44:14 +00:00
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
2024-07-22 19:51:49 +00:00
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')
2024-07-22 19:44:14 +00:00
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
2024-07-22 21:19:52 +00:00
+++ mpvacious-patched/utils/force-japanese.lua 2024-07-22 17:19:11.258733910 -0400
@@ -0,0 +1,75 @@
2024-07-22 19:44:14 +00:00
+local assdraw = require 'mp.assdraw'
+
+local preferred_alangs = {"jpn", "ja", "japanese"}
+local preferred_slangs = {"jpn", "ja", "japanese"}
+
+local phrases = {
+ "日本語オンリーで行こう!英語なんて大嫌い!",
+ "これで完全に日本語モードです!",
+ "やったね!日本語が優先されました!",
+ "日本語が一番!英語は嫌いだ!",
+ "今、完全に日本語です!英語はなし!"
+}
+
2024-07-22 21:19:52 +00:00
+local function find_japanese_audio(tracks)
+ local regex = ".*[Jj][Pp].*"
+ 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
2024-07-22 19:44:14 +00:00
+
2024-07-22 21:19:52 +00:00
+local function find_japanese_sub(tracks)
+ local regex = ".*[Jj][Pp].*"
+ for _, track in ipairs(tracks) do
+ if track.type == "sub" and string.match(track.title or "", regex) then
+ return track.id
2024-07-22 19:44:14 +00:00
+ end
+ end
2024-07-22 21:19:52 +00:00
+ return nil
+end
2024-07-22 19:44:14 +00:00
+
2024-07-22 21:19:52 +00:00
+local function find_best_match(tracks, preferred_langs, track_type)
+ for _, lang in ipairs(preferred_langs) do
2024-07-22 19:44:14 +00:00
+ for _, track in ipairs(tracks) do
2024-07-22 21:19:52 +00:00
+ if track.type == track_type and track.lang == lang then
+ return track.id
2024-07-22 19:44:14 +00:00
+ end
+ end
+ end
2024-07-22 21:19:52 +00:00
+ 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")
2024-07-22 19:44:14 +00:00
+
+ 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)
+ 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