Skip to content

Commit

Permalink
feat(ytdl-mpv): no hard-coded sleep when switching
Browse files Browse the repository at this point in the history
between chapters of different tracks, await until switch
with a safer counter for loop break
  • Loading branch information
andros21 committed Oct 12, 2023
1 parent a424f66 commit d3ac14d
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
8 changes: 5 additions & 3 deletions bin/mpvctl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
9 changes: 7 additions & 2 deletions bin/ytdl-mpv
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit d3ac14d

Please sign in to comment.