-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex-music
More file actions
executable file
·73 lines (71 loc) · 2.04 KB
/
Copy pathindex-music
File metadata and controls
executable file
·73 lines (71 loc) · 2.04 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
#!/bin/bash
# index-music: a simple script for creating an index of music files dowloaded using youtube-music
#
# Copyright (C) 2022 mini_bomba
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
FAIL=0
if YTDL=$(which yt-dlp)
then
echo "Using yt-dlp" >&2
elif YTDL=$(which youtube-dl)
then
echo "yt-dlp not found; using fallback youtube-dl." >&2
echo "Consider installing yt-dlp if you experience throttling." >&2
else
echo "Missing required dependency: yt-dlp" >&2
FAIL=1
fi
export YTDL
if ! which grep > /dev/null 2>&1
then
echo "Missing required dependency: grep" >&2
FAIL=1
fi
if ! which jq > /dev/null 2>&1
then
echo "Missing required dependency: jq" >&2
FAIL=1
fi
if ! which xargs > /dev/null 2>&1
then
echo "Missing required dependency: xargs" >&2
FAIL=1
fi
if ! which sort > /dev/null 2>&1
then
echo "Missing required dependency: sort" >&2
FAIL=1
fi
if [ $FAIL -ne 0 ]
then
exit 1
fi
function index-file() {
if echo $1 | grep -Pv '^[[:alnum:]_-]{11}\.mp3$' > /dev/null
then
echo "$1 Invalid youtube ID"
return
fi
ID=${1:0:-4}
DATA=$($YTDL --skip-download --print-json --no-warnings "https://youtu.be/$ID" | jq -r '.title')
if [[ -z "$DATA" ]]
then
echo "$1 Private or invalid youtube video"
else
echo "$1 $DATA"
fi
}
export -f index-file
ls | xargs -P $(grep -c ^processor /proc/cpuinfo) -n 1 -d "\n" -r bash -c 'index-file "$0"' | sort