Skip to content

Commit 50df232

Browse files
v2.0 - Download to a temp folder
#299 - Resolves this for sonarr
1 parent b78ff08 commit 50df232

File tree

1 file changed

+26
-7
lines changed

1 file changed

+26
-7
lines changed

sonarr/Extras.bash

Lines changed: 26 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#!/usr/bin/env bash
2-
scriptVersion="1.9"
2+
scriptVersion="2.0"
33
arrEventType="$sonarr_eventtype"
44
arrItemId=$sonarr_series_id
55
tmdbApiKey="3b7751e3179f796565d88fdb2fcdf426"
@@ -136,28 +136,47 @@ DownloadExtras () {
136136

137137
videoLanguages="$(echo "$extrasLanguages" | sed "s/-[[:alpha:]][[:alpha:]]//g")"
138138

139+
tempFolder="/config/extended/temp"
140+
if [ -d "$tempFolder" ]; then
141+
rm -rf "$tempFolder"
142+
sleep 0.01
143+
fi
144+
145+
if [ ! -d "$tempFolder" ]; then
146+
mkdir -p "$tempFolder"
147+
fi
148+
139149
log "$itemTitle :: $i of $tmdbVideosListDataIdsCount :: $tmdbExtraType :: $tmdbExtraTitle ($tmdbExtraKey) :: Downloading (yt-dlp :: $videoFormat)..."
140150
if [ ! -z "$cookiesFile" ]; then
141-
yt-dlp -f "$videoFormat" --no-video-multistreams --cookies "$cookiesFile" -o "$finalPath/$finalFileName" --write-sub --sub-lang $videoLanguages --embed-subs --merge-output-format mkv --no-mtime --geo-bypass $ytdlpExtraOpts "https://www.youtube.com/watch?v=$tmdbExtraKey" 2>&1 | tee -a /config/logs/$scriptName.txt
151+
yt-dlp -f "$videoFormat" --no-video-multistreams --cookies "$cookiesFile" -o "$tempFolder/$finalFileName" --write-sub --sub-lang $videoLanguages --embed-subs --merge-output-format mkv --no-mtime --geo-bypass $ytdlpExtraOpts "https://www.youtube.com/watch?v=$tmdbExtraKey" 2>&1 | tee -a /config/logs/$scriptName.txt
142152
else
143-
yt-dlp -f "$videoFormat" --no-video-multistreams -o "$finalPath/$finalFileName" --write-sub --sub-lang $videoLanguages --embed-subs --merge-output-format mkv --no-mtime --geo-bypass $ytdlpExtraOpts "https://www.youtube.com/watch?v=$tmdbExtraKey" 2>&1 | tee -a /config/logs/$scriptName.txt
153+
yt-dlp -f "$videoFormat" --no-video-multistreams -o "$tempFolder/$finalFileName" --write-sub --sub-lang $videoLanguages --embed-subs --merge-output-format mkv --no-mtime --geo-bypass $ytdlpExtraOpts "https://www.youtube.com/watch?v=$tmdbExtraKey" 2>&1 | tee -a /config/logs/$scriptName.txt
144154
fi
145-
if [ -f "$finalPath/$finalFileName.mkv" ]; then
155+
if [ -f "$tempFolder/$finalFileName.mkv" ]; then
146156
log "$itemTitle :: $i of $tmdbVideosListDataIdsCount :: $tmdbExtraType :: $tmdbExtraTitle ($tmdbExtraKey) :: Compete"
147-
chmod 666 "$finalPath/$finalFileName.mkv"
148157
else
149158
log "$itemTitle :: $i of $tmdbVideosListDataIdsCount :: $tmdbExtraType :: $tmdbExtraTitle ($tmdbExtraKey) :: ERROR :: Download Failed"
150159
continue
151160
fi
152161

153-
if python3 /config/extended/sma/manual.py --config "/config/extended/sma.ini" -i "$finalPath/$finalFileName.mkv" -nt; then
162+
if python3 /config/extended/sma/manual.py --config "/config/extended/sma.ini" -i "$tempFolder/$finalFileName.mkv" -nt; then
154163
log "$itemTitle :: $i of $tmdbVideosListDataIdsCount :: $tmdbExtraType :: $tmdbExtraTitle :: Processed with SMA..."
155164
rm /config/extended/sma/config/*log*
156165
else
157166
log "$itemTitle :: $i of $tmdbVideosListDataIdsCount :: $tmdbExtraType :: $tmdbExtraTitle :: ERROR :: SMA Processing Error"
158167
rm "$finalPath/$finalFileName.mkv"
159-
log "$itemTitle :: $i of $tmdbVideosListDataIdsCount :: $tmdbExtraType :: $tmdbExtraTitle :: INFO: deleted: $finalPath/$finalFileName.mkv"
168+
log "$itemTitle :: $i of $tmdbVideosListDataIdsCount :: $tmdbExtraType :: $tmdbExtraTitle :: INFO: deleted: $tempFolder/$finalFileName.mkv"
160169
fi
170+
171+
if [ -f "$tempFolder/$finalFileName.mkv" ]; then
172+
log "$itemTitle :: $i of $tmdbVideosListDataIdsCount :: $tmdbExtraType :: $tmdbExtraTitle :: Moving file to final destination"
173+
mv "$tempFolder/$finalFileName.mkv" "$finalPath/$finalFileName.mkv"
174+
chmod 666 "$finalPath/$finalFileName.mkv"
175+
if [ -d "$tempFolder" ]; then
176+
rm -rf "$tempFolder"
177+
fi
178+
fi
179+
161180
updatePlex="true"
162181
done
163182
done

0 commit comments

Comments
 (0)