Compare commits

..

3 Commits

Author SHA1 Message Date
5ca03f6a75 feat: don't compress the video under 10 mb if the video is already under target size 2026-02-23 23:37:37 +05:30
coolnsx
993b828617 Added another dependency 2026-02-20 20:06:33 +05:30
coolnsx
2344bd7dfb s/ / /g 2026-02-20 19:56:52 +05:30
4 changed files with 29 additions and 6 deletions

View File

@@ -49,5 +49,5 @@ player_droid() {
}
player_linux() {
setsid -f mpv "$1" --force-media-title="$2" $@
setsid -f mpv "$1" --force-media-title="$2" $3
}

View File

@@ -76,7 +76,7 @@ printf "%s\n" "$url" | while read -r id title; do
subs_flag=
[ -n "$subtitle" ] && subs_flag="--sub-file=$subtitle"
# shellcheck disable=SC2086
player_$os "$provider_video" "$title" --referrer="https://$domain" $subs_flag
player_$os "$provider_video" "$title" "--referrer=https://$domain $subs_flag"
break
;;
cast)

View File

@@ -13,7 +13,25 @@ notify_droid() {
notify_linux() {
info "$1"
notify-send -e "$1" -h "string:x-canonical-private-synchronous:${0##*/}"
notify-send -e -i "$3" -h "string:x-canonical-private-synchronous:${0##*/}" -t "${2:-5000}" "$1" "$4"
}
compress() {
duration=$(ffprobe -hide_banner -i "$1" 2>&1 | sed -nE 's|.*Duration: ([^,]*).*|\1|p')
i=20
while :; do
ffmpeg -loglevel error -i "$1" -c:v libx264 -c:a copy -crf "$i" "$process_file" -y -progress - | while read -r line; do
complete=$(printf "%s\n" "$line" | sed -nE 's|out_time=(.*)|\1|p')
size=$(du -m "$process_file" | cut -f1)
[ -n "$complete" ] && notify_$os "Compressing File under $target_size_mb MB Using Quality Preset : $i.." "700" "ffmpeg" "$complete / $duration ($size MB)"
[ "$size" -gt "$target_size_mb" ] && killall -s KILL ffmpeg && break
done
[ "$(du -m "$process_file" | cut -f1)" -lt "$target_size_mb" ] && break
: $((i += 1))
done
notify_$os "File Successfully compressed with Quality Preset : $i" "1000" "ffmpeg"
[ -f "$process_file" ] && filepath=$process_file
}
send_matrix_msg() {
@@ -54,6 +72,8 @@ send_matrix_msg() {
#main
link="$1"
yt_dlp_logs="${TMPDIR:-/tmp}/${0##*/}-logs"
process_file="${TMPDIR:-/tmp}/processed.mp4"
target_size_mb=10
case $(uname -o) in
*ndroid*)
@@ -74,7 +94,7 @@ info "Downloading Video.."
truncate -s0 "$yt_dlp_logs" # truncate file if exists, creates if doesn't exists
yt-dlp --no-skip-unavailable-fragments --fragment-retries infinite -N 16 -t mp4 "$link" -o "$download_dir/%(title)s.%(ext)s" | tee "$yt_dlp_logs"
yt-dlp -S "filesize:10M" -t mp4 "$link" -o "$download_dir/%(title)s.%(ext)s" | tee "$yt_dlp_logs"
filepath=$(sed -nE "s|.*($download_dir.*\.mp4).*|\1|p" "$yt_dlp_logs" | head -1)
@@ -84,6 +104,9 @@ filepath=$(sed -nE "s|.*($download_dir.*\.mp4).*|\1|p" "$yt_dlp_logs" | head -1)
# load matrix creds
matrix_creds
# compresses the video file under 10 MB
[ "$(du -m "$filepath" | cut -f1)" -gt "$target_size_mb" ] && compress "$filepath"
send_matrix_msg "$filepath"
# unload matrix creds
@@ -91,5 +114,5 @@ matrix_creds "unload"
notify_$os "Video Sent to Matrix"
rm -f "$filepath"
rm -f "$filepath" "$process_file" "$yt_dlp_logs"
exit 0

View File

@@ -65,7 +65,7 @@ get_cookies() {
# the user has firefox installed
if [ ! -f "$HOME/.config/google-chrome/Default/Cookies" ]; then
cp "$(find "$HOME/.mozilla" -type f -iname 'cookies.sqlite' | head -1)" "$logdir/cookies.sqlite"
sqlite3 "$logdir/cookies.sqlite" "SELECT name, value FROM moz_cookies WHERE host='.youtube.com' and name NOT like 'ST-%' and name NOT like 'VISITOR%' and name NOT like 'PREF%';" | tr '|\n' '=;' >"$cookie"
sqlite3 "$logdir/cookies.sqlite" "SELECT name, value FROM moz_cookies WHERE host='.youtube.com' and name NOT like 'ST-%' and name NOT like 'VISITOR%' and name NOT like 'PREF%' and name NOT like '%Secure-%';" | tr '|\n' '=;' >"$cookie"
rm "$logdir/cookies.sqlite"
return 0
fi