From dbefa868bfdf1fd84ffe8f64c0836fcda7da0c07 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Sol=C3=ADs?= Date: Fri, 30 May 2025 19:49:04 +0000 Subject: [PATCH] fix: Correct parsing logic --- README.md | 4 ++++ youtube-download-channel.sh | 14 +++++++++----- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index a79abc3..1b9cce1 100755 --- a/README.md +++ b/README.md @@ -2,6 +2,10 @@ Public scripts for assorted web maintenance tasks used in my server. +# This is a mirrored repository + +If you're browsing this repository from [GitHub](https://github.com/csolisr/public-scripts), you should know that the main home for these files is on [my personal server over Forgejo](https://code.azkware.net/csolisr/public-scripts). + # Description As you can see, the vast majority of my scripts are used to handle my [Friendica](https://friendi.ca) server, especially where the default PHP would take too long or not cover my usage case. diff --git a/youtube-download-channel.sh b/youtube-download-channel.sh index db0e1b5..aabab23 100755 --- a/youtube-download-channel.sh +++ b/youtube-download-channel.sh @@ -54,8 +54,11 @@ else --sleep-requests "${sleeptime}" fi rm -rf "${csv}" -ls -t | grep -e ".info.json" | while read -r x; do - echo youtube $(jq -c '.id' "${x}" | sed -e "s/\"//g") | tee -a "${archive}" & +#ls -t | grep -e ".info.json" | while read -r x; do +find . -type f -iname "*.info.json" -exec ls -t {} + | while read -r xp; do + x="${xp##./}" + #echo youtube $(jq -c '.id' "${x}" | sed -e "s/\"//g") | tee -a "${archive}" & + echo "youtube $(jq -cr '.id' "${x}")" | tee -a "${archive}" & 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}" & done @@ -69,15 +72,16 @@ done wait sort "${sortcsv}" | uniq >"/tmp/${channel}-sort-ordered.csv" echo "{\"playlistName\":\"${channel}\",\"protected\":false,\"description\":\"Videos to watch later\",\"videos\":[" >"/tmp/${channel}.db" -cat "/tmp/${channel}-sort-ordered.csv" | while read -r line; do +#cat "/tmp/${channel}-sort-ordered.csv" | while read -r line; do +while read -r line; do file=$(echo "${line}" | cut -d ',' -f3-) echo "${file}" jq -c "{\"videoId\": .id, \"title\": .title, \"author\": .uploader, \"authorId\": .channel_id, \"lengthSeconds\": .duration, \"published\": .epoch, \"timeAdded\": $(date +%s), \"playlistItemId\": \"$(cat /proc/sys/kernel/random/uuid)\", \"type\": \"video\"}" "${subfolder}/${file}" | tee -a "/tmp/${channel}.db" echo "," >>"/tmp/${channel}.db" -done +done <"/tmp/${channel}-sort-ordered.csv" echo "],\"_id\":\"${channel}\",\"createdAt\":$(date +%s),\"lastUpdatedAt\":$(date +%s)}" >>"/tmp/${channel}.db" rm "${json}" -cat "/tmp/${channel}.db" | grep -v -e ":[ ]*null" | tr '\n' '\r' | sed -e "s/,\r\]/\]/g" | tr '\r' '\n' | jq -c "." >"${json}" && rm "/tmp/${channel}.db" +grep -v -e ":[ ]*null" "/tmp/${channel}.db" | tr '\n' '\r' | sed -e "s/,\r[,\r]*/,\r/g" | sed -e "s/,\r\]/\]/g" | tr '\r' '\n' | jq -c . >"${json}" && rm "/tmp/${channel}.db" rm "/tmp/${channel}-sort-ordered.csv" "${sortcsv}" sort "${csv}" | uniq >"/tmp/${channel}-without-header.csv" echo '"Upload Date", "Timestamp", "Uploader", "Title", "Webpage URL"' >"/tmp/${channel}.csv"