mirror of
https://github.com/ksyasuda/mpv-youtube-queue.git
synced 2024-11-22 03:19:54 -08:00
Fix move video (#17)
* fix the move_video function and add some script-messages * add gitignore
This commit is contained in:
parent
fa2014acd6
commit
392b39c7fc
2
.gitignore
vendored
Normal file
2
.gitignore
vendored
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
test.sh
|
||||||
|
.git/*
|
@ -165,14 +165,14 @@ local function open_channel_in_browser()
|
|||||||
open_url_in_browser(current_video.channel_url)
|
open_url_in_browser(current_video.channel_url)
|
||||||
end
|
end
|
||||||
|
|
||||||
-- local function _print_internal_playlist()
|
local function _print_internal_playlist()
|
||||||
-- local count = mp.get_property_number("playlist-count")
|
local count = mp.get_property_number("playlist-count")
|
||||||
-- print("Playlist contents:")
|
print("Playlist contents:")
|
||||||
-- for i = 0, count - 1 do
|
for i = 0, count - 1 do
|
||||||
-- local uri = mp.get_property(string.format("playlist/%d/filename", i))
|
local uri = mp.get_property(string.format("playlist/%d/filename", i))
|
||||||
-- print(string.format("%d: %s", i, uri))
|
print(string.format("%d: %s", i, uri))
|
||||||
-- end
|
end
|
||||||
-- end
|
end
|
||||||
|
|
||||||
local function toggle_print()
|
local function toggle_print()
|
||||||
if destroyer ~= nil then
|
if destroyer ~= nil then
|
||||||
@ -320,19 +320,20 @@ function YouTubeQueue.reorder_queue(from_index, to_index)
|
|||||||
-- Check if the provided indices are within the bounds of the video_queue
|
-- Check if the provided indices are within the bounds of the video_queue
|
||||||
if from_index > 0 and from_index <= #video_queue and to_index > 0 and
|
if from_index > 0 and from_index <= #video_queue and to_index > 0 and
|
||||||
to_index <= #video_queue then
|
to_index <= #video_queue then
|
||||||
-- Swap the videos between the two provided indices in the video_queue
|
-- move the video from the from_index to to_index in the internal playlist.
|
||||||
|
-- playlist-move is 0-indexed
|
||||||
|
if from_index < to_index and to_index == #video_queue then
|
||||||
|
mp.commandv("playlist-move", from_index - 1, to_index)
|
||||||
|
elseif from_index < to_index then
|
||||||
|
mp.commandv("playlist-move", to_index - 1, from_index - 1)
|
||||||
|
else
|
||||||
|
mp.commandv("playlist-move", from_index - 1, to_index - 1)
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Remove from from_index and insert at to_index into YouTubeQueue
|
||||||
local temp_video = video_queue[from_index]
|
local temp_video = video_queue[from_index]
|
||||||
table.remove(video_queue, from_index)
|
table.remove(video_queue, from_index)
|
||||||
table.insert(video_queue, to_index, temp_video)
|
table.insert(video_queue, to_index, temp_video)
|
||||||
|
|
||||||
-- swap the videos in the mpv playlist
|
|
||||||
-- playlist-move is 0-indexed and works the opposite of what is expected
|
|
||||||
-- ex: playlist-move 1 2 will move the video at index 2 to index 1
|
|
||||||
mp.commandv("loadfile", video_queue[to_index].video_url, "append")
|
|
||||||
mp.commandv("playlist-move", #video_queue, to_index - 1)
|
|
||||||
mp.commandv("playlist-move", to_index - 1, from_index - 1)
|
|
||||||
mp.commandv("playlist-move", from_index - 1, #video_queue)
|
|
||||||
mp.commandv("playlist-remove", #video_queue)
|
|
||||||
else
|
else
|
||||||
print_osd_message("Invalid indices for reordering. No changes made.",
|
print_osd_message("Invalid indices for reordering. No changes made.",
|
||||||
MSG_DURATION, style.error)
|
MSG_DURATION, style.error)
|
||||||
@ -627,7 +628,12 @@ mp.register_event("end-file", on_end_file)
|
|||||||
mp.register_event("track-changed", on_track_changed)
|
mp.register_event("track-changed", on_track_changed)
|
||||||
mp.register_event("playback-restart", on_playback_restart)
|
mp.register_event("playback-restart", on_playback_restart)
|
||||||
|
|
||||||
|
-- keep for backwards compatibility
|
||||||
mp.register_script_message("add_to_queue", YouTubeQueue.add_to_queue)
|
mp.register_script_message("add_to_queue", YouTubeQueue.add_to_queue)
|
||||||
mp.register_script_message("print_queue", YouTubeQueue.print_queue)
|
mp.register_script_message("print_queue", YouTubeQueue.print_queue)
|
||||||
|
|
||||||
|
mp.register_script_message("add_to_youtube_queue", YouTubeQueue.add_to_queue)
|
||||||
mp.register_script_message("toggle_youtube_queue", toggle_print)
|
mp.register_script_message("toggle_youtube_queue", toggle_print)
|
||||||
|
mp.register_script_message("print_internal_playlist", _print_internal_playlist)
|
||||||
|
mp.register_script_message("reorder_youtube_queue", YouTubeQueue.reorder_queue)
|
||||||
-- }}}
|
-- }}}
|
||||||
|
Loading…
Reference in New Issue
Block a user