From ddb309d21a68ad0a75848dc4a2374c5c172a6b89 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Sol=C3=ADs?= Date: Wed, 11 Jun 2025 14:42:49 +0000 Subject: [PATCH] fix: Prevent loss of data already downloaded if interrupted --- youtube-download-channel.sh | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/youtube-download-channel.sh b/youtube-download-channel.sh index 1102e24..6aa9036 100755 --- a/youtube-download-channel.sh +++ b/youtube-download-channel.sh @@ -111,7 +111,6 @@ find "${temporary}" -type f -iname "*.info.json" | while read -r x; do fi fi if [[ -f "${x}" ]]; then - echo "youtube $(jq -cr '.id' "${x}")" >>"${archive}" if [[ ${enablecsv} = "1" ]]; then jq -c '[.upload_date, .timestamp, .uploader , .title, .webpage_url]' "${x}" | while read -r i; do echo "${i}" | sed -e "s/^\[//g" -e "s/\]$//g" -e "s/\\\\\"/"/g" >>"${csv}" @@ -161,7 +160,12 @@ if [[ ${enablecsv} = "1" ]]; then mv "/tmp/${channel}.csv" "${csv}" rm "/tmp/${channel}-without-header.csv" fi -sort "${archive}" | uniq >"/tmp/${channel}.txt" -mv "/tmp/${channel}.txt" "${archive}" cd "${temporary}" || exit -tar -cvp -I "zstd -T0" -f "${subfolder}/${channel}.tar.zst" -- *.info.json && rm -- *.info.json && rm -rf "${temporary}" +tar -cvp -I "zstd -T0" -f "${subfolder}/${channel}.tar.zst" -- *.info.json +find "${temporary}" -type f -iname "*.info.json" | while read -r x; do + if [[ -f "${x}" ]]; then + echo "youtube $(jq -cr '.id' "${x}")" >>"${archive}" + fi +done +sort "${archive}" | uniq >"/tmp/${channel}.txt" && mv "/tmp/${channel}.txt" "${archive}" +rm -rf "${temporary}"