feat: Optimize file analysis loop
This commit is contained in:
parent
74af7e44ea
commit
46cf852324
1 changed files with 33 additions and 28 deletions
|
@ -76,41 +76,46 @@ if [[ ! -f "${sortcsv}" ]]; then
|
||||||
fi
|
fi
|
||||||
db=$(date -d"${breaktime}" +"%s")
|
db=$(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 [[ "${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]+$ ]]; then
|
if [[ -f "${subfolder}/${x}" && "${breaktime}" =~ ^[0-9]+$ && "${db}" -ge "${df}" ]]; then
|
||||||
|
echo "Video ${x} uploaded before ${breaktime}, removing..." && rm "${subfolder}/${x}" #&
|
||||||
|
fi
|
||||||
|
if [[ -f "${subfolder}/${x}" ]]; then
|
||||||
df=$(jq -rc '.timestamp' "${subfolder}/${x}")
|
df=$(jq -rc '.timestamp' "${subfolder}/${x}")
|
||||||
if [[ "${db}" -ge "${df}" ]]; then
|
touch "${subfolder}/${x}" -d "@${df}" #&
|
||||||
echo "Video ${x} uploaded before ${breaktime}, removing..." && rm "${subfolder}/${x}" &
|
|
||||||
else
|
|
||||||
touch "${subfolder}/${x}" -d "@${df}" &
|
|
||||||
fi
|
|
||||||
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
|
||||||
if [[ $(jobs -r -p | wc -l) -ge $(($(getconf _NPROCESSORS_ONLN) * 3 * 2)) ]]; then
|
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
|
||||||
wait -n
|
wait -n
|
||||||
fi
|
fi
|
||||||
fi
|
|
||||||
done
|
done
|
||||||
wait
|
wait
|
||||||
if [[ ${enablecsv} = "1" || ${enabledb} = "1" ]]; then
|
if [[ ${enablecsv} = "1" || ${enabledb} = "1" ]]; then
|
||||||
sort "${sortcsv}" | uniq >"/tmp/${channel}-sort-ordered.csv"
|
sort "${sortcsv}" | uniq >"/tmp/${channel}-sort-ordered.csv"
|
||||||
fi
|
fi
|
||||||
if [[ ${enabledb} = "1" ]]; then
|
if [[ ${enabledb} = "1" ]]; then
|
||||||
|
if [[ -f "/tmp/${channel}.db" ]]; then
|
||||||
rm "/tmp/${channel}.db"
|
rm "/tmp/${channel}.db"
|
||||||
|
fi
|
||||||
echo "{\"playlistName\":\"${channel}\",\"protected\":false,\"description\":\"Videos from ${channel} to watch later\",\"videos\":[" >"/tmp/${channel}.db"
|
echo "{\"playlistName\":\"${channel}\",\"protected\":false,\"description\":\"Videos from ${channel} to watch later\",\"videos\":[" >"/tmp/${channel}.db"
|
||||||
fi
|
fi
|
||||||
if [[ ${enablecsv} = "1" || ${enabledb} = "1" ]]; then
|
if [[ ${enablecsv} = "1" || ${enabledb} = "1" ]]; then
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue