Salue zusammen,
ich bin grade echt verwirrt. Ich hab n kleines Skript zusammengehackt, das per yt-dlp nach neuen Episoden in einer Playlist sucht, und diese bei Bedarf runterlädt. Klappt auch einwandfrei - WENN ich es händisch ausführe. Der Eintrag in die crontab als @daily läuft zwar, daber geht aber was schief.
Hier zunächst das Skript (bitte nur leise auslachen, danke).
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 | #!/bin/bash #for debugging set -xv BASEPATH="/home/ICH/bin" cd $BASEPATH PLAYLIST="https://www.youtube.com/watch?v=P8pLvV3FjPc&list=PL1tiwbzkOjQydg3QOkBLG9OYqWJ0dwlxF" CURRENT=$(<NOofEpisodes) declare -i DIFFERENCE=0 TARGETPATH="/Pfad/Zu/Mediaserver" echo $(date -u) "Last count of episodes: $CURRENT" >> log.file 2>&1 echo $(date -u) "Downloading Critical Role Campaign 3 Playlist as json and saving it as cr3.json" >> log.file 2>&1 yt-dlp --flat-playlist --print-json "$PLAYLIST" > cr3.json #using jq to read cr3.json and output number of episodes. NEW=$(jq -s length cr3.json) echo $(date -u) "New count of episodes: $NEW" >> log.file 2>&1 #Calculate $DIFFERENCE. If >0 download as many episodes from playlist #Substrace NEW from CURRENT; double brackets to transform strings to integers ((DIFFERENCE=$NEW-$CURRENT)) echo $(date -u) "Difference is: $DIFFERENCE" >> log.file 2>&1 #IF DIFFERENCE is >0 start downloading from episode $CURRENT to episode $NEW if [ $DIFFERENCE -gt 0 ] then echo $(date -u) "There is at least 1 new episode of CR 3. Starting download!" >> log.file 2>&1 ((START=$CURRENT+1)) yt-dlp -f 22 --playlist-start $START --playlist-end $NEW -P "$TARGETPATH" $PLAYLIST else echo -e $(date -u) "There are no new episodes. \n*sad smiley* \nIs it THURSDAY yet?" >> log.file 2>&1 fi ##Writing current episode number to NOofEpisodes echo $(date -u) "New episode count now: $NEW" >> log.file 2>&1 echo $NEW > NOofEpisodes #end debugging set +xv |
Und händisch ausgeführt klappt das auch. Das JSON wird heruntergeladen, durch jq gejagt, die Zahl der items ausgelesen, schön mit der Zahl in NOofEpisodes verglichen, hübsch geloggt, alles propper.
So sieht das dann im Log aus:
Wed Mar 23 07:26:19 UTC 2022 Last count of episodes: 16 Wed Mar 23 07:26:19 UTC 2022 Downloading Critical Role Campaign 3 Playlist as json and saving it as cr3.json Wed Mar 23 07:26:21 UTC 2022 New count of episodes: 16 Wed Mar 23 07:26:21 UTC 2022 Difference is: 0 Wed Mar 23 07:26:21 UTC 2022 There are no new episodes. *sad smiley* Is it THURSDAY yet? Wed Mar 23 07:26:21 UTC 2022 New episode count now: 16
Wenn das dann aber von crontab ausgeführt wird, passiert folgendes:
Wed 23 Mar 2022 08:00:01 AM UTC Last count of episodes: 16 Wed 23 Mar 2022 08:00:01 AM UTC Downloading Critical Role Campaign 3 Playlist as json and saving it as cr3.json Wed 23 Mar 2022 08:00:01 AM UTC New count of episodes: 0 Wed 23 Mar 2022 08:00:01 AM UTC Difference is: -16 Wed 23 Mar 2022 08:00:01 AM UTC There are no new episodes. *sad smiley* Is it THURSDAY yet? Wed 23 Mar 2022 08:00:01 AM UTC New episode count now: 0
yt-dlp lädt also offenbar nichts herunter, cr.json bleibt leer, alles geht in die Grütze. Woran liegt das?
Ich geh jetzt mal hin und bastele ne Abfrage mit Abbruch rein, damit mir das verkorkste yt-dlp nicht immer die NOofEpisode zerschießt, aber insgesamt wäre ich für Hilfe sehr aufgeschlossen.