From d3ac14dc007108f453375fe90f056be82290ecf4 Mon Sep 17 00:00:00 2001 From: andros21 Date: Tue, 19 Sep 2023 19:02:59 +0200 Subject: [PATCH] feat(ytdl-mpv): no hard-coded sleep when switching between chapters of different tracks, await until switch with a safer counter for loop break --- bin/mpvctl | 8 +++++--- bin/ytdl-mpv | 9 +++++++-- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/bin/mpvctl b/bin/mpvctl index 3cc825b..16e3ec2 100755 --- a/bin/mpvctl +++ b/bin/mpvctl @@ -65,9 +65,10 @@ positional arguments: stop always stop playback toggle toggle playback track jump to playlist track number - ctrack) get current track playlist number - chapters) get chapter list (if available) - chapter) jump to track chapter number + ctrack get current track playlist number + chapters get chapter list (if available) + chapter jump to track chapter number + cchapter get current chapter (-1 if no chapters) optional arguments: -h, --help print this help @@ -360,6 +361,7 @@ case "$1" in ctrack) _getProperty 'playlist-pos' ;; chapters) _getChapters "$2" "$3" ;; chapter) _setProperty 'set_property' 'chapter' "$2" ;; + cchapter) _getProperty 'chapter' | sed 's/null/-1/' ;; -h | --help) shift; _usage; exit 0 ;; *) shift; _usage; exit 1 ;; esac diff --git a/bin/ytdl-mpv b/bin/ytdl-mpv index 0905f91..7ebc951 100755 --- a/bin/ytdl-mpv +++ b/bin/ytdl-mpv @@ -376,10 +376,15 @@ _editMenuChapters() { if [ "$(_ytdl_mpvctl ctrack)" -eq "$stn" ]; then _ytdl_mpvctl chapter "$ch" else + local i + i=0 _ytdl_mpvctl toggle _ytdl_mpvctl track "$stn" - sleep 3 - _ytdl_mpvctl chapter "$ch" + until [ "$(_ytdl_mpvctl cchapter)" -eq "$ch" ]; do + _ytdl_mpvctl chapter "$ch" + [[ $i -gt 1000000 ]] && break + i=$((i+1)) + done _ytdl_mpvctl toggle fi fi