summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTheSiahxyz <164138827+TheSiahxyz@users.noreply.github.com>2025-02-10 09:15:54 +0900
committerTheSiahxyz <164138827+TheSiahxyz@users.noreply.github.com>2025-02-10 09:15:54 +0900
commit36c1bd7d9cbba095f3ee216f0d3ccec002ea8991 (patch)
tree76da858eb381c9cc84aabe8211d5f307bcb92195
parent8db391ce6ca07ec78780c782a204abee357d73d0 (diff)
modified qutebrowser/config.py, modified bin/qndl
-rw-r--r--ar/.config/qutebrowser/config.py7
-rwxr-xr-xar/.local/bin/qndl155
2 files changed, 94 insertions, 68 deletions
diff --git a/ar/.config/qutebrowser/config.py b/ar/.config/qutebrowser/config.py
index a7841dc..e702c00 100644
--- a/ar/.config/qutebrowser/config.py
+++ b/ar/.config/qutebrowser/config.py
@@ -927,7 +927,12 @@ c.content.javascript.legacy_touch_events = "auto"
## qutebrowser's stylesheet handling are excluded, as those errors are to
## be expected and can't be easily handled by the underlying code.
## Type: Dict
-# c.content.javascript.log_message.excludes = {'userscript:_qute_stylesheet': ['*Refused to apply inline style because it violates the following Content Security Policy directive: *']}
+c.content.javascript.log_message.excludes = {
+ "userscript:_qute_stylesheet": [
+ "*Refused to apply inline style because it violates the following Content Security Policy directive: *"
+ ],
+ "userscript:_qute_js": ["*TrustedHTML*"],
+}
## Javascript message sources/levels to show in the qutebrowser UI. When
## a JavaScript message is logged from a location matching the glob
diff --git a/ar/.local/bin/qndl b/ar/.local/bin/qndl
index 15d7a43..0dd7263 100755
--- a/ar/.local/bin/qndl
+++ b/ar/.local/bin/qndl
@@ -1,106 +1,127 @@
#!/bin/sh
-# check browser
+YTDL_CMD_BASE="yt-dlp --continue --embed-metadata --ignore-errors --no-force-overwrites --no-playlist --verbose"
+
case "$BROWSER" in
librewolf) cookies="librewolf:~/.librewolf" ;;
firefox) cookies="firefox:~/.mozilla/firefox" ;;
esac
+[ -n "$cookies" ] && YTDL_CMD_BASE="$YTDL_CMD_BASE --cookies-from-browser $cookies"
+
+shift $((OPTIND - 1))
+
+# Use the first non-option argument as the URL if provided, else from clipboard
# [url] [type] [cmd]
if [ $# -eq 1 ]; then
type="$1"
- url="$(xclip -selection clipboard -o)"
+ URL="$(xclip -selection clipboard -o)"
elif [ $# -eq 2 ]; then
if echo "$1" | grep -qE "https?://"; then
- url="$1"
+ URL="$1"
elif echo "$2" | grep -qE "https?://"; then
type="$1"
- url="$2"
+ URL="$2"
fi
fi
-# check url
-[ -z "$url" ] && notify-send "⛔ No URL provided and clipboard is empty or does not contain a valid URL." && exit 1
-! echo "$url" | grep -qE '^https?://[a-zA-Z0-9.-]+(/[a-zA-Z0-9./?&%=_-]*)?$' && notify-send "⛔ Invalid URL format: $url" && exit 1
-! curl --head --silent --fail "$url" >/dev/null && notify-send "⛔ URL is not accessible: $url" && exit 1
-
-# opts
-[ -n "$cookies" ] && base="yt-dlp --cookies-from-browser $cookies -civ --no-force-overwrites --no-playlist" ||
- base="yt-dlp -civ --no-force-overwrites --no-playlist"
-
+# Process command-line options for download type
case $type in
--m | --music)
- downloadtype="music"
- dest="${XDG_MUSIC_DIR:-${HOME}/Music}"
- record="${XDG_DOTFILES_DIR:-${HOME}/.dotfiles}/default/Music/.music.txt"
- output="$dest/%(artist|)s%(artist& - |)s%(title)s.%(ext)s"
- cmd="$base --audio-format best --audio-quality 0 --download-archive \"$record\" --extract-audio --recode-video mp3"
+m)
+ DOWNLOAD_TYPE="music"
+ OUTPUT_DIR="${XDG_MUSIC_DIR:-${HOME}/Music}"
+ ARCHIVE_FILE="${XDG_DOTFILES_DIR:-${HOME}/.dotfiles}/default/Music/.music.txt"
+ YTDL_OUTPUT_FORMAT="${OUTPUT_DIR}/%(artist|)s%(artist& - |)s%(title)s.%(ext)s"
+ YTDL_CMD_BASE="$YTDL_CMD_BASE --audio-format best --audio-quality 0 --download-archive \"$ARCHIVE_FILE\" --extract-audio --recode-video mp3"
;;
--r | --restore)
- dest="${XDG_MUSIC_DIR:-${HOME}/Music}"
- record="${XDG_DOTFILES_DIR:-${HOME}/.dotfiles}/default/Music/.music.txt"
- output="$dest/%(artist|)s%(artist& - |)s%(title)s.%(ext)s"
- cmd="$base --audio-format best --audio-quality 0 --extract-audio --recode-video mp3"
- [ ! -f "$record" ] && exit 1
+r)
+ OUTPUT_DIR="${XDG_MUSIC_DIR:-${HOME}/Music}"
+ ARCHIVE_FILE="${XDG_DOTFILES_DIR:-${HOME}/.dotfiles}/default/Music/.music.txt"
+ YTDL_OUTPUT_FORMAT="${OUTPUT_DIR}/%(artist|)s%(artist& - |)s%(title)s.%(ext)s"
+ YTDL_CMD_BASE="$YTDL_CMD_BASE --audio-format best --audio-quality 0 --extract-audio --recode-video mp3"
+ YTDL_CMD="$YTDL_CMD_BASE --output \"$YTDL_OUTPUT_FORMAT\""
+ [ ! -f "$ARCHIVE_FILE" ] && exit 1
while read -r line; do
video_id=$(echo "$line" | awk '{print $2}')
- cmd="$cmd -o $output"
- idnum=$(tsp $cmd "https://www.youtube.com/watch?v=$video_id")
- done <"$record"
- tsp -D "$idnum" notify-send "🎵 Music restored!"
+ YTDL_CMD="$YTDL_CMD_BASE --output \"$YTDL_OUTPUT_FORMAT\" \"https://www.youtube.com/watch?v=$video_id\""
+ idnum=$(tsp bash -c "$YTDL_CMD")
+ pkill -RTMIN+21 "${STATUSBAR:-dwmblocks}"
+ done <"$ARCHIVE_FILE"
exit 0
;;
--v | --video)
- downloadtype="video"
- dest="${XDG_VIDEOS_DIR:-${HOME}/Videos}"
- output="$dest/%(title)s [%(id)s].%(ext)s"
- encode=$(printf "best\n60fps\n30fps\nmp4\nmkv" | dmenu -i -p "Choose an encoding (default: 1080p)") || exit
- option=""
- case $encode in
- best) format="--format bestvideo+bestaudio/best" ;;
- 60fps) format='--format "((bv*[fps=60]/bv*)[height<=1080]/(wv*[fps=60]/wv*)) + ba / (b[fps=60]/b)[height<=1080]/(w[fps=60]/w)"' ;;
- 30fps) format='--format "((bv*[fps=30]/bv*)[height<=1080]/(wv*[fps=30]/wv*)) + ba / (b[fps=30]/b)[height<=1080]/(w[fps=30]/w)"' ;;
+v)
+ DOWNLOAD_TYPE="video"
+ OUTPUT_DIR="${XDG_VIDEOS_DIR:-${HOME}/Videos}"
+ YTDL_OUTPUT_FORMAT="${OUTPUT_DIR}/%(title)s [%(id)s].%(ext)s"
+ VIDEO_EXT=$(printf "best\n60fps\n30fps\nmp4\nmkv" | dmenu -i -p "Choose an encoding (default: 1080p)") || exit
+ case $VIDEO_EXT in
+ best)
+ VIDEO_FORMATS="--format bestvideo+bestaudio/best"
+ ;;
+ 60fps)
+ VIDEO_FORMATS='--format "((bv*[fps=60]/bv*)[height<=1080]/(wv*[fps=60]/wv*)) + ba / (b[fps=60]/b)[height<=1080]/(w[fps=60]/w)"'
+ ;;
+ 30fps)
+ VIDEO_FORMATS='--format "((bv*[fps=30]/bv*)[height<=1080]/(wv*[fps=30]/wv*)) + ba / (b[fps=30]/b)[height<=1080]/(w[fps=30]/w)"'
+ ;;
*)
- format="--format bestvideo+bestaudio/best"
- option="--recode-video $encode"
+ VIDEO_FORMATS="--format bestvideo+bestaudio/best"
+ VIDEO_OPTIONS="--recode-video $VIDEO_EXT"
;;
esac
- cmd="$base --buffer-size 1M --embed-metadata --embed-thumbnail --no-sponsorblock $format $option"
- cmd="${cmd%* }"
+ YTDL_CMD_BASE="$YTDL_CMD_BASE --buffer-size 1M --embed-thumbnail $VIDEO_FORMATS --no-sponsorblock $VIDEO_OPTIONS"
+ YTDL_CMD_BASE="${YTDL_CMD_BASE%* }"
+ ;;
+*)
+ notify-send "⛔ Invalid option: -$OPTARG"
+ exit 1
;;
esac
-# check playlist
-case $url in
+[ -z "$URL" ] && notify-send "⛔ No URL provided and clipboard is empty or does not contain a valid URL." && exit 1
+
+# Validate the URL format
+! echo "$URL" | grep -qE '^https?://[a-zA-Z0-9.-]+(/[a-zA-Z0-9./?&%=_-]*)?$' && notify-send "⛔ Invalid URL format: $URL" && exit 1
+
+# Validate URL accessibility
+! curl --head --silent --fail "$URL" >/dev/null && notify-send "⛔ URL is not accessible: $URL" && exit 1
+
+case $URL in
*playlist* | *list=*)
- filetype=$(printf "playlist\na content" | dmenu -i -p "Download entire playlist or just this content?")
- [ "$filetype" = "playlist" ] &&
- base=$(echo "$base" | sed 's/ --no-playlist//') &&
- base="$base --yes-playlist" &&
+ PL_DOWNLOAD_CHOICE=$(printf "playlist\na content" | dmenu -i -p "Download entire playlist or just this content?")
+ [ "$PL_DOWNLOAD_CHOICE" = "playlist" ] &&
+ YTDL_CMD_BASE=$(echo "$YTDL_CMD_BASE" | sed 's/ --no-playlist//') &&
+ YTDL_CMD_BASE="$YTDL_CMD_BASE --yes-playlist" &&
echo 🪏 >/tmp/qplaylist
- [ "$downloadtype" = "video" ] &&
- channel=$(yt-dlp -s -O "%(channel)s" "$url" | head -n 1 | sed 's/, /,/g;s/[\/:*?"<>| ]/-/g' | tr '[:upper:]' '[:lower:]') &&
- playlisttitle=$(yt-dlp -s -O "%(playlist_title)s" "$url" | head -n 1 | sed 's/, /,/g;s/[\/:*?"<>| ]/-/g' | tr '[:upper:]' '[:lower:]') &&
- subdest="$channel/$playlisttitle" &&
- mkdir -p "$dest/$subdest" &&
- output="$dest/$subdest/%(playlist_index)02d. %(title)s [%(id)s].%(ext)s"
+ [ "$DOWNLOAD_TYPE" = "video" ] &&
+ CHANNEL=$(yt-dlp --print "%(channel)s" "$URL" | head -n 1 | sed 's/, /,/g;s/[\/:*?"<>| ]/-/g' | tr '[:upper:]' '[:lower:]') &&
+ PLAYLIST=$(yt-dlp --print "%(playlist_title)s" "$URL" | head -n 1 | sed 's/, /,/g;s/[\/:*?"<>| ]/-/g' | tr '[:upper:]' '[:lower:]') &&
+ SUBDIR="${CHANNEL}/${PLAYLIST}" &&
+ mkdir -p "${OUTPUT_DIR}/${SUBDIR}" &&
+ YTDL_OUTPUT_FORMAT="${OUTPUT_DIR}/${SUBDIR}/%(playlist_index)02d_%(title)s [%(id)s].%(ext)s"
;;
esac
-filename=$(yt-dlp -s -O "%(filename)s [%(id)s].%(ext)s" "$url")
-
-[ -z "$type" ] && output="$HOME/$filename"
+SIMULATION_CMD="yt-dlp --simulate --print %(filename)s $URL"
+YTDL_CMD="$YTDL_CMD_BASE --output \"$YTDL_OUTPUT_FORMAT\" \"$URL\""
-# queue
-echo "$filename" | while IFS= read -r file; do
- notify-send "📥 Queuing..." "$(basename "$file")"
+# Notify and perform simulation to get filename (feedback to user)
+echo "$SIMULATION_CMD" | while IFS= read -r line; do
+ filename=$(basename "$line")
+ notify-send "📥 Queuing $DOWNLOAD_TYPE to download:" "$filename"
done
-# download
+# Enqueue the download task with tsp
+FILENAME=$($SIMULATION_CMD 2>/dev/null)
rm -rf /tmp/qplaylist
-notify-send "⏳ Downloading..." "$filename"
-idnum="$(tsp $cmd -o "$output" "$url")"
+notify-send "⏳ Downloading $DOWNLOAD_TYPE:" "$FILENAME"
+idnum=$(tsp bash -c "$YTDL_CMD")
+pkill -RTMIN+21 "${STATUSBAR:-dwmblocks}"
+
+# Notify upon completion
+filename=$(yt-dlp -s -O '%(filename)s [%(ids)s].%(ext)s' "$URL")
+tsp -D "$idnum" notify-send "✅ $DOWNLOAD_TYPE download complete:" "$filename" ||
+ notify-send "❌ Faild to download:" "$filename"
-# done
-tsp -D "$idnum" notify-send "👍 Completed download!" "$filename" || notify-send "❌ Failed to donwload:" "$filename"
-[ "$downloadtype" = "music" ] && tsp -D "$idnum" "mpc update"
+# Conditionally update the music database if the download type is music
+[ "$DOWNLOAD_TYPE" = "music" ] && tsp -D "$idnum" bash -c "mpc update"