-
Notifications
You must be signed in to change notification settings - Fork 0
/
ff-song.sh
executable file
·163 lines (147 loc) · 3.6 KB
/
ff-song.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
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
163
# create high quality video from song and picture
# site:musicbrainz.org acoustid -site:forums.musicbrainz.org
# http://github.com/stedolan/jq/issues/105
: '
blog.musicbrainz.org/2013/03/21/
puids-are-deprecated-and-will-be-removed-on-15-october-2013
blog.musicbrainz.org/2013/09/03/
changes-for-upcoming-schema-change-release-2013-10-14
'
function JQ {
jq -r "$@" .json | sed 's/\r//'
}
function warn {
printf '\e[36m%s\e[m\n' "$*" >&2
}
function log {
unset PS4
sx=$((set -x
: "$@") 2>&1)
warn "${sx:2}"
"$@"
}
function querystring {
sed 'y/ /&/' <<< ${qs[*]}
}
function show {
for bb
do
echo ${bb^}: ${!bb}
done
}
function readu {
while :
do
show $1
warn [y,e,q]?
read line
case $line in
y) break
;;
e) read -ei "${!1}" $1
break
;;
q) exit
;;
esac
warn y - accept
warn e - edit
warn q - quit
done
}
function exten {
sed "
s/[^.]*$//
s/[^[:alnum:]]//g
s/$/.$2/
" <<< ${!1}
}
function bf {
regtool set /user/console/ScreenBufferSize $(hx 2000 $1)
regtool set /user/console/WindowSize $(hx 25 $1)
cygstart bash $2
kill -7 $$ $PPID
}
if (( $# < 2 ))
then
echo ${0##*/} PICTURE SONGS
echo
echo Script will use files to create high quality videos,
echo then upload videos to YouTube.
exit
fi
img=$1
shift
songs=("$@")
declare -A artists titles
for song in "${songs[@]}"
do
warn $song
. <(fpcalc "$song" | sed 1d)
qs=(
client=8XaBELgH
duration=$DURATION
fingerprint=$FINGERPRINT
meta=recordings+sources
)
warn connect to acoustid.org...
curl -s api.acoustid.org/v2/lookup?`querystring` | jq .results[0] > .json
warn acoustid `JQ .id`
set .sources "($DURATION - (.duration // 0) | length)"
rid=$(JQ ".recordings | max_by(.2 * $1 - .8 * $2).id")
# FIXME allow edit of recording id
warn musicbrainz recording id $rid
# hit musicbrainz API for entire album
if ! (( ${#date} ))
then
qs=(
fmt=json
inc=artist-credits+labels+discids+recordings
recording=$rid
)
warn connect to musicbrainz.org...
set '(.media[0].discs | length)' '.["cover-art-archive"].count'
curl -s musicbrainz.org/ws/2/release?`querystring` |
jq ".releases | max_by(.3 * $1 + .7 * $2)" > .json
warn musicbrainz release id `JQ .id`
cp .json rls.json
tags=$(JQ '.["artist-credit"][0].name')
album=`JQ .title`
show album
label=$(JQ '.["label-info"][0].label.name')
show label
date=`JQ .date`
readu date
fi
# must leave "media" open
# FIXME use "or" to allow multiple recording ids
jq ".media[].tracks[] | select(.recording.id == \"$rid\")" rls.json > .json
artist=$(JQ '[.["artist-credit"][] | .name, .joinphrase] | add')
show artist
title=`JQ .title`
readu title
show title album artist label date > `exten song txt`
titles[$song]=$title
artists[$song]=$artist
done
for song in "${songs[@]}"
do
mp3gain -s d "$song"
ffprobe -v error -show_format -print_format json "$song" > .json
# Adding "-preset" would only make small difference in size or speed.
# "-shortest" can mess up duration. Adding "-analyzeduration" would only
# suppress warning, not change file.
log ffmpeg -loop 1 -r 1 -i "$img" -i "$song" -t `JQ .format.duration` \
-qp 0 -filter:v 'scale=trunc(oh*a/2)*2:720' -b:a 384k -v error \
-stats `exten song mp4`
done
(( ${#album} <= 30 )) && tags+=,$album
type google || exit
for song in "${songs[@]}"
do
# category is case sensitive
log google youtube post `exten song mp4` Music \
-n "${artists[$song]}, ${titles[$song]}" -s `exten song txt` \
-t "$tags" -u svnpenn
done
buffer 80