Compare commits
2 commits
af0e32eb68
...
f38bd73bf8
Author | SHA1 | Date | |
---|---|---|---|
f38bd73bf8 | |||
11d3594121 |
2 changed files with 96 additions and 74 deletions
|
@ -2,35 +2,48 @@
|
||||||
IFS="
|
IFS="
|
||||||
"
|
"
|
||||||
#Set your parameters here
|
#Set your parameters here
|
||||||
folder=/var/www/friendica
|
#Name of the database
|
||||||
storagefolder=storage
|
db=friendica
|
||||||
|
#User of the database
|
||||||
|
user=root
|
||||||
|
#Folder with the storage files to check
|
||||||
|
storagefolder=/var/www/friendica/storage
|
||||||
|
#The folder storage name, with slashes escaped to work through sed
|
||||||
|
folderescaped=${storagefolder////\\/}
|
||||||
|
|
||||||
loop_1() {
|
loop_1() {
|
||||||
t=$(file "${p}")
|
ks=$(echo "${p}" | sed -e "s/${folderescaped}//g" -e "s/\///g")
|
||||||
if [[ "${t}" =~ JPEG ]]; then
|
e=$(sudo -u "${user}" mariadb "${db}" -N -B -q -e "select \`backend-ref\` from photo where \`backend-ref\` = '${ks}'")
|
||||||
nice -n 10 jpegoptim -m 76 "${p}" #&> /dev/null
|
#If the file was not found in the database, but still exists in the filesystem, delete it
|
||||||
elif [[ "${t}" =~ GIF ]]; then
|
if [[ -z "${e}" && -f "${p}" ]]; then
|
||||||
nice -n 10 gifsicle --batch -O3 --lossy=80 --colors=255 "${p}" #&> /dev/null
|
sudo rm -rfv "${p}" #&> /dev/null
|
||||||
#Specific compression for large GIF files
|
else
|
||||||
while [[ $(stat -c%s "${p}" || 0) -ge 512000 ]]; do
|
t=$(file "${p}")
|
||||||
frameamount=$(($(exiftool -b -FrameCount "${p}" || 1) - 1))
|
if [[ "${t}" =~ JPEG ]]; then
|
||||||
nice -n 10 gifsicle "${p}" $(seq -f "#%g" 0 2 "${frameamount}") -O3 --lossy=80 --colors=255 -o "${p}" #&> /dev/null
|
nice -n 10 jpegoptim -m 76 "${p}" #&> /dev/null
|
||||||
done
|
elif [[ "${t}" =~ GIF ]]; then
|
||||||
elif [[ "${t}" =~ PNG ]]; then
|
nice -n 10 gifsicle --batch -O3 --lossy=80 --colors=255 "${p}" #&> /dev/null
|
||||||
nice -n 10 oxipng -o max "${p}" #&> /dev/null
|
#Specific compression for large GIF files
|
||||||
elif [[ "${t}" =~ Web/P ]]; then
|
while [[ $(stat -c%s "${p}" || 0) -ge 512000 ]]; do
|
||||||
#If file is not animated
|
frameamount=$(($(exiftool -b -FrameCount "${p}" || 1) - 1))
|
||||||
if [[ -f "${p}" ]]; then
|
nice -n 10 gifsicle "${p}" $(seq -f "#%g" 0 2 "${frameamount}") -O3 --lossy=80 --colors=255 -o "${p}" #&> /dev/null
|
||||||
if grep -q -a -l -e "ANIM" -e "ANMF" "${p}"; then
|
done
|
||||||
tmppic="/tmp/temp_$(date +%s).webp"
|
elif [[ "${t}" =~ PNG ]]; then
|
||||||
nice -n 10 cwebp -mt -af -quiet "${p}" -o "${tmppic}" #&> /dev/null
|
nice -n 10 oxipng -o max "${p}" #&> /dev/null
|
||||||
if [[ -f "${tmppic}" ]]; then
|
elif [[ "${t}" =~ Web/P ]]; then
|
||||||
size_new=$(stat -c%s "${tmppic}" 2>/dev/null || echo 0)
|
#If file is not animated
|
||||||
size_original=$(stat -c%s "${p}" 2>/dev/null || echo 0)
|
if [[ -f "${p}" ]]; then
|
||||||
if [[ "${size_original}" -gt "${size_new}" ]]; then
|
if grep -q -a -l -e "ANIM" -e "ANMF" "${p}"; then
|
||||||
mv "${tmppic}" "${p}" #&> /dev/null
|
tmppic="/tmp/temp_$(date +%s).webp"
|
||||||
else
|
nice -n 10 cwebp -mt -af -quiet "${p}" -o "${tmppic}" #&> /dev/null
|
||||||
rm "${tmppic}" #&> /dev/null
|
if [[ -f "${tmppic}" ]]; then
|
||||||
|
size_new=$(stat -c%s "${tmppic}" 2>/dev/null || echo 0)
|
||||||
|
size_original=$(stat -c%s "${p}" 2>/dev/null || echo 0)
|
||||||
|
if [[ "${size_original}" -gt "${size_new}" ]]; then
|
||||||
|
mv -v "${tmppic}" "${p}" #&> /dev/null
|
||||||
|
else
|
||||||
|
rm -v "${tmppic}" #&> /dev/null
|
||||||
|
fi
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
@ -38,7 +51,11 @@ loop_1() {
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
find "${folder}/${storagefolder}" -depth -mindepth 2 -type f -size +50k -atime -8 -not -iname "index.html" | (
|
#Generate an index to make searches faster
|
||||||
|
echo "Generating photo index..." #&> /dev/null
|
||||||
|
sudo mariadb "${db}" -e "alter table photo add index if not exists backend_index (\`backend-ref\`)" #&> /dev/null
|
||||||
|
echo "Generating list of files..." #&> /dev/null
|
||||||
|
find "${storagefolder}" -depth -mindepth 2 -type f -size +50k -mtime -8 -not -iname "index.html" | (
|
||||||
while read -r p; do
|
while read -r p; do
|
||||||
loop_1 "${p}" &
|
loop_1 "${p}" &
|
||||||
until [[ $(jobs -r -p | wc -l) -lt $(($(getconf _NPROCESSORS_ONLN) / 2)) ]]; do
|
until [[ $(jobs -r -p | wc -l) -lt $(($(getconf _NPROCESSORS_ONLN) / 2)) ]]; do
|
||||||
|
@ -47,3 +64,5 @@ find "${folder}/${storagefolder}" -depth -mindepth 2 -type f -size +50k -atime -
|
||||||
done
|
done
|
||||||
)
|
)
|
||||||
wait
|
wait
|
||||||
|
#Drop the index in the end to save storage
|
||||||
|
sudo mariadb "${db}" -e "alter table photo drop index backend_index" #&> /dev/null
|
||||||
|
|
|
@ -63,52 +63,55 @@ 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
|
||||||
for full_url in "${url}/videos" "${url}/shorts" "${url}/streams"; do
|
#for section_url in "${url}/videos" "${url}/shorts" "${url}/streams"; do
|
||||||
echo "${full_url}"
|
#Via https://github.com/yt-dlp/yt-dlp/issues/13573#issuecomment-3020152141
|
||||||
if [[ -f "${cookies}" || "${channel}" = "subscriptions" ]]; then
|
full_url=$(yt-dlp -I0 --print "playlist:https://www.youtube.com/playlist?list=UU%(channel_id.2:)s" "${url}")
|
||||||
#If available, you can use the cookies from your browser directly. Substitute
|
#full_url=$(curl "${url}" | tr -d "\n\r" | xmlstarlet fo -R -n -H 2>/dev/null | xmlstarlet sel -t -v "/html" -n | grep "/channel/UC" | sed -e "s/var .* = //g" -e "s/\};/\}/g" -e "s/channel\/UC/playlist\?list=UU/g" | jq -r ".metadata .channelMetadataRenderer .channelUrl")
|
||||||
# --cookies "${cookies}"
|
echo "${url} = ${full_url}"
|
||||||
#for the below, substituting for your browser of choice:
|
if [[ -f "${cookies}" || "${channel}" = "subscriptions" ]]; then
|
||||||
# --cookies-from-browser "firefox"
|
#If available, you can use the cookies from your browser directly. Substitute
|
||||||
#In case this still fails, you can resort to a PO Token. Follow the instructions at
|
# --cookies "${cookies}"
|
||||||
# https://github.com/yt-dlp/yt-dlp/wiki/PO-Token-Guide
|
#for the below, substituting for your browser of choice:
|
||||||
#and add a new variable with the contents of the PO Token in the form
|
# --cookies-from-browser "firefox"
|
||||||
# potoken="INSERTYOURPOTOKENHERE"
|
#In case this still fails, you can resort to a PO Token. Follow the instructions at
|
||||||
#then substitute the "--extractor-args" line below with
|
# https://github.com/yt-dlp/yt-dlp/wiki/PO-Token-Guide
|
||||||
# --extractor-args "youtubetab:approximate_date,youtube:player-client=default,mweb;po_token=mweb.gvs+${potoken}" \
|
#and add a new variable with the contents of the PO Token in the form
|
||||||
#including the backslash so the multiline command keeps working.
|
# potoken="INSERTYOURPOTOKENHERE"
|
||||||
"${python}" "${ytdl}" "${full_url}" \
|
#then substitute the "--extractor-args" line below with
|
||||||
--cookies "${cookies}" \
|
# --extractor-args "youtubetab:approximate_date,youtube:player-client=default,mweb;po_token=mweb.gvs+${potoken}" \
|
||||||
--extractor-args "youtubetab:approximate_date" \
|
#including the backslash so the multiline command keeps working.
|
||||||
--skip-download --download-archive "${archive}" \
|
"${python}" "${ytdl}" "${full_url}" \
|
||||||
--dateafter "${breaktime}" \
|
--cookies "${cookies}" \
|
||||||
--break-on-reject --lazy-playlist --write-info-json \
|
--skip-download --download-archive "${archive}" \
|
||||||
--sleep-requests "${sleeptime}" \
|
--dateafter "${breaktime}" \
|
||||||
--parse-metadata "video::(?P<formats>)" \
|
--extractor-args "youtubetab:approximate_date,youtubetab:skip=webpage" \
|
||||||
--parse-metadata "video::(?P<thumbnails>)" \
|
--break-on-reject --lazy-playlist --write-info-json \
|
||||||
--parse-metadata "video::(?P<subtitles>)" \
|
--sleep-requests "${sleeptime}" \
|
||||||
--parse-metadata "video::(?P<automatic_captions>)" \
|
--parse-metadata "video::(?P<formats>)" \
|
||||||
--parse-metadata "video::(?P<chapters>)" \
|
--parse-metadata "video::(?P<thumbnails>)" \
|
||||||
--parse-metadata "video::(?P<heatmap>)" \
|
--parse-metadata "video::(?P<subtitles>)" \
|
||||||
--parse-metadata "video::(?P<tags>)" \
|
--parse-metadata "video::(?P<automatic_captions>)" \
|
||||||
--parse-metadata "video::(?P<categories>)"
|
--parse-metadata "video::(?P<chapters>)" \
|
||||||
else
|
--parse-metadata "video::(?P<heatmap>)" \
|
||||||
"${python}" "${ytdl}" "${full_url}" \
|
--parse-metadata "video::(?P<tags>)" \
|
||||||
--extractor-args "youtubetab:approximate_date" \
|
--parse-metadata "video::(?P<categories>)"
|
||||||
--skip-download --download-archive "${archive}" \
|
else
|
||||||
--dateafter "${breaktime}" \
|
"${python}" "${ytdl}" "${full_url}" \
|
||||||
--break-on-reject --lazy-playlist --write-info-json \
|
--skip-download --download-archive "${archive}" \
|
||||||
--sleep-requests "${sleeptime}" \
|
--dateafter "${breaktime}" \
|
||||||
--parse-metadata "video::(?P<formats>)" \
|
--extractor-args "youtubetab:approximate_date,youtubetab:skip=webpage" \
|
||||||
--parse-metadata "video::(?P<thumbnails>)" \
|
--break-on-reject --lazy-playlist --write-info-json \
|
||||||
--parse-metadata "video::(?P<subtitles>)" \
|
--sleep-requests "${sleeptime}" \
|
||||||
--parse-metadata "video::(?P<automatic_captions>)" \
|
--parse-metadata "video::(?P<formats>)" \
|
||||||
--parse-metadata "video::(?P<chapters>)" \
|
--parse-metadata "video::(?P<thumbnails>)" \
|
||||||
--parse-metadata "video::(?P<heatmap>)" \
|
--parse-metadata "video::(?P<subtitles>)" \
|
||||||
--parse-metadata "video::(?P<tags>)" \
|
--parse-metadata "video::(?P<automatic_captions>)" \
|
||||||
--parse-metadata "video::(?P<categories>)"
|
--parse-metadata "video::(?P<chapters>)" \
|
||||||
fi
|
--parse-metadata "video::(?P<heatmap>)" \
|
||||||
done
|
--parse-metadata "video::(?P<tags>)" \
|
||||||
|
--parse-metadata "video::(?P<categories>)"
|
||||||
|
fi
|
||||||
|
#done
|
||||||
if [[ ${enablecsv} = 1 ]]; then
|
if [[ ${enablecsv} = 1 ]]; then
|
||||||
if [[ -f "${tmpcsv}" ]]; then
|
if [[ -f "${tmpcsv}" ]]; then
|
||||||
rm -rf "${tmpcsv}"
|
rm -rf "${tmpcsv}"
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue