-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathytinfo
More file actions
executable file
·162 lines (148 loc) · 4.77 KB
/
ytinfo
File metadata and controls
executable file
·162 lines (148 loc) · 4.77 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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
#!/usr/bin/env bash
#
# ############################################################################
# Project: scripts (none)
# File...: ytinfo
# Created: Sunday, 2020/04/26 - 09:02:28
# Author.: @fbnmtz, (fabiano.matoz@gmail.com)
# ~·~·~·~·~·~·~·~·~·~·~·~·~~·~·~·~·~·~·~·~·~·~·~·~·~~·~·~·~·~·~~·~·~·~·~·~·~·~
# Last Modified: Wednesday, 2023/05/31 - 00:11:14
# Modified By..: @fbnmtz, (fabiano.matoz@gmail.com)
# ~·~·~·~·~·~·~·~·~·~·~·~·~~·~·~·~·~·~·~·~·~·~·~·~·~~·~·~·~·~·~~·~·~·~·~·~·~·~
# Version: 0.1.5.22
# ~·~·~·~·~·~·~·~·~·~·~·~·~~·~·~·~·~·~·~·~·~·~·~·~·~~·~·~·~·~·~~·~·~·~·~·~·~·~
# Description:
# >
# ############################################################################
# HISTORY:
#
################################################################################
# V2
################################################################################
date_cmd="--dateafter $(date '+%Y%m%d')"
ARGS=""
OUTPUT=""
command="yt-dlp"
################################################################################
# DEFINE YOUTUBE-DL DEFAULT OPTIONS
################################################################################
# -i: ignore errors (ex: unavailable videos)
# --skip-download: dont download requested video/playlist in URL. get on info
# -o: define output format (values and format/order)
# -j: convert output format to json
# -4: force to use ipv4
# --geo-bypass: avoid geo restrictions for videos
# --write-description: get video description
DEFAULT_ARGS="-i --skip-download \
-o '%(uploader)s:%(playlist)s:%(playlist_index)s:%(upload_date)s:%(duration)s:%(id)s:%(title)s' \
-j \
-4 \
"
# return youtube-db command line with default options.Some options may be defined by user
getCMD(){
while [ "$1" != "" ]; do
case "$1" in
-u|--url)
URL=$2 ;;
-a|--after-date)
ARGS=$date_cmd ;;
-s|--simulate)
ARGS+=" -s" ;;
*)
DEFAULT_ARGS="--skip-download -o '%(uploader)s:%(playlist)s:%(playlist_index)s:%(upload_date)s:%(duration)s:%(id)s:%(title)s' -j"
esac
shift
done
# add YT sort format to URL
CMD="$command $DEFAULT_ARGS $ARGS $URL/videos"
}
# run command generated by 'getCMD' redirecting output to a json parser (jq)
runCMD(){
eval "$CMD" | jq '._filename' > /tmp/ytinfo.tmp
OUTPUT=$(cat /tmp/ytinfo.tmp)
}
# get all videos from a channel url
channel_videos(){
# DEFAULT_ARGS="--skip-download -o '%(uploader)s:%(playlist)s:%(playlist_index)s:%(upload_date)s:%(duration)s:%(id)s:%(title)s' -j"
getCMD
runCMD
format_output
}
# filter channel videos after a date. ()
videos_date(){
dt=$1
ARGS="--dateafter $(date '+%Y%m%d' --date="$dt-1 day")"
getCMD
runCMD
format_output
}
format_output(){
if [ "$OUTPUT" != "" ]; then
echo "# updated=$(date '+%Y%m%d') @$URL"
while IFS=':' read channel playlist index date duration id title; do
# `channel` and `title` returned with two invalid chars (") at begin/end. so lets remove then
title=${title:0:-1}
channel=${channel:1}
echo "https://youtu.be/$id # $channel:$playlist:$index:$date:$duration:$title"
done <<< $OUTPUT
else
echo "null"
fi
}
# get all playlists from a channel url
channel_playlists(){
URL+="/playlists"
getCMD --simulate
runCMD
echo "# updated=$(date '+%Y%m%d') @$URL"
while IFS=':' read channel playlist index date duration id title; do
echo "https://youtu.be/$id # $(echo $channel | sed 's,'\"\'','','):$playlist:$index:$date:$duration:$(echo $title | sed 's,'\'\"','',')"
done <<< $OUTPUT
}
channel_name(){
ARGS="--dateafter $(date '+%Y%m%d' --date='-2 weeks')"
getCMD
runCMD
echo <<< $OUTPUT
}
# main app
APP=$(basename $0)
usage(){
echo "usage: $APP [command] [options]"
echo -e " * commands:
describe here your commands/options"
}
requireARGS(){
if [ "$1" == "" ]; then
usage
exit 1
fi
}
# check all params
while [ "$1" != "" ]; do
case $1 in
-cv | --channel-videos)
shift
URL=$1
channel_videos ;;
-vd | --videos-date)
shift
dt=$1
shift
URL=$1
videos_date $dt ;;
-cp | --channel-playlists)
shift
URL=$1
channel_playlists;;
-cn | --channel-name)
shift
URL=$1
channel_name ;;
*)
usage
exit 1
esac
# remove current $1 arg, and assing $2 to $1
shift
done