-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtc
executable file
·153 lines (144 loc) · 4.98 KB
/
tc
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
#!/bin/bash
IFS=$'\n'
source $HOME/transcode.conf
cron=false
foldername=''
arg=''
rtinfo=''
hash=''
if [[ "$#" == 1 && "$1" == -* ]]; then
echo "Folder Name is Required. Exiting..."
exit
else
foldername="$1"
fi
if [[ "$#" == 2 ]]; then
arg="$1"
rtinfo="$2"
if [[ -n "${rtinfo}" ]]; then
# note trailing slash here is critical
foldername=$(echo "${rtinfo}" | cut -f1)/
hash=$(echo "${rtinfo}" | cut -f2)
else
echo "No matching torrents. Exiting..."
exit
fi
fi
case "${arg}" in
-cron) cron=true ;;
*) #future use
;;
esac
if [[ -z "${foldername}" || ! -d "${downloads}${foldername}" ]]; then
echo "No matching torrents. Exiting..."
exit
fi
musicfoldercount=0
subfoldercount=$(find "${downloads}${foldername}"*/ -maxdepth 1 -type d -print 2>/dev/null | wc -l)
if [[ "${subfoldercount}" > "0" ]]; then
subfolderlist=''
allsubfolderlist=$(find "${downloads}${foldername}"*/ -maxdepth 1 -type d -printf "%f\n")
# do not apply braces here
for subfoldername in $allsubfolderlist; do
musicfilecount=$(find "${downloads}${foldername}${subfoldername}" -name "*.flac" | wc -l)
echo "subfolder: $downloads$foldername$subfoldername - musicfilecount: ${musicfilecount}"
if [[ "${musicfilecount}" > "0" ]]; then
((musicfoldercount++))
subfolderlist="${subfolderlist}${subfoldername}"$'\n'
fi
done
if [[ "${musicfoldercount}" > "0" ]]; then
firstsubfoldername=$(echo "${subfolderlist}" | head -1)
fi
else
firstsubfoldername=''
fi
# Various Artists?
counter=0
various=false
for flacfile in $(find "${downloads}${foldername}${firstsubfoldername}" -maxdepth 1 -type f -name "*.flac" 2>/dev/null); do
thisartist="$(metaflac --show-tag=ARTIST "${flacfile}" | sed -n -e 's/^ARTIST=//pI' | sed -r 's/[:,?<>*|/]+/-/g')"
if [[ "${counter}" == "0" ]]; then
firstflacfile="${flacfile}"
firstfileartist="${thisartist}"
else
if [[ "${firstfileartist}" != "${thisartist}" ]]; then
various=true
break
fi
fi
(( counter++ ))
done
if ${various}; then
artist="Various Artists"
else
artist="${firstfileartist}"
fi
album=$(metaflac --show-tag=ALBUM "${firstflacfile}" | sed -n -e 's/^ALBUM=//pI' | sed -r 's/[:,?<>*|/]+/-/g')
year=$(metaflac --show-tag=DATE "${firstflacfile}" | sed -n -e 's/^DATE=//pI')
newfolder="$artist - $album ($year) [V0]/"
good=false
if ! "${cron}"; then
echo "${newfolder}"
read -p "Use this folder name? " -n 1 -r
if ! [[ "${REPLY}" =~ ^[yY]$ ]]; then
echo
read -p "Enter the desired folder name: "
newfolder="$REPLY"
echo "$newfolder"
read -p "Use this folder name? " -n 1 -r
if [[ "${REPLY}" =~ ^[yY]$ ]]; then
good=true
fi
else
good=true
fi
case "${newfolder}" in
*/) # do nothing
;;
*) newfolder="$newfolder/";;
esac
else
# this is cron job
if [[ -n "${artist}" && -n "${album}" && -n "${year}" ]]; then
good=true
/usr/local/bin/rtcontrol --from-view main \* -qo name hash=${hash} --custom=1="tc_processing"
else
echo "Bad or no tags"
/usr/local/bin/rtcontrol --from-view main \* -qo name hash=${hash} --custom=1="tc_failed"
subject="Transcode Failed - ${foldername}"
mail="subject:${subject}\nfrom:${from}\nThe title says it all, but Google wants more, so here is some more text. This folder could not be transcoded -Your Friend, Sterns"
echo -e "$mail" | /usr/sbin/sendmail "$recipients"
exit
fi
fi
if ${good}; then
if [[ "${musicfoldercount}" == "0" ]]; then
echo
echo "Great! Transcoding..."
mkdir "${downloads}${newfolder}"
parallel -j${maxthreads} avconv -i {} -codec:v copy -qscale:a 0 {.}.mp3 ::: "${downloads}${foldername}"*.flac
mv "${downloads}${foldername}"*.{mp3,jpg,png,log,txt} "${downloads}${newfolder}"
echo "Finished Transcoding."
else
for subfoldername in $subfolderlist; do
mkdir -p "${downloads}${newfolder}${subfoldername}"
parallel -j${maxthreads} avconv -i {} -codec:v copy -qscale:a 0 {.}.mp3 ::: "${downloads}${foldername}${subfoldername}"*.flac
mv "${downloads}${foldername}${subfoldername}"*.{mp3,jpg,png,log,txt} "${downloads}${newfolder}${subfoldername}"
echo "Finished Transcoding a Subfolder"
done
fi
echo "Start Torrent Creation..."
"${binfolder}"/py3createtorrent.py -P "${downloads}${newfolder}" what -o /home/seeder1/rtorrent/newtorrent/
newtorrent="${newfolder%/}".torrent
cp "/home/seeder1/rtorrent/newtorrent/${newtorrent}" "${watchfolder}"
"${binfolder}"/rtcontrol --from-view main \* -qo name hash=${hash} --custom=1=""
subject="Transcode Completed - ${foldername}"
mail="subject:${subject}\nfrom:${from}\nThe title says it all, but Google wants more, so here is some more text.\n \
https://what.cd/torrents.php?groupname=${hash}"
echo -e "${mail}" | /usr/sbin/sendmail "${recipients}"
else
echo
echo "Aborted!"
echo
fi