Skip to content

Commit

Permalink
fix: add labels to mkv downloads and make multiple subs work
Browse files Browse the repository at this point in the history
  • Loading branch information
justchokingaround committed Jul 28, 2024
1 parent 5b40688 commit b26cda4
Showing 1 changed file with 25 additions and 15 deletions.
40 changes: 25 additions & 15 deletions lobster.sh
Original file line number Diff line number Diff line change
Expand Up @@ -575,22 +575,32 @@ EOF
fi
exit 0
}
# download_video [url] [title] [download_dir] [thumbnail_file]
# download_video [url] [title] [download_dir] [json_data] [thumbnail_file (only when image_preview is enabled)]
download_video() {
title="$(printf "%s" "$2" | tr -d ':/')"
dir="${3}/${title}"
num_subs="$(echo "$subs_links" | sed 's/:\([^\/]\)/\n\\1/g' | wc -l)"
ffmpeg_subs_links=$(printf "%s" "$subs_links" | sed -E 's/https(\\)?:/-i https:/g; s/:\([^\/]\)/ \\1/g')
# ik this is dumb idc
language=$(printf "%s" "$4" | sed -nE "s@.*\"file\":\"[^\"]*\".*\"label\":\"(.$subs_language)[,\"\ ].*@\1@p")
num_subs="$(printf "%s" "$subs_links" | sed 's/:\([^\/]\)/\n\\1/g' | wc -l)"
ffmpeg_subs_links=$(printf "%s" "$subs_links" | sed 's/:\([^\/]\)/\nh/g; s/\\:/:/g' | while read -r sub_link; do
printf " -i %s" "$sub_link"
done)
sub_ops="$ffmpeg_subs_links -map 0:v -map 0:a"
i=0
while [ "$i" -lt "$num_subs" ]; do
ffmpeg_maps="$ffmpeg_maps -map $((i + 1))"
# FIXME: use filename for language
ffmpeg_meta="$ffmpeg_meta -metadata:s:s:$i language=unknown"
i=$((i + 1))
done
if [ "$num_subs" -eq 0 ]; then
sub_ops=" -i $subs_links -map 0:v -map 0:a -map 1"
ffmpeg_meta="-metadata:s:s:0 language=$language"
else
i=1
for i in $(seq 1 "$num_subs"); do
ffmpeg_maps="$ffmpeg_maps -map $i"
ffmpeg_meta="$ffmpeg_meta -metadata:s:s:$((i - 1)) language=$(printf "%s_%s" "$language" "$i")"
i=$((i + 1))
done
fi
sub_ops="$sub_ops $ffmpeg_maps -c:v copy -c:a copy -c:s srt $ffmpeg_meta"
eval "ffmpeg -loglevel error -stats -i '$1' $sub_ops -c copy '$dir.mkv'"
# shellcheck disable=SC2086
ffmpeg -loglevel error -stats -i "$1" $sub_ops -c copy -threads 6 "$dir.mkv"
}
choose_from_trending_or_recent() {
path=$1
Expand All @@ -615,18 +625,18 @@ EOF
if [ "$download" = "1" ]; then
if [ "$media_type" = "movie" ]; then
if [ "$image_preview" = "true" ]; then
download_video "$video_link" "$title" "$download_dir" "$images_cache_dir/ $title ($media_type) $media_id.jpg" || exit 1
download_video "$video_link" "$title" "$download_dir" "$json_data" "$images_cache_dir/ $title ($media_type) $media_id.jpg" &
send_notification "Finished downloading" "5000" "$images_cache_dir/ $title ($media_type) $media_id.jpg" "$title"
else
download_video "$video_link" "$title" "$download_dir" || exit 1
download_video "$video_link" "$title" "$download_dir" "$json_data" &
send_notification "Finished downloading" "5000" "" "$title"
fi
else
if [ "$image_preview" = "true" ]; then
download_video "$video_link" "$title - $season_title - $episode_title" "$download_dir" "$images_cache_dir/ $title ($media_type) $media_id.jpg" || exit 1
download_video "$video_link" "$title - $season_title - $episode_title" "$download_dir" "$json_data" "$images_cache_dir/ $title ($media_type) $media_id.jpg" &
send_notification "Finished downloading" "5000" "$images_cache_dir/ $title - $season_title - $episode_title ($media_type) $media_id.jpg" "$title - $season_title - $episode_title"
else
download_video "$video_link" "$title - $season_title - $episode_title" "$download_dir" || exit 1
download_video "$video_link" "$title - $season_title - $episode_title" "$download_dir" "$json_data" &
send_notification "Finished downloading" "5000" "" "$title - $season_title - $episode_title"
fi
fi
Expand Down

0 comments on commit b26cda4

Please sign in to comment.