-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathytdl.lib
More file actions
executable file
·133 lines (114 loc) · 3.81 KB
/
ytdl.lib
File metadata and controls
executable file
·133 lines (114 loc) · 3.81 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
#!/usr/bin/env bash
#
# ############################################################################
# Project: scripts (none)
# File...: ytdl.lib
# Created: Sunday, 2022/04/03 - 17:39:45
# Author.: @fbnmtz, (fabiano.matoz@gmail.com)
# ~·~·~·~·~·~·~·~·~·~·~·~·~~·~·~·~·~·~·~·~·~·~·~·~·~~·~·~·~·~·~~·~·~·~·~·~·~·~
# Last Modified: Tuesday, 2023/08/29 - 17:00:59
# Modified By..: @fbnmtz, (fabiano.matoz@gmail.com)
# ~·~·~·~·~·~·~·~·~·~·~·~·~~·~·~·~·~·~·~·~·~·~·~·~·~~·~·~·~·~·~~·~·~·~·~·~·~·~
# Version: 0.0.6.171
# ~·~·~·~·~·~·~·~·~·~·~·~·~~·~·~·~·~·~·~·~·~·~·~·~·~~·~·~·~·~·~~·~·~·~·~·~·~·~
# Description:
# >
# ############################################################################
# HISTORY:
#
use system
_xLIB_YTDL_=true
# ~·~·~·~·~·~·~·~·~·~·~·~·~~·~·~·~·~·~·~·~·~·~·~·~·~~·~·~·~·~·~~·~·~·~·~·~·~·~
notify_app=xsys.notify
ytdl_output=''
ytdl_text=''
CMD="yt-dlp"
ARGS="-4"
# get system home path
gethome(){
local videos_path=''
case "$(xsys.os)" in
Linux )
if [ -n "$XDG_VIDEOS_DIR" ]; then
videos_path=$XDG_VIDEOS_DIR
else
videos_path=$HOME/videos
fi
;;
Darwin) videos_path=$HOME/Movies ;;
esac
echo "$videos_path"
}
geLinuxtPath(){
local type=$1
case "$type" in
audio) ;;
video) ;;
esac
}
prepareArgs(){
local type=$1
local url=$2
shift; shift;
case "$url" in
*"&list"*)
ytdl_text="$type playlist"
ytdl_output="$APP_HOME/%(playlist)s/%(playlist_index)s-%(title)s.%(ext)s"
;;
*"channel"* | *"user"*)
ytdl_text="$type channel/user"
ytdl_output="$APP_HOME/%(uploader)s/%(playlist_index)s-%(title)s.%(ext)s"
if [ "$type" == "video" ]; then
ARGS+=" --playlist-reverse"
fi
;;
*)
ytdl_text="$type file"
if [ "$1" != "" ]; then
location_to_save="$APP_HOME/$1/"
# shift
else
location_to_save="$APP_HOME/"
fi
if [ "$type" == "video" ]; then
domain=$(echo "$url" | cut -d ':' -f2 | sed 's/\/\///' | cut -d '/' -f1 | sed 's/^www.//')
case $domain in
# from YT open url in mpv
youtu.be|youtube.com|youtube.com.br)
ytdl_output="$location_to_save%(title)s.%(ext)s" ;;
*redd.it|reddit.com)
ytdl_output="$location_to_save%(original_url)s-%(upload_date>%Y-%m-%d)s-%(duration>%H-%M-%S)s.%(ext)s" ;;
*)
ytdl_output="$location_to_save%(uploader)s.%(title)s.%(creator)s.%(upload_date>%Y-%m-%d)s.%(release_date)s-%(duration>%H-%M-%S)s-%(original_url)s-%(id)s-%(filesize)s.%(ext)s"
esac
else
ytdl_output="$location_to_save%(title)s.%(ext)s"
fi
esac
case "$type" in
audio) ARGS+=" --output $ytdl_output --extract-audio --audio-format mp3 " ;;
video) ARGS+=" --cookies ~/bin/youtube.com_cookies.txt --output $ytdl_output" ;;
esac
}
runCMD(){
APP_HOME="$(gethome)/ytdl"
local type=$1
local url=$2
prepareArgs "$type" "$url"
ytdlCMD "$url"
}
ytdlCMD(){
local url=$1
command="$CMD $ARGS $url"
echo "$command"
if $command; then
$notify_app "$APP" "$ytdl_text download complete \n'$url'" -c
else
$notify_app "$APP" "Error!" -c
fi
}
# extract audio from a local video file
ytExtract(){
audio=$(echo "$filename" | tr -s ' ' '-' | cut -d '.' -f1)
ffmpeg -i "$filename" -f mp3 -ab 192000 -vn "${audio}".mp3
}