simplify yt-dlp download structure

This commit is contained in:
Yan Lin 2026-02-01 10:26:25 +01:00
parent 6a5e778871
commit 2ce9fb3a9b

View file

@ -36,7 +36,6 @@ in
cfg.package
deno # Required for YouTube downloads due to JS challenges
ffmpeg
jq # For JSON parsing in cleanup functions
python312Packages.bgutil-ytdlp-pot-provider # PO token provider for YouTube
];
@ -116,107 +115,6 @@ in
return 1
}
# Generate Jellyfin-compatible NFO files from yt-dlp metadata (movie format)
_generate_jellyfin_nfo() {
local filepath="$1"
[[ -z "$filepath" ]] && return 1
local dir=$(dirname "$filepath")
local basename=$(basename "$filepath")
local name_noext="''${basename%.*}"
local json_file="$dir/$name_noext.info.json"
[[ ! -f "$json_file" ]] && return 1
local title=$(jq -r '.title // "Unknown"' "$json_file")
local description=$(jq -r '.description // ""' "$json_file" | head -c 2000)
local upload_date=$(jq -r '.upload_date // ""' "$json_file")
local uploader=$(jq -r '.uploader // "Unknown"' "$json_file")
local year=""
local premiered=""
if [[ ''${#upload_date} -eq 8 ]]; then
year="''${upload_date:0:4}"
premiered="''${upload_date:0:4}-''${upload_date:4:2}-''${upload_date:6:2}"
fi
description=$(echo "$description" | sed 's/&/\&amp;/g; s/</\&lt;/g; s/>/\&gt;/g')
title=$(echo "$title" | sed 's/&/\&amp;/g; s/</\&lt;/g; s/>/\&gt;/g')
uploader=$(echo "$uploader" | sed 's/&/\&amp;/g; s/</\&lt;/g; s/>/\&gt;/g')
local nfo_file="$dir/$name_noext.nfo"
cat > "$nfo_file" << MOVIENFO
<?xml version="1.0" encoding="UTF-8"?>
<movie>
<title>$title</title>
<year>$year</year>
<premiered>$premiered</premiered>
<plot>$description</plot>
<studio>$uploader</studio>
</movie>
MOVIENFO
local thumb_file=""
for ext in jpg webp png; do
if [[ -f "$dir/$name_noext.$ext" ]]; then
thumb_file="$dir/$name_noext.$ext"
break
fi
done
if [[ -n "$thumb_file" ]]; then
local thumb_ext="''${thumb_file##*.}"
mv "$thumb_file" "$dir/$name_noext-thumb.$thumb_ext" 2>/dev/null
fi
}
# Generate Audiobookshelf-compatible metadata from yt-dlp metadata
_generate_audiobookshelf_metadata() {
local filepath="$1"
[[ -z "$filepath" ]] && return 1
local dir=$(dirname "$filepath")
local basename=$(basename "$filepath")
local name_noext="''${basename%.*}"
local json_file="$dir/$name_noext.info.json"
[[ ! -f "$json_file" ]] && return 1
local title=$(jq -r '.title // "Unknown"' "$json_file")
local uploader=$(jq -r '.uploader // "Unknown"' "$json_file")
local description=$(jq -r '.description // ""' "$json_file" | head -c 2000)
local upload_date=$(jq -r '.upload_date // ""' "$json_file")
local year=""
if [[ ''${#upload_date} -eq 8 ]]; then
year="''${upload_date:0:4}"
fi
local metadata_file="$dir/metadata.abs"
cat > "$metadata_file" << ABSMETA
#metadata-version=v1.0.0
title=$title
authors=$uploader
publishedYear=$year
description=$description
ABSMETA
local thumb_file=""
local thumb_ext=""
for ext in jpg webp png; do
if [[ -f "$dir/$name_noext.$ext" ]]; then
thumb_file="$dir/$name_noext.$ext"
thumb_ext="$ext"
break
fi
done
if [[ -n "$thumb_file" ]]; then
mv "$thumb_file" "$dir/cover.$thumb_ext" 2>/dev/null
fi
}
# Unified video download function
dlv() {
@ -373,9 +271,9 @@ ABSMETA
# Build output template based on download type
local output_template
if [[ "$audio_only" == true ]]; then
output_template="$DOWNLOAD_DIR/$platform_name-audio/%(uploader|Unknown)s/%(title)s/%(title)s.%(ext)s"
output_template="$DOWNLOAD_DIR/$platform_name-audio/%(uploader|Unknown)s/%(title)s.%(ext)s"
else
output_template="$DOWNLOAD_DIR/$platform_name/%(title)s (%(upload_date>%Y|0000)s)/%(title)s (%(upload_date>%Y|0000)s).%(ext)s"
output_template="$DOWNLOAD_DIR/$platform_name/%(uploader|Unknown)s/%(title)s.%(ext)s"
fi
local archive_file="$DOWNLOAD_DIR/.archive.txt"
@ -408,31 +306,6 @@ ABSMETA
# Execute download with retry
if _retry_download "$cmd"; then
# Generate metadata files based on download type
if [[ "$audio_only" == true ]]; then
local series_base="$DOWNLOAD_DIR/$platform_name-Audio"
find "$series_base" -name "*.info.json" 2>/dev/null | while read -r json_file; do
local base="''${json_file%.info.json}"
local metadata_file="$(dirname "$base")/metadata.abs"
if [[ ! -f "$metadata_file" ]]; then
for ext in m4a mp3 wav flac opus ogg; do
[[ -f "$base.$ext" ]] && _generate_audiobookshelf_metadata "$base.$ext" && break
done
fi
done
else
local series_base="$DOWNLOAD_DIR/$platform_name"
find "$series_base" -name "*.info.json" 2>/dev/null | while read -r json_file; do
local base="''${json_file%.info.json}"
local nfo_file="$base.nfo"
if [[ ! -f "$nfo_file" ]]; then
for ext in mp4 mkv webm m4a mp3 wav flac; do
[[ -f "$base.$ext" ]] && _generate_jellyfin_nfo "$base.$ext" && break
done
fi
done
fi
# Build success message
local success_msg="$platform_name download completed"