Differences

This shows you the differences between two versions of the page.

Link to this comparison view

user:hum_yt-dl-gui [2019/01/26 21:40] (current)
hum created
Line 1: Line 1:
 +===== youtube-dl-gui =====
 +
 +I wrote a minimalistic youtube-dl-gui. It depends on youtube-dl and yad. You can copy the code below in youtube-dl-gui in ~/bin . 
 +
 +
 +----
 +
 +<​code>​
 +
 +#!/bin/bash
 +# youtube-dl-gui (C) Jens Korte, GPL3 only: https://​www.gnu.org/​licenses/​gpl-3.0.en.html
 +VERSION="​0.05"​
 +
 +#### VARIABLEN ####
 +
 +DEBUG=""​ # empty=no debug output; yes=Debug output
 +#​DEBUG="​yes"​ # empty=no debug output; yes=Debug output
 +
 +# in a xterm there was no ~/bin added when started from Desktop icon in LMDE (Mint)
 +test -d "​$HOME"/​bin && PATH="​$PATH":"​$HOME"/​bin
 +
 +test "​$DEBUG"​ && echo "$0 version: $VERSION started; press return"​
 +test "​$DEBUG"​ && read n
 +
 +Targetdir=`ls -d ~/[Mm]usi* 2>/​dev/​null | head -n1`
 +test "​$Targetdir"​ || Targetdir="​$HOME"​
 +test "​$DEBUG"​ && echo $Targetdir
 +
 +exit_msg () {
 +  echo $1
 +  echo press Return
 +  read n
 +  exit 1
 +}
 +
 +
 +check_dependencies () {
 +  test "​$DEBUG"​ && echo DEBUG: checking for: yad, youtube-dl
 +  test `which yad` || exit_msg "yad not found"
 +  test `which youtube-dl` || exit_msg "​youtube-dl not found"
 +}
 +
 +#### FORM ####
 +
 +YAD=`yad --title "​download YouTube Video as MP3 or video, insert Link" \
 +--form --separator="​!"​ --item-separator="​!"​ \
 +--field="​VideoOrAudio:​CB"​ \
 +--field="​URL:" ​ \
 +--field="​Playlist:​CB"​ \
 +--field="​Targetdir:​DIR"​ \
 +"​MP3!Video"​ ""​ "​yes-playlist!no-playlist"​ "​$Targetdir"​` || exit_msg "YAD form canceled"​
 +
 +#### WORK ####
 +
 +VIDEOORMP3=`echo "​$YAD"​ | cut -d"​!"​ -f1`
 +URL=`echo "​$YAD"​ | cut -d"​!"​ -f2`
 +PLAYLIST=`echo "​$YAD"​ | cut -d"​!"​ -f3`
 +OUTPUT_TEMPLATE="​%(title)s.%(ext)s"​
 +Targetdir=`echo "​$YAD"​ | cut -d"​!"​ -f4`
 +test "​$PLAYLIST"​ = "​yes-playlist"​ && OUTPUT_TEMPLATE="​%(playlist_index)s ""​$OUTPUT_TEMPLATE"​
 +
 +# Output Template if data is set correctly
 +#​OUTPUT_TEMPLATE='​%(artist)s-%(track).%(ext)s'​
 +#test "​$PLAYLIST"​ = "​yes-playlist"​ && OUTPUT_TEMPLATE='​%(track_number)02d '"​$OUTPUT_TEMPLATE"​
 +
 +
 +test "​$DEBUG"​ && echo DEBUG: YAD: $YAD
 +test "​$DEBUG"​ && echo "​DEBUG:​ URL: $URL"
 +test "​$DEBUG"​ && echo "​DEBUG:​ Playlist: --$PLAYLIST"​
 +test "​$DEBUG"​ && echo "​OUTPUT_TEMPLATE:​ $OUTPUT_TEMPLATE"​
 +test "​$DEBUG"​ && echo "​DEBUG:​ TARGET DIR: " $Targetdir
 +
 +cd $Targetdir
 +test "​$VIDEOORMP3"​ = "​MP3" ​  &&​ youtube-dl -i -x -f bestaudio/​best --audio-format mp3 -o "​$OUTPUT_TEMPLATE"​ --$PLAYLIST $URL
 +test "​$VIDEOORMP3"​ = "​Video"​ && youtube-dl -i -o "​$OUTPUT_TEMPLATE"​ --$PLAYLIST $URL
 +
 +
 +## Changelog
 +#
 +### 0.05
 +# * english translation including variables
 +# * Targetdir: ~/[Mm]usi* or ~ added
 +#
 +### 0.04
 +#
 +# * renamed to yt-dl-gui-0.04.sh
 +# * added PATH with "​$HOME"/​bin since in a xterm there was no ~/bin in the PATH
 +#
 +### 0.03
 +#
 +# * add Video or MP3 selection
 +# * changed item-seperator and seperator in form to !
 +
 +
 +
 +## Notes
 +#
 +#​-o|--output TEMPLATE
 +#Available for the media that is a track or a part of a music album:
 +# · track_number (numeric): Number of the track within an album or a disc
 +# · artist (string): Artist(s) of the track
 +# · track (string): Title of the track
 +#​hierarchical ​    ​path, ​    ​e.g.-o '​%(playlist)s/​%(playlist_index)s - %(title)s.%(ext)s'​
 +#To use percent literals in an output template use %%.  To output to stdout use -o -.
 +#​--restrict-filenames
 +
 +#Download YouTube playlist videos in separate directory indexed by video order in a playlist
 +#$ youtube-dl -o '​%(playlist)s/​%(playlist_index)s - %(title)s.%(ext)s'​ https://​www.youtube.com/​playlist?​list=PLwiyx1dc3P2JR9N8gQaQN_BCvlSlap7re
 +
 +
 +#​--add-metadata
 +#​--metadata-from-title FORMAT (wie -o)
 +</​code>​