This repository was archived by the owner on Aug 11, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patharchive-youtube-channel.sh
executable file
·85 lines (77 loc) · 2.68 KB
/
archive-youtube-channel.sh
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
#!/bin/bash
# This script is used to create and update local archives of Youtube channels
# Todo:
# - Option flag for archive_dir.
# - Transcode to HEVC (hint: `youtbe-dl --exec`).
# - Option to only update a specific channel.
# - Confirm folder name when adding new channel.
# - Allow for per channel config file (e.g. parsing consistantly formatted
# channel titles to extract actual video title).
# - Parse video names to remove channel names and find episode numbers where
# applicable. Would likely require per channel config files. It would
# probably work best if file naming was acheived through parsing the json file
# directly rather than using youtube-dl.
# - Confirm dir has a channel_url file.
# - Do something to fix how Jellyfin handles episode numbers and titles. Maybe
# edit the .NFOs and set the date as the epsode number? (Hint: `xmlstarlet`)
archive_dir="/run/media/daniel/DIW Storage 0/video/youtube channels"
alias printf='builtin printf'
# Takes url, returns channel directory name or empty string.
# The 'channel_url' file exists test is hack to deal with empty input. It should
# be replaced with input validation.
function is_subbed_test () {
for i in "$archive_dir"/* ; do
if [[ -f "$i"/channel_url && $(cat "$i"/channel_url) == "$1" ]] ; then
printf "${i##*/}"
exit 1
fi
done
printf ""
}
function new_sub () {
local url=""
local channel=""
printf "Enter channel URL: "
read url
local existing_dir=$(is_subbed_test "$url")
if [[ "$existing_dir" != "" ]] ; then
printf "This channel is already being saved to \'$existing_dir\'.\n"
else
channel="$(youtube-dl --get-filename --playlist-end 1 --output '%(uploader)s' $url)"
mkdir "$archive_dir"/"$channel"
printf "$url" > "$archive_dir"/"$channel"/channel_url
printf "Channel added. Videos will be saved to \'$channel\'.\n"
fi
}
function download () {
youtube-dl \
--download-archive downloaded \
--continue \
--ignore-errors \
--no-overwrites \
--add-metadata \
--write-thumbnail \
--embed-thumbnail \
--all-subs \
--embed-subs \
--write-info-json \
--output "%(upload_date)s %(title)s [%(extractor)s_id %(id)s].%(ext)s" \
"$1"
}
function update_all_channels () {
for i in "$archive_dir"/*; do
cd "$i"
download "$(cat channel_url)"
done
}
function main () {
if [[ "$1" == "update" ]] ; then
update_all_channels
elif [[ "$1" == "add" ]] ; then
new_sub
else
printf "Command not recognized. Recognized commands are 'update' and "
printf "'add'\n"
fi
}
main "$@"