Make both audio and video versions of yt download function
authorSiraaj Khandkar <siraaj@khandkar.net>
Thu, 29 Oct 2020 23:07:23 +0000 (19:07 -0400)
committerSiraaj Khandkar <siraaj@khandkar.net>
Thu, 29 Oct 2020 23:07:23 +0000 (19:07 -0400)
home/lib/login_functions.sh
home/lib/login_variables.sh

index c477f70..45460f4 100644 (file)
@@ -237,21 +237,29 @@ howto() {
     cat "$(find  ~/Archives/Documents/HOWTOs -mindepth 1 -maxdepth 1 | sort | fzf)"
 }
 
-yt() {
-    local _yt_uri
-    local _yt_id
-    local _yt_title
-    local _yt_dir
-
-    _yt_uri="$1"
-    _yt_id=$(youtube-dlc --get-id "$_yt_uri")
-    _yt_title=$(youtube-dlc --get-title "$_yt_uri")
-    _yt_dir="${DIR_YOUTUBE}/individual-videos/${_yt_title}--${_yt_id}"
-
-    mkdir -p "$_yt_dir"
-    cd "$_yt_dir" || kill -INT $$
-    echo "$_yt_uri" > 'uri'
-    youtube-dlc -c --write-description --write-info-json "$_yt_uri"
+_yt() {
+    local -r base_dir="$1"
+    local -r opts="$2"
+    local -r uri="$3"
+
+    local -r id=$(youtube-dlc --get-id "$uri")
+    local -r title=$(youtube-dlc --get-title "$uri" | sed 's/[^A-Za-z0-9._-]/_/g')
+    local -r dir="${base_dir}/${title}--${id}"
+
+    mkdir -p "$dir"
+    cd "$dir" || kill -INT $$
+    echo "$uri" > 'uri'
+    youtube-dlc $opts -c --write-description --write-info-json "$uri"
+}
+
+yt_audio() {
+    local -r uri="$1"
+    _yt "${DIR_YOUTUBE_AUDIO}/individual" '-f 140' "$uri"
+}
+
+yt_video() {
+    local -r uri="$1"
+    _yt "${DIR_YOUTUBE_VIDEO}/individual" "$uri"
 }
 
 gh_fetch_repos() {
index 3d0dbf3..16bab2c 100644 (file)
@@ -2,8 +2,10 @@ export PATH=$HOME/bin:$HOME/.local/bin:$HOME/go/bin:/snap/bin:/sbin:/usr/sbin:$P
 export EDITOR=vim
 export VISUAL=$EDITOR
 export DIR_GITHUB="${HOME}/Archives/Software/src/repos/remote/github.com"
+export DIR_AUDIO="${HOME}/Archives/Audio"
 export DIR_VIDEO="${HOME}/Archives/Videos"
-export DIR_YOUTUBE="${DIR_VIDEO}/Web/youtube.com"
+export DIR_YOUTUBE_VIDEO="${DIR_VIDEO}/Web/youtube.com"
+export DIR_YOUTUBE_AUDIO="${DIR_AUDIO}/youtube.com"
 export DIR_NOTES="$HOME/Documents/Notes"
 export DIR_LOG="$HOME/var/log"
 export DIR_LOG_MPD="$DIR_LOG/mpd"
This page took 0.025094 seconds and 4 git commands to generate.