Skip to content

Commit

Permalink
shortcuts/mp3: wrap ~/.local/bin/yd
Browse files Browse the repository at this point in the history
  • Loading branch information
tylerbrazier committed Oct 12, 2024
1 parent 0527a68 commit 499b3a6
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 64 deletions.
2 changes: 1 addition & 1 deletion local/bin/yd
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ ask_cover_url() {
}

run_ytdl() {
cmd="$BIN --restrict-filenames --add-metadata"
cmd="python $BIN --restrict-filenames --add-metadata"
[ "$A_OR_V" = a ] && cmd="$cmd -x --audio-format mp3"
[ "$USE_THUMBNAIL" -eq 1 ] && cmd="$cmd --embed-thumbnail"
if [ "$IS_PLAYLIST" -eq 1 ]; then
Expand Down
64 changes: 1 addition & 63 deletions shortcuts/mp3
Original file line number Diff line number Diff line change
@@ -1,69 +1,7 @@
#!/bin/sh
# /~https://github.com/termux/termux-widget
# Download a youtube video as an mp3 and add cover art

YTDL_BIN="$HOME/.local/bin/yt-dlp"

if [ ! -f "$YTDL_BIN" ]; then
echo "No $YTDL_BIN" >&2
exit 1
fi

printf "Video URL: "
read -r v_url
[ -z "$v_url" ] && exit 1

printf "Use the video's thumbnail? "
read -r use_thumbnail
case "$use_thumbnail" in
[Yy]*) use_thumbnail=1;;
*) use_thumbnail=;;
esac

if [ -z "$use_thumbnail" ]; then
printf "Cover URL (jpg): "
read -r c_url
[ -z "$c_url" ] && exit 1

o="'%(title)s.tmp.%(ext)s'"
else
o="'%(title)s.%(ext)s'"
fi

cmd="python3 $YTDL_BIN \
--restrict-filenames \
-x --audio-format mp3 \
--add-metadata -o $o"
[ -n "$use_thumbnail" ] && cmd="$cmd --embed-thumbnail"
cmd="$cmd '$v_url'"
echo "$cmd"
eval "$cmd" || exit 1

if [ -z "$use_thumbnail" ]; then
f="$(basename ./*.tmp.mp3)"

if [ ! -f "$f" ]; then
echo "Couldn't find the downloaded file; f=$f" >&2
exit 1
fi

cmd="curl -o cover.jpg '$c_url'"
echo "$cmd"
eval "$cmd" || exit 1

cmd="ffmpeg -i $f -i cover.jpg \
-map 0:0 -map 1:0 \
-c copy -id3v2_version 3 \
-metadata:s:v title=cover \
-metadata:s:v comment='Cover (front)' \
$(echo "$f" | sed 's/.tmp.mp3$/.mp3/')"
echo "$cmd"
eval "$cmd" || exit 1

cmd="rm cover.jpg $f"
echo "$cmd"
eval "$cmd"
fi
/bin/sh "$HOME"/.local/bin/yd

printf "Press Enter..."
read -r _

0 comments on commit 499b3a6

Please sign in to comment.