From 92d6bf6e8132d2bad2eb6c2c5a31359e75c22c22 Mon Sep 17 00:00:00 2001 From: Coolnsx Date: Sat, 23 Dec 2023 23:04:39 +0530 Subject: [PATCH] It fucking compiles \:D/ --- youtube | 103 ++++++++++++++++++++++++++++++++++++++++---------------- 1 file changed, 74 insertions(+), 29 deletions(-) diff --git a/youtube b/youtube index a90f119..44cb7f5 100755 --- a/youtube +++ b/youtube @@ -1,44 +1,89 @@ #!/bin/sh # script for downloading videos/audios from sites... -# defining shell colors for distinction -c_red="\033[1;31m" -c_green="\033[1;32m" -c_yellow="\033[1;33m" -c_blue="\033[1;34m" -c_magenta="\033[1;35m" -c_cyan="\033[1;36m" -c_reset="\033[0m" +#shellcheck disable=SC2317 -part() { - printf "${c_magenta}Enter Starting Point(hh:mm:ss)or(mm:ss)${c_reset}:" - read start - printf "${c_yellow}Enter Upto Seconds:${c_cyan}" - read dur - ffmpeg -loglevel error -stats -i "$(yt-dlp -f "$3" --get-url "$1")" -ss "$start" -t "$dur" "$download_dir/$(date +%s).$2" +info() { + printf "\033[1;36m[ %s ] [ %s ] %s\033[0m\n" "$2" "$3" "$1" } +error() { + printf "\033[1;31m[ %s ] [ %s ] %s\033[0m\n" "$2" "$3" "$1" +} + +notify_droid() { + termux-notification -c "$1" +} + +notify_linux() { + notify-send "$1" -h "string:x-canonical-private-synchronous:${0##*/}" +} + +#main +link="$1" +agent="Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36" + case $(uname -o) in *ndroid*) download_dir="/sdcard" - x=$(termux-clipboard-get) + [ -z "$link" ] && link=$(termux-clipboard-get) + os="droid" ;; *) download_dir="$HOME" - x=$(wl-paste) + [ -z "$link" ] && link=$(wl-paste) + os="linux" ;; esac -#program starts from here.. -[ -n "$1" ] && x=$1 -[ "$1" = "v" ] && yt-dlp "$x" -o "$download_dir/%(title)s.%(ext)s" && termux-notification -c "video downloaded" && exit 0 -printf "\n${c_blue} video link :${c_magenta}$x\n" -printf "${c_yellow}Download>>\n${c_blue}[a]Audio only\n${c_magenta}[f]part of Audio only\n${c_green}[v]Full video\n${c_cyan}[p]Part of video\n${c_red}[q]Quit" -printf "\n${c_reset}Enter choice:${c_green}" -read choice -case $choice in - a) yt-dlp -f 'ba' -x --audio-format mp3 "$x" -o "$download_dir/%(title)s.%(ext)s" && termux-notification -c "audio downloaded" ;; - f) part "$x" "mp3" "ba" && termux-notification -c "audio downloaded" ;; - v) yt-dlp "$x" -o "$download_dir/%(title)s.%(ext)s" && termux-notification -c "video downloaded" ;; - p) part "$x" "mp4" "b" && termux-notification -c "video downloaded" ;; - q) exit 0 ;; +printf "\n\033[1;34m Video link :\033[0m%s\n" "$link" +case "$link" in + *instagram*) + app="Instagram" + id=$(printf "%s" "$link" | cut -d'/' -f5) + [ -z "$id" ] && error "Unable to extract ID" "$app" "$id" + info "Extracting Video URL" "$app" "$id" + fallback=1 + ;; + *youtu*) + app="Youtube" + id=$(printf "%s" "$link" | cut -d"=" -f2 | cut -d"/" -f4) + [ -z "$id" ] && error "Unable to extract ID" "$app" "$id" + info "Extracting Video URL" "$app" "$id" + yt_ver="2.20231219.04.00" + json="{ + \"context\": { + \"client\": { + \"clientName\": \"WEB\", + \"clientVersion\": \"$yt_ver\", + \"userAgent\": \"$agent\", + \"hl\": \"en\", + \"timeZone\": \"Asia/Calcutta\", + \"utcOffsetMinutes\": 330 + } + }, + \"videoId\": \"$id\", + \"playbackContext\": { + \"contentPlaybackContext\": { + \"html5Preference\": \"HTML5_PREF_WANTS\" + } + }, + \"contentCheckOk\": true, + \"racyCheckOk\": true + }" + data=$(curl -X POST -A "$agent" -s "https://www.youtube.com/youtubei/v1/player?key=AIzaSyAO_FJ2SlqU8Q4STEHLGCilw_Y9_11qcW8&prettyPrint=false" -H "content-type:application/json" -H "X-Youtube-Client-Version: $yt_ver" -d "$json" -e "$link" | tr '{}' '\n' | sed -nE 's|.*,"title":"([^"]*)".*|\1|p;s|.*itag":18,"url":"([^"]*)".*|\1|p;s|.*itag":22,"url":"([^"]*)".*|\1|p') + title=$(printf "%s" "$data" | tail -1) + video_url=$(printf "%s" "$data" | tail -2 | head -1) + printf "%s" "$video_url" | grep -q "googlevideo\.com" || fallback=1 + ;; esac + +if [ -n "$fallback" ]; then + info "Using fallback" "$app" "$id" + yt-dlp "$link" -o "$download_dir/%(title)s.%(ext)s" +else + info "Downloading Video" "$app" "$id" + aria2c -x16 -s16 --user-agent="$agent" "$video_url" -d "$download_dir" --summary-interval=0 -o "$title.mp4" || notify_$os "Unable to Download $app Video" +fi + +notify_$os "$app Video Downloaded" +exit 0