fix: Correct logic flow, add comments
This commit is contained in:
parent
46cf852324
commit
544f80da84
1 changed files with 24 additions and 14 deletions
|
@ -18,7 +18,6 @@ folder=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd)
|
||||||
# https://github.com/yt-dlp/yt-dlp/wiki/FAQ#how-do-i-pass-cookies-to-yt-dlp
|
# https://github.com/yt-dlp/yt-dlp/wiki/FAQ#how-do-i-pass-cookies-to-yt-dlp
|
||||||
#and place it next to your script.
|
#and place it next to your script.
|
||||||
cookies="${folder}/yt-cookies.txt"
|
cookies="${folder}/yt-cookies.txt"
|
||||||
#subfolder="${folder}/${channel}"
|
|
||||||
subfolder="${folder}/subscriptions"
|
subfolder="${folder}/subscriptions"
|
||||||
archive="${subfolder}/${channel}.txt"
|
archive="${subfolder}/${channel}.txt"
|
||||||
sortcsv="${subfolder}/${channel}-sort.csv"
|
sortcsv="${subfolder}/${channel}-sort.csv"
|
||||||
|
@ -46,25 +45,34 @@ if [[ -f "${channel}.tar.zst" ]]; then
|
||||||
tar -xvp -I zstd -f "${channel}.tar.zst"
|
tar -xvp -I zstd -f "${channel}.tar.zst"
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
#If available, you can use the cookies from your browser directly:
|
|
||||||
# --cookies-from-browser "firefox"
|
|
||||||
url="https://www.youtube.com/@${channel}"
|
url="https://www.youtube.com/@${channel}"
|
||||||
if [[ "${channel}" = "subscriptions" ]]; then
|
if [[ "${channel}" = "subscriptions" ]]; then
|
||||||
url="https://www.youtube.com/feed/subscriptions"
|
url="https://www.youtube.com/feed/subscriptions"
|
||||||
fi
|
fi
|
||||||
if [[ -f "${cookies}" && "${channel}" = "subscriptions" ]]; then
|
if [[ -f "${cookies}" && "${channel}" = "subscriptions" ]]; then
|
||||||
"${python}" "${ytdl}" "${url}" \
|
"${python}" "${ytdl}" "${url}" \
|
||||||
|
--extractor-args "youtubetab:approximate_date" \
|
||||||
--skip-download --download-archive "${archive}" \
|
--skip-download --download-archive "${archive}" \
|
||||||
--dateafter "${breaktime}" \
|
--dateafter "${breaktime}" \
|
||||||
--extractor-args youtubetab:approximate_date \
|
|
||||||
--break-on-reject --lazy-playlist --write-info-json \
|
--break-on-reject --lazy-playlist --write-info-json \
|
||||||
--sleep-requests "${sleeptime}"
|
--sleep-requests "${sleeptime}"
|
||||||
else
|
else
|
||||||
|
#If available, you can use the cookies from your browser directly. Substitute
|
||||||
|
# --cookies "${cookies}"
|
||||||
|
#for the below, substituting for your browser of choice:
|
||||||
|
# --cookies-from-browser "firefox"
|
||||||
|
#In case this still fails, you can resort to a PO Token. Follow the instructions at
|
||||||
|
# https://github.com/yt-dlp/yt-dlp/wiki/PO-Token-Guide
|
||||||
|
#and add a new variable with the contents of the PO Token in the form
|
||||||
|
# potoken="INSERTYOURPOTOKENHERE"
|
||||||
|
#then substitute the "--extractor-args" line below with
|
||||||
|
# --extractor-args "youtubetab:approximate_date,youtube:player-client=default,mweb;po_token=mweb.gvs+${potoken}" \
|
||||||
|
#including the backslash so the multiline command keeps working.
|
||||||
"${python}" "${ytdl}" "${url}" \
|
"${python}" "${ytdl}" "${url}" \
|
||||||
--cookies "${cookies}" \
|
--cookies "${cookies}" \
|
||||||
|
--extractor-args "youtubetab:approximate_date" \
|
||||||
--skip-download --download-archive "${archive}" \
|
--skip-download --download-archive "${archive}" \
|
||||||
--dateafter "${breaktime}" \
|
--dateafter "${breaktime}" \
|
||||||
--extractor-args youtubetab:approximate_date \
|
|
||||||
--break-on-reject --lazy-playlist --write-info-json \
|
--break-on-reject --lazy-playlist --write-info-json \
|
||||||
--sleep-requests "${sleeptime}"
|
--sleep-requests "${sleeptime}"
|
||||||
fi
|
fi
|
||||||
|
@ -74,35 +82,37 @@ fi
|
||||||
if [[ ! -f "${sortcsv}" ]]; then
|
if [[ ! -f "${sortcsv}" ]]; then
|
||||||
touch "${sortcsv}"
|
touch "${sortcsv}"
|
||||||
fi
|
fi
|
||||||
db=$(date -d"${breaktime}" +"%s")
|
breaktime_timestamp=$(date -d"${breaktime}" +"%s")
|
||||||
find . -type f -iname "*.info.json" -exec ls -t {} + | while read -r xp; do
|
find . -type f -iname "*.info.json" -exec ls -t {} + | while read -r xp; do
|
||||||
(
|
(
|
||||||
x="${xp##./}"
|
x="${xp##./}"
|
||||||
if [[ -f "${subfolder}/${x}" && "${channel}" != "subscriptions" && $(jq -rc ".uploader_id" "${subfolder}/${x}") != "@${channel}" ]]; then
|
if [[ -f "${subfolder}/${x}" && "${channel}" != "subscriptions" && $(jq -rc ".uploader_id" "${subfolder}/${x}") != "@${channel}" ]]; then
|
||||||
echo "Video ${x} not uploaded from ${channel}, removing..." && rm "${subfolder}/${x}" #&
|
echo "Video ${x} not uploaded from ${channel}, removing..." && rm "${subfolder}/${x}"
|
||||||
fi
|
fi
|
||||||
if [[ -f "${subfolder}/${x}" && "${breaktime}" =~ ^[0-9]+$ && "${db}" -ge "${df}" ]]; then
|
if [[ -f "${subfolder}/${x}" && "${breaktime}" =~ ^[0-9]+$ ]]; then
|
||||||
echo "Video ${x} uploaded before ${breaktime}, removing..." && rm "${subfolder}/${x}" #&
|
file_timestamp=$(jq -rc '.timestamp' "${subfolder}/${x}")
|
||||||
|
if [[ "${breaktime_timestamp}" -ge "${file_timestamp}" ]]; then
|
||||||
|
echo "Video ${x} uploaded before ${breaktime}, removing..." && rm "${subfolder}/${x}"
|
||||||
|
fi
|
||||||
fi
|
fi
|
||||||
if [[ -f "${subfolder}/${x}" ]]; then
|
if [[ -f "${subfolder}/${x}" ]]; then
|
||||||
df=$(jq -rc '.timestamp' "${subfolder}/${x}")
|
file_timestamp=$(jq -rc '.timestamp' "${subfolder}/${x}")
|
||||||
touch "${subfolder}/${x}" -d "@${df}" #&
|
touch "${subfolder}/${x}" -d "@${file_timestamp}"
|
||||||
fi
|
fi
|
||||||
if [[ -f "${subfolder}/${x}" ]]; then
|
if [[ -f "${subfolder}/${x}" ]]; then
|
||||||
echo "youtube $(jq -cr '.id' "${subfolder}/${x}")" | tee -a "${archive}" &
|
echo "youtube $(jq -cr '.id' "${subfolder}/${x}")" | tee -a "${archive}" &
|
||||||
if [[ ${enablecsv} = "1" ]]; then
|
if [[ ${enablecsv} = "1" ]]; then
|
||||||
jq -c '[.upload_date, .timestamp, .uploader , .title, .webpage_url]' "${subfolder}/${x}" | while read -r i; do
|
jq -c '[.upload_date, .timestamp, .uploader , .title, .webpage_url]' "${subfolder}/${x}" | while read -r i; do
|
||||||
echo "${i}" | sed -e "s/^\[//g" -e "s/\]$//g" -e "s/\\\\\"/"/g" | tee -a "${csv}" #&
|
echo "${i}" | sed -e "s/^\[//g" -e "s/\]$//g" -e "s/\\\\\"/"/g" | tee -a "${csv}"
|
||||||
done
|
done
|
||||||
fi
|
fi
|
||||||
if [[ ${enablecsv} = "1" || ${enabledb} = "1" ]]; then
|
if [[ ${enablecsv} = "1" || ${enabledb} = "1" ]]; then
|
||||||
jq -c '[.upload_date, .timestamp]' "${subfolder}/${x}" | while read -r i; do
|
jq -c '[.upload_date, .timestamp]' "${subfolder}/${x}" | while read -r i; do
|
||||||
echo "${i},${x}" | sed -e "s/^\[//g" -e "s/\],/,/g" -e "s/\\\\\"/"/g" | tee -a "${sortcsv}" #&
|
echo "${i},${x}" | sed -e "s/^\[//g" -e "s/\],/,/g" -e "s/\\\\\"/"/g" | tee -a "${sortcsv}"
|
||||||
done
|
done
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
) &
|
) &
|
||||||
#if [[ $(jobs -r -p | wc -l) -ge $(($(getconf _NPROCESSORS_ONLN) * 3 * 2)) ]]; then
|
|
||||||
if [[ $(jobs -r -p | wc -l) -ge $(getconf _NPROCESSORS_ONLN) ]]; then
|
if [[ $(jobs -r -p | wc -l) -ge $(getconf _NPROCESSORS_ONLN) ]]; then
|
||||||
wait -n
|
wait -n
|
||||||
fi
|
fi
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue