generated from yt-dlp/yt-dlp-sample-plugins
-
Notifications
You must be signed in to change notification settings - Fork 0
/
yt-albumdownload
executable file
·119 lines (106 loc) · 3.22 KB
/
yt-albumdownload
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
#!/bin/bash
CUSTOM_YEAR=false
DUMP=false
NO_ALBUM_RG=false
NO_RG=false
PREVIEW=false
VARIOUS=false
YT_DLP_ARGS=""
HELP="Usage: yt-albumdownload [options] <Youtube playlist URL>
Some arguments are mutually exclusive. It's probably somewhat self-evident which ones.
--help: This thing
--various: Set album artist and immediate subdirectory to 'Various Artists' and filename to
'[track #] [track artist] - [track title]'; implies --no-album-rg
--no-rg: Don't apply replaygain
--no-album: Don't treat as album when applying replaygain
--year <YEAR>: Use YEAR instead of parsing release year (could be an empty string)
--preview: Just output preview JSON (NB: File extensions will be unknown at this point)
--dump: Just dump complete JSON output from yt-dlp to stdout"
if [ "$#" -eq 0 ]; then
echo "$HELP"
exit 0
fi
while (( "$#" )); do
case "$1" in
--help)
echo "$HELP"
exit 0
;;
--dump)
DUMP=true
shift
;;
--various)
VARIOUS=true
NO_ALBUM_RG=true
shift
;;
--preview)
PREVIEW=true
shift
;;
--year)
CUSTOM_YEAR=true
YEAR="$2"
shift 2
;;
--no-rg)
NO_RG=true
shift
;;
--no-album)
NO_ALBUM_RG=true
shift
;;
*)
YT_DLP_ARGS="$YT_DLP_ARGS $1"
shift
;;
esac
done
ARGS=(
--parse-metadata "uploader:%(meta_album_artist)s"
--parse-metadata "%(playlist_index)02d:%(meta_track)s"
--parse-metadata "artist:%(meta_artist)s"
--parse-metadata "playlist_title:%(meta_album)s"
--parse-metadata "release_year:%(meta_date)s"
--parse-metadata "release_year:%(meta_year)s"
--replace-in-metadata meta_album_artist " - Topic" ""
--replace-in-metadata meta_date "^NA$" ""
--replace-in-metadata meta_year "^NA$" ""
--replace-in-metadata title "/" "-"
--extract-audio
)
if $VARIOUS; then
ARGS+=(--replace-in-metadata meta_album_artist "^.*$" "Various Artists")
FILENAME="%(meta_album_artist)s/%(meta_album)s/%(meta_track)s - %(meta_artist)s - %(title)s.%(ext)s"
else
FILENAME="%(meta_album_artist)s/%(meta_album)s/%(meta_track)s - %(title)s.%(ext)s"
fi
if $CUSTOM_YEAR; then
ARGS+=(
--replace-in-metadata meta_date "^.*$" "$YEAR"
--replace-in-metadata meta_year "^.*$" "$YEAR"
)
fi
if $DUMP; then
yt-dlp "${ARGS[@]}" --dump-single-json --simulate $YT_DLP_ARGS
exit 0
fi
if $PREVIEW; then
JQ_ARGS=(
'.entries[]|{album: .meta_album, album_artist: .meta_album_artist,'
'track: .meta_track, artist: .meta_artist, title: .title, date: .meta_date,'
'filename: [.meta_album_artist, "/", .meta_album, "/", .meta_track, " ", .title, ".[ext]"]|add}'
)
yt-dlp "${ARGS[@]}" --dump-single-json --simulate $YT_DLP_ARGS | jq "${JQ_ARGS[*]}"
exit 0
fi
if ! $NO_RG; then
if $NO_ALBUM_RG; then
ARGS+=(--use-postprocessor 'ReplayGain:when=playlist;no_album=true')
else
ARGS+=(--use-postprocessor 'ReplayGain:when=playlist')
fi
fi
yt-dlp "${ARGS[@]}" --output "$FILENAME" $YT_DLP_ARGS