我正在运行一个Bash脚本,该脚本通过一个包含视频的目录并重新下载(使用youtube-dl)以更新元数据。问题是如果必须下载一些(因为原始视频已经改变),必须提供当前路径。这本身没有问题,但我注意到在调用youtube-dl的循环之后,绝对路径被截断。
我仍然找不到错误模式。截断总是不同,但截断的路径总是相同的,但有一点是肯定的,如果没有调用youtube-dl,则所有路径都是完整的。
#!/bin/bash
path="$1"
youtube_regex=".*\([a-zA-Z0-9_-]\{11\}\)^*";
vimeo_regex=".*\-\([0-9]\{8\}\).^*";
while read -d '' filename;
do
echo "FILE: $filename";
#directoryname="$(dirname "$filename")";
directoryname="${filename%/*}";
cd "$directoryname";
echo "WORKING DIRECTORY: `pwd`";
echo "ABSOLUTE PATH + LOCAL FILENAME: $filename";
video_id=`expr "$filename" : $youtube_regex`;
if [ -n "$video_id" ];
then
video_url="https://www.youtube.com/watch?v=$video_id";
else
video_id=`expr "$filename" : $vimeo_regex`;
video_url="https://vimeo.com/$video_id";
if [ -z "$video_id" ];
then
echo "VIDEO ID: NULL";
fi;
fi;
if [ -n "$video_url" ];
then
youtube-dl "$video_url"; # <- this seems to be the cause
else
echo 'METADATA DOWNLOAD UNSUCESSFUL';
fi;
echo '+-----------------------------------------+';
echo '| FILE PROCESS FINISHED |';
echo '+-----------------------------------------+';
done < <(find "$path" -type f \( -name \*mp4 -or -name \*flv -or -name \*webm \) -print0);
编辑:这是错误的一个示例(如果您想查看截断的路径,只需查找带有消息ERROR: Interrupted by user
的块)。
nelson@triplecero:~$ ./write_video_metadata.sh /media/SAMSUNG/Video/
FILE: /media/SAMSUNG/Video/Music Videos/Bass Guitar/Yolanda Charles and Phil Gould - Bass Syncopation Exercise-T3Lszt2HPK8.mp4
WORKING DIRECTORY: /media/SAMSUNG/Video/Music Videos/Bass Guitar
ABSOLUTE PATH + LOCAL FILENAME: /media/SAMSUNG/Video/Music Videos/Bass Guitar/Yolanda Charles and Phil Gould - Bass Syncopation Exercise-T3Lszt2HPK8.mp4
[youtube] T3Lszt2HPK8: Downloading webpage
[youtube] T3Lszt2HPK8: Extracting video information
[youtube] T3Lszt2HPK8: Looking for automatic captions
WARNING: Couldn't find automatic captions for T3Lszt2HPK8
WARNING: video doesn't have subtitles
[download] Yolanda Charles and Phil Gould - Bass Syncopation Exercise-T3Lszt2HPK8.mp4 has already been downloaded
[ffmpeg] Adding metadata to 'Yolanda Charles and Phil Gould - Bass Syncopation Exercise-T3Lszt2HPK8.mp4'
+-----------------------------------------+
| FILE PROCESS FINISHED |
+-----------------------------------------+
FILE: hgQ.mp4
./write_video_metadata.sh: línea 30: cd: hgQ.mp4: No existe el fichero o el directorio
WORKING DIRECTORY: /media/SAMSUNG/Video/Music Videos/Bass Guitar
ABSOLUTE PATH + LOCAL FILENAME: hgQ.mp4
VIDEO ID: NULL
[generic] vimeo: Requesting header
WARNING: Falling back on generic information extractor.
[generic] vimeo: Downloading webpage
[generic] vimeo: Extracting information
[download] Resuming download at byte 465123
[download] Destination: Vimeo, Your Videos Belong Here-yosemite_hd_ii_hd.webm
[download] 1.5% of 77.29MiB at 161.94KiB/s ETA 08:01^C
ERROR: Interrupted by user
+-----------------------------------------+
| FILE PROCESS FINISHED |
+-----------------------------------------+
FILE: /media/SAMSUNG/Video/Music Videos/100 best music videos of all time/Metallica - Turn The Page-dOibtqWo6z4.mp4
WORKING DIRECTORY: /media/SAMSUNG/Video/Music Videos/100 best music videos of all time
ABSOLUTE PATH + LOCAL FILENAME: /media/SAMSUNG/Video/Music Videos/100 best music videos of all time/Metallica - Turn The Page-dOibtqWo6z4.mp4
[youtube] dOibtqWo6z4: Downloading webpage
[youtube] dOibtqWo6z4: Extracting video information
[youtube] dOibtqWo6z4: Looking for automatic captions
[youtube] dOibtqWo6z4: Downloading XML
WARNING: video doesn't have subtitles
[info] Writing video subtitles to: Metallica - Turn The Page-dOibtqWo6z4.en.srt
[info] Writing video subtitles to: Metallica - Turn The Page-dOibtqWo6z4.es.srt
[download] Metallica - Turn The Page-dOibtqWo6z4.mp4 has already been downloaded
[ffmpeg] Adding metadata to 'Metallica - Turn The Page-dOibtqWo6z4.mp4'
+-----------------------------------------+
| FILE PROCESS FINISHED |
+-----------------------------------------+
FILE: ive in Harlem/Gorillaz - Feel Good Inc (Live in Harlem)-1wuPOY-TDk4.mp4
./write_video_metadata.sh: línea 30: cd: ive in Harlem: No existe el fichero o el directorio
WORKING DIRECTORY: /media/SAMSUNG/Video/Music Videos/100 best music videos of all time
ABSOLUTE PATH + LOCAL FILENAME: ive in Harlem/Gorillaz - Feel Good Inc (Live in Harlem)-1wuPOY-TDk4.mp4
[youtube] 1wuPOY-TDk4: Downloading webpage
[youtube] 1wuPOY-TDk4: Extracting video information
[youtube] 1wuPOY-TDk4: Looking for automatic captions
WARNING: Couldn't find automatic captions for 1wuPOY-TDk4
WARNING: video doesn't have subtitles
[download] Destination: Gorillaz - Feel Good Inc (Live in Harlem)-1wuPOY-TDk4.mp4
[download] 1.3% of 15.37MiB at 147.45KiB/s ETA 01:45^C
ERROR: Interrupted by user
+-----------------------------------------+
| FILE PROCESS FINISHED |
+-----------------------------------------+
FILE: /media/SAMSUNG/Video/Music Videos/Gorillaz/thegreatmonster/Gorillaz - Spitting Out The Demons-MPn7l5a9sKg.mp4
WORKING DIRECTORY: /media/SAMSUNG/Video/Music Videos/Gorillaz/thegreatmonster
ABSOLUTE PATH + LOCAL FILENAME: /media/SAMSUNG/Video/Music Videos/Gorillaz/thegreatmonster/Gorillaz - Spitting Out The Demons-MPn7l5a9sKg.mp4
[youtube] MPn7l5a9sKg: Downloading webpage
[youtube] MPn7l5a9sKg: Extracting video information
[youtube] MPn7l5a9sKg: Looking for automatic captions
WARNING: Couldn't find automatic captions for MPn7l5a9sKg
WARNING: video doesn't have subtitles
[download] Gorillaz - Spitting Out The Demons-MPn7l5a9sKg.mp4 has already been downloaded
[ffmpeg] Adding metadata to 'Gorillaz - Spitting Out The Demons-MPn7l5a9sKg.mp4'
+-----------------------------------------+
| FILE PROCESS FINISHED |
+-----------------------------------------+
FILE: n TODOBAJOS TV - Introducción al flamenco II-j28g33HAQ6E.mp4
./write_video_metadata.sh: línea 30: cd: n TODOBAJOS TV - Introducción al flamenco II-j28g33HAQ6E.mp4: No existe el fichero o el directorio
WORKING DIRECTORY: /media/SAMSUNG/Video/Music Videos/Gorillaz/thegreatmonster
ABSOLUTE PATH + LOCAL FILENAME: n TODOBAJOS TV - Introducción al flamenco II-j28g33HAQ6E.mp4
[youtube] j28g33HAQ6E: Downloading webpage
[youtube] j28g33HAQ6E: Extracting video information
[youtube] j28g33HAQ6E: Looking for automatic captions
WARNING: Couldn't find automatic captions for j28g33HAQ6E
WARNING: video doesn't have subtitles
[download] Resuming download at byte 64512
[download] Destination: (2_3) CARLES BENAVENT en TODOBAJOS TV - Introducción al flamenco II-j28g33HAQ6E.mp4
[download] 0.2% of 49.65MiB at 150.71KiB/s ETA 05:36^C
ERROR: Interrupted by user
+-----------------------------------------+
| FILE PROCESS FINISHED |
+-----------------------------------------+
FILE: /media/SAMSUNG/Video/Music Videos/TodobajosTV/(5_5) CHARLIE MORENO en TODOBAJOS TV - SOLO-4Z1zoVq-FwY.mp4
WORKING DIRECTORY: /media/SAMSUNG/Video/Music Videos/TodobajosTV
ABSOLUTE PATH + LOCAL FILENAME: /media/SAMSUNG/Video/Music Videos/TodobajosTV/(5_5) CHARLIE MORENO en TODOBAJOS TV - SOLO-4Z1zoVq-FwY.mp4
^Z
[1]+ Detenido ./write_video_metadata.sh /media/SAMSUNG/Video/
nelson@triplecero:~$