feat: Add preliminary support for Termux, reduce temporary file size

This commit is contained in:
Carlos Solís 2025-06-16 14:42:44 +00:00
parent 0cacefbcf8
commit 9b7e9c9553

View file

@ -20,6 +20,9 @@ folder=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd)
cookies="${folder}/yt-cookies.txt" cookies="${folder}/yt-cookies.txt"
subfolder="${folder}/subscriptions" subfolder="${folder}/subscriptions"
temporary="/tmp/subscriptions-${channel}" temporary="/tmp/subscriptions-${channel}"
if [[ ! -w "/tmp" ]]; then
temporary="${subfolder}/subscriptions-${channel}"
fi
archive="${subfolder}/${channel}.txt" archive="${subfolder}/${channel}.txt"
sortcsv="${temporary}/${channel}-sort.csv" sortcsv="${temporary}/${channel}-sort.csv"
csv="${subfolder}/${channel}.csv" csv="${subfolder}/${channel}.csv"
@ -28,17 +31,22 @@ python="python"
if [[ -f "/opt/venv/bin/python" ]]; then if [[ -f "/opt/venv/bin/python" ]]; then
python="/opt/venv/bin/python" python="/opt/venv/bin/python"
fi fi
ytdl="/usr/bin/yt-dlp" ytdl="yt-dlp"
if [[ -f "/usr/bin/yt-dlp" ]]; then
ytdl="/usr/bin/yt-dlp"
fi
if [[ -f "/opt/venv/bin/yt-dlp" ]]; then if [[ -f "/opt/venv/bin/yt-dlp" ]]; then
ytdl="/opt/venv/bin/yt-dlp" ytdl="/opt/venv/bin/yt-dlp"
fi fi
if [[ -f "/data/data/com.termux/files/usr/bin/yt-dlp" ]]; then
ytdl="/data/data/com.termux/files/usr/bin/yt-dlp"
fi
if [[ ! -d "${subfolder}" ]]; then if [[ ! -d "${subfolder}" ]]; then
mkdir -v "${subfolder}" mkdir -v "${subfolder}"
fi fi
if [[ ! -d "${temporary}" ]]; then if [[ ! -d "${temporary}" ]]; then
mkdir -v "${temporary}" mkdir -v "${temporary}"
fi fi
#TODO: mount $temporary on RAM, if possible
cd "${temporary}" || exit cd "${temporary}" || exit
if [[ ! -f "${archive}" ]]; then if [[ ! -f "${archive}" ]]; then
touch "${archive}" touch "${archive}"
@ -74,14 +82,24 @@ for full_url in "${url}/videos" "${url}/shorts" "${url}/streams"; do
--skip-download --download-archive "${archive}" \ --skip-download --download-archive "${archive}" \
--dateafter "${breaktime}" \ --dateafter "${breaktime}" \
--break-on-reject --lazy-playlist --write-info-json \ --break-on-reject --lazy-playlist --write-info-json \
--sleep-requests "${sleeptime}" --sleep-requests "${sleeptime}" \
--parse-metadata "video::(?P<formats>)" \
--parse-metadata "video::(?P<thumbnails>)" \
--parse-metadata "video::(?P<automatic_captions>)" \
--parse-metadata "video::(?P<tags>)" \
--parse-metadata "video::(?P<categories>)"
else else
"${python}" "${ytdl}" "${full_url}" \ "${python}" "${ytdl}" "${full_url}" \
--extractor-args "youtubetab:approximate_date" \ --extractor-args "youtubetab:approximate_date" \
--skip-download --download-archive "${archive}" \ --skip-download --download-archive "${archive}" \
--dateafter "${breaktime}" \ --dateafter "${breaktime}" \
--break-on-reject --lazy-playlist --write-info-json \ --break-on-reject --lazy-playlist --write-info-json \
--sleep-requests "${sleeptime}" --sleep-requests "${sleeptime}" \
--parse-metadata "video::(?P<formats>)" \
--parse-metadata "video::(?P<thumbnails>)" \
--parse-metadata "video::(?P<automatic_captions>)" \
--parse-metadata "video::(?P<tags>)" \
--parse-metadata "video::(?P<categories>)"
fi fi
done done
if [[ ${enablecsv} = 1 ]]; then if [[ ${enablecsv} = 1 ]]; then
@ -102,6 +120,7 @@ total=$(find "${temporary}" -type f -iname "*.info.json" | wc -l)
find "${temporary}" -type f -iname "*.info.json" | while read -r x; do find "${temporary}" -type f -iname "*.info.json" | while read -r x; do
count=$((count + 1)) count=$((count + 1))
( (
jq '.formats="" | .automatic_captions="" | .thumbnails="" | .tags=""' "${x}" >"${temporary}/${x}.tmp" && mv "${temporary}/${x}.tmp" "${x}"
if [[ -f "${x}" && "${channel}" != "subscriptions" && $(jq -rc ".uploader_id" "${x}") != "@${channel}" ]]; then if [[ -f "${x}" && "${channel}" != "subscriptions" && $(jq -rc ".uploader_id" "${x}") != "@${channel}" ]]; then
echo "Video ${x} not uploaded from ${channel}, removing..." && rm "${x}" echo "Video ${x} not uploaded from ${channel}, removing..." && rm "${x}"
fi fi
@ -145,7 +164,7 @@ if [[ ${enabledb} = "1" ]]; then
count=$((count + 1)) count=$((count + 1))
file=$(echo "${line}" | cut -d ',' -f3-) file=$(echo "${line}" | cut -d ',' -f3-)
if [[ -f "${file}" ]]; then if [[ -f "${file}" ]]; then
jq -c "{\"videoId\": .id, \"title\": .title, \"author\": .uploader, \"authorId\": .channel_id, \"lengthSeconds\": .duration, \"published\": ( .timestamp * 1000 ), \"timeAdded\": $(date +%s)$(date +%N | cut -c-3), \"playlistItemId\": \"$(cat /proc/sys/kernel/random/uuid)\", \"type\": \"video\"}" "${temporary}/${file}" >>"${temporary}/${channel}.db" jq -c "{\"videoId\": .id, \"title\": .title, \"author\": .uploader, \"authorId\": .channel_id, \"lengthSeconds\": .duration, \"published\": ( .timestamp * 1000 ), \"timeAdded\": $(date +%s)$(date +%N | cut -c-3), \"playlistItemId\": \"$(cat /proc/sys/kernel/random/uuid)\", \"type\": .media_type}" "${temporary}/${file}" >>"${temporary}/${channel}.db"
echo "," >>"${temporary}/${channel}.db" echo "," >>"${temporary}/${channel}.db"
echo "${count}/${total} ${file}" echo "${count}/${total} ${file}"
fi fi