[FEATURE] Add output option for info json file
This commit is contained in:
parent
99925836f3
commit
a74333be88
9 changed files with 76 additions and 2 deletions
|
|
@ -38,6 +38,7 @@ presets:
|
||||||
output_directory: "{music_video_directory}"
|
output_directory: "{music_video_directory}"
|
||||||
file_name: "{music_video_name}.{ext}"
|
file_name: "{music_video_name}.{ext}"
|
||||||
thumbnail_name: "{music_video_name}-thumb.jpg"
|
thumbnail_name: "{music_video_name}-thumb.jpg"
|
||||||
|
info_json_name: "{music_video_name}.{info_json_ext}"
|
||||||
|
|
||||||
# For each video downloaded, add a music video NFO file for it. Populate it
|
# For each video downloaded, add a music video NFO file for it. Populate it
|
||||||
# with tags that Kodi will read and use to display it in the music or music
|
# with tags that Kodi will read and use to display it in the music or music
|
||||||
|
|
|
||||||
|
|
@ -53,6 +53,7 @@ presets:
|
||||||
output_directory: "{youtube_tv_shows_directory}/{tv_show_name_sanitized}"
|
output_directory: "{youtube_tv_shows_directory}/{tv_show_name_sanitized}"
|
||||||
file_name: "{episode_name}.{ext}"
|
file_name: "{episode_name}.{ext}"
|
||||||
thumbnail_name: "{episode_name}-thumb.jpg"
|
thumbnail_name: "{episode_name}-thumb.jpg"
|
||||||
|
info_json_name: "{episode_name}.{info_json_ext}"
|
||||||
maintain_download_archive: True
|
maintain_download_archive: True
|
||||||
|
|
||||||
# For each video downloaded, add an episode NFO file for it. We give it
|
# For each video downloaded, add an episode NFO file for it. We give it
|
||||||
|
|
|
||||||
|
|
@ -44,8 +44,9 @@ presets:
|
||||||
# them on a successive invocation.
|
# them on a successive invocation.
|
||||||
output_options:
|
output_options:
|
||||||
output_directory: "{music_directory}"
|
output_directory: "{music_directory}"
|
||||||
file_name: "{artist_sanitized}/{album_directory_name}/{track_number_padded} - {title_sanitized}.{ext}"
|
file_name: "{album_path}/{track_file_name}.{ext}"
|
||||||
thumbnail_name: "{artist_sanitized}/{album_directory_name}/folder.jpg"
|
thumbnail_name: "{album_path}/folder.{thumbnail_ext}"
|
||||||
|
info_json_name: "{album_path}/{track_file_name}.{info_json_ext}"
|
||||||
maintain_download_archive: True
|
maintain_download_archive: True
|
||||||
|
|
||||||
# For each song downloaded, populate the audio file with music tags.
|
# For each song downloaded, populate the audio file with music tags.
|
||||||
|
|
@ -67,4 +68,6 @@ presets:
|
||||||
# which gets reused above for the audio file name and album art path.
|
# which gets reused above for the audio file name and album art path.
|
||||||
overrides:
|
overrides:
|
||||||
album_directory_name: "[{album_year}] {album_sanitized}"
|
album_directory_name: "[{album_year}] {album_sanitized}"
|
||||||
|
track_file_name: "{track_number_padded} - {title_sanitized}"
|
||||||
|
album_path: "{artist_sanitized}/{album_directory_name}"
|
||||||
music_directory: "/path/to/music"
|
music_directory: "/path/to/music"
|
||||||
|
|
@ -10,6 +10,7 @@ presets:
|
||||||
output_options:
|
output_options:
|
||||||
output_directory: "{music_directory}"
|
output_directory: "{music_directory}"
|
||||||
file_name: "{custom_track_name_sanitized}.{ext}"
|
file_name: "{custom_track_name_sanitized}.{ext}"
|
||||||
|
info_json_name: "{custom_track_name_sanitized}.{info_json_ext}"
|
||||||
|
|
||||||
audio_extract:
|
audio_extract:
|
||||||
codec: "mp3"
|
codec: "mp3"
|
||||||
|
|
|
||||||
|
|
@ -126,6 +126,7 @@ class OutputOptions(StrictDictValidator):
|
||||||
_required_keys = {"output_directory", "file_name"}
|
_required_keys = {"output_directory", "file_name"}
|
||||||
_optional_keys = {
|
_optional_keys = {
|
||||||
"thumbnail_name",
|
"thumbnail_name",
|
||||||
|
"info_json_name",
|
||||||
"subtitles_name",
|
"subtitles_name",
|
||||||
"maintain_download_archive",
|
"maintain_download_archive",
|
||||||
"keep_files_before",
|
"keep_files_before",
|
||||||
|
|
@ -148,6 +149,9 @@ class OutputOptions(StrictDictValidator):
|
||||||
self._thumbnail_name = self._validate_key_if_present(
|
self._thumbnail_name = self._validate_key_if_present(
|
||||||
key="thumbnail_name", validator=StringFormatterValidator
|
key="thumbnail_name", validator=StringFormatterValidator
|
||||||
)
|
)
|
||||||
|
self._info_json_name = self._validate_key_if_present(
|
||||||
|
key="info_json_name", validator=StringFormatterValidator
|
||||||
|
)
|
||||||
|
|
||||||
self._maintain_download_archive = self._validate_key_if_present(
|
self._maintain_download_archive = self._validate_key_if_present(
|
||||||
key="maintain_download_archive", validator=BoolValidator, default=False
|
key="maintain_download_archive", validator=BoolValidator, default=False
|
||||||
|
|
@ -191,6 +195,15 @@ class OutputOptions(StrictDictValidator):
|
||||||
"""
|
"""
|
||||||
return self._thumbnail_name
|
return self._thumbnail_name
|
||||||
|
|
||||||
|
@property
|
||||||
|
def info_json_name(self) -> Optional[StringFormatterValidator]:
|
||||||
|
"""
|
||||||
|
Optional. The file name for the media's info json file. This can include directories such
|
||||||
|
as ``"Season {upload_year}/{title}.{info_json_ext}"``, and will be placed in the output
|
||||||
|
directory.
|
||||||
|
"""
|
||||||
|
return self._info_json_name
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def maintain_download_archive(self) -> bool:
|
def maintain_download_archive(self) -> bool:
|
||||||
"""
|
"""
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,5 @@
|
||||||
|
import copy
|
||||||
|
import json
|
||||||
import os
|
import os
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from typing import Dict
|
from typing import Dict
|
||||||
|
|
@ -59,6 +61,33 @@ class Entry(EntryVariables, BaseEntry):
|
||||||
|
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
def get_download_info_json_name(self) -> str:
|
||||||
|
"""
|
||||||
|
Returns
|
||||||
|
-------
|
||||||
|
The download info json's file name
|
||||||
|
"""
|
||||||
|
return f"{self.uid}.{self.info_json_ext}"
|
||||||
|
|
||||||
|
def get_download_info_json_path(self) -> str:
|
||||||
|
"""
|
||||||
|
Returns
|
||||||
|
-------
|
||||||
|
Entry's downloaded info json file path
|
||||||
|
"""
|
||||||
|
return str(Path(self.working_directory()) / self.get_download_info_json_name())
|
||||||
|
|
||||||
|
def write_info_json(self) -> None:
|
||||||
|
"""
|
||||||
|
Write the entry's _kwargs back into the info.json file as well as its source variables
|
||||||
|
"""
|
||||||
|
kwargs_dict = copy.deepcopy(self._kwargs)
|
||||||
|
kwargs_dict["ytdl-sub-entry-variables"] = self.to_dict()
|
||||||
|
kwargs_json = json.dumps(self._kwargs, ensure_ascii=False, sort_keys=True, indent=2)
|
||||||
|
|
||||||
|
with open(self.get_download_info_json_path(), "w", encoding="utf-8") as file:
|
||||||
|
file.write(kwargs_json)
|
||||||
|
|
||||||
@final
|
@final
|
||||||
def is_downloaded(self) -> bool:
|
def is_downloaded(self) -> bool:
|
||||||
"""
|
"""
|
||||||
|
|
|
||||||
|
|
@ -304,3 +304,13 @@ class EntryVariables(SourceVariables):
|
||||||
The uploaded date formatted as YYYY-MM-DD
|
The uploaded date formatted as YYYY-MM-DD
|
||||||
"""
|
"""
|
||||||
return f"{self.upload_year}-{self.upload_month_padded}-{self.upload_day_padded}"
|
return f"{self.upload_year}-{self.upload_month_padded}-{self.upload_day_padded}"
|
||||||
|
|
||||||
|
@property
|
||||||
|
def info_json_ext(self) -> str:
|
||||||
|
"""
|
||||||
|
Returns
|
||||||
|
-------
|
||||||
|
str
|
||||||
|
The "info.json" extension
|
||||||
|
"""
|
||||||
|
return "info.json"
|
||||||
|
|
|
||||||
|
|
@ -205,6 +205,21 @@ class Subscription:
|
||||||
entry=entry,
|
entry=entry,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
if self.output_options.info_json_name:
|
||||||
|
output_info_json_name = self.overrides.apply_formatter(
|
||||||
|
formatter=self.output_options.info_json_name, entry=entry
|
||||||
|
)
|
||||||
|
|
||||||
|
# if not dry-run, write the info json
|
||||||
|
if not dry_run:
|
||||||
|
entry.write_info_json()
|
||||||
|
|
||||||
|
self._enhanced_download_archive.save_file_to_output_directory(
|
||||||
|
file_name=entry.get_download_thumbnail_name(),
|
||||||
|
output_file_name=output_info_json_name,
|
||||||
|
entry=entry,
|
||||||
|
)
|
||||||
|
|
||||||
@contextlib.contextmanager
|
@contextlib.contextmanager
|
||||||
def _prepare_working_directory(self):
|
def _prepare_working_directory(self):
|
||||||
"""
|
"""
|
||||||
|
|
|
||||||
|
|
@ -77,6 +77,7 @@ def mock_entry_to_dict(
|
||||||
"upload_day_of_year_reversed": 354,
|
"upload_day_of_year_reversed": 354,
|
||||||
"upload_day_of_year_reversed_padded": "354",
|
"upload_day_of_year_reversed_padded": "354",
|
||||||
"thumbnail_ext": thumbnail_ext,
|
"thumbnail_ext": thumbnail_ext,
|
||||||
|
"info_json_ext": "info.json",
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue