Skip to content

Commit

Permalink
增加切换音轨脚本
Browse files Browse the repository at this point in the history
  • Loading branch information
x1ao4 committed Apr 6, 2024
1 parent c06506c commit 1c00450
Show file tree
Hide file tree
Showing 2 changed files with 90 additions and 0 deletions.
45 changes: 45 additions & 0 deletions en/cycleAudio-keybinds.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
-- Whether to show the embedded audio track title by default
local show_title = false

function toggle_show_title()
show_title = not show_title
end

mp.add_key_binding("6", "toggle_show_title", toggle_show_title)

function cycle_audio_tracks()
mp.command("cycle audio")
local audio_info = mp.get_property_native("track-list")
local media = mp.get_property("user-data/plex/playing-media")
local displayTitle = "None"

for _, track in pairs(audio_info) do
if track["type"] == "audio" and track["selected"] then
local ff_index = track["ff-index"]

for audio in string.gmatch(media, "{(.-)}") do
local index = string.match(audio, "\"index\":(%d+)")
local id = string.match(audio, "\"id\":\"(.-)\"")
local title, display
if show_title then
if not track["title"] then
display = string.match(audio, "\"displayTitle\":\"(.-)\"")
else
title = track["title"]
end
else
display = string.match(audio, "\"displayTitle\":\"(.-)\"")
end

if ff_index ~= 0 and index and (title or display) and tonumber(index) == ff_index then
displayTitle = title or display
break
end
end
end
end

mp.osd_message("Current Audio Track: " .. displayTitle)
end

mp.add_key_binding("y", "cycle_audio_tracks", cycle_audio_tracks)
45 changes: 45 additions & 0 deletions zh/cycleAudio-keybinds.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
-- 是否默认显示内置音轨标题
local show_title = false

function toggle_show_title()
show_title = not show_title
end

mp.add_key_binding("6", "toggle_show_title", toggle_show_title)

function cycle_audio_tracks()
mp.command("cycle audio")
local audio_info = mp.get_property_native("track-list")
local media = mp.get_property("user-data/plex/playing-media")
local displayTitle = ""

for _, track in pairs(audio_info) do
if track["type"] == "audio" and track["selected"] then
local ff_index = track["ff-index"]

for audio in string.gmatch(media, "{(.-)}") do
local index = string.match(audio, "\"index\":(%d+)")
local id = string.match(audio, "\"id\":\"(.-)\"")
local title, display
if show_title then
if not track["title"] then
display = string.match(audio, "\"displayTitle\":\"(.-)\"")
else
title = track["title"]
end
else
display = string.match(audio, "\"displayTitle\":\"(.-)\"")
end

if ff_index ~= 0 and index and (title or display) and tonumber(index) == ff_index then
displayTitle = title or display
break
end
end
end
end

mp.osd_message("当前音轨: " .. displayTitle)
end

mp.add_key_binding("y", "cycle_audio_tracks", cycle_audio_tracks)

0 comments on commit 1c00450

Please sign in to comment.