all tests passing
This commit is contained in:
parent
9294bae75f
commit
c17403e9c3
8 changed files with 15 additions and 33 deletions
|
|
@ -34,8 +34,6 @@ class BaseEntry(ABC):
|
||||||
self._working_directory = working_directory
|
self._working_directory = working_directory
|
||||||
self._kwargs = entry_dict
|
self._kwargs = entry_dict
|
||||||
|
|
||||||
self._additional_variables: Dict[str, str | int] = {}
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def uid(self: "BaseEntry") -> str:
|
def uid(self: "BaseEntry") -> str:
|
||||||
"""
|
"""
|
||||||
|
|
|
||||||
|
|
@ -581,7 +581,6 @@ class VariableDefinitions:
|
||||||
def ytdl_sub_input_url(self) -> Variable:
|
def ytdl_sub_input_url(self) -> Variable:
|
||||||
return Variable("ytdl_sub_input_url")
|
return Variable("ytdl_sub_input_url")
|
||||||
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def download_index(self) -> Variable:
|
def download_index(self) -> Variable:
|
||||||
"""
|
"""
|
||||||
|
|
|
||||||
|
|
@ -11,8 +11,9 @@ from ytdl_sub.config.validators.options import OptionsDictValidator
|
||||||
from ytdl_sub.downloaders.ytdl_options_builder import YTDLOptionsBuilder
|
from ytdl_sub.downloaders.ytdl_options_builder import YTDLOptionsBuilder
|
||||||
from ytdl_sub.entries.entry import Entry
|
from ytdl_sub.entries.entry import Entry
|
||||||
from ytdl_sub.entries.script.variable_definitions import VARIABLES as v
|
from ytdl_sub.entries.script.variable_definitions import VARIABLES as v
|
||||||
from ytdl_sub.utils.chapters import Chapters, ytdl_sub_chapters_from_comments, \
|
from ytdl_sub.utils.chapters import Chapters
|
||||||
ytdl_sub_split_by_chapters_parent_uid
|
from ytdl_sub.utils.chapters import ytdl_sub_chapters_from_comments
|
||||||
|
from ytdl_sub.utils.chapters import ytdl_sub_split_by_chapters_parent_uid
|
||||||
from ytdl_sub.utils.ffmpeg import set_ffmpeg_metadata_chapters
|
from ytdl_sub.utils.ffmpeg import set_ffmpeg_metadata_chapters
|
||||||
from ytdl_sub.utils.file_handler import FileMetadata
|
from ytdl_sub.utils.file_handler import FileMetadata
|
||||||
from ytdl_sub.validators.regex_validator import RegexListValidator
|
from ytdl_sub.validators.regex_validator import RegexListValidator
|
||||||
|
|
@ -195,9 +196,7 @@ class ChaptersOptions(OptionsDictValidator):
|
||||||
def added_variables(
|
def added_variables(
|
||||||
self, resolved_variables: Set[str], unresolved_variables: Set[str]
|
self, resolved_variables: Set[str], unresolved_variables: Set[str]
|
||||||
) -> Dict[PluginOperation, Set[str]]:
|
) -> Dict[PluginOperation, Set[str]]:
|
||||||
return {
|
return {PluginOperation.MODIFY_ENTRY: {"ytdl_sub_chapters_from_comments"}}
|
||||||
PluginOperation.MODIFY_ENTRY: {"ytdl_sub_chapters_from_comments"}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
class ChaptersPlugin(Plugin[ChaptersOptions]):
|
class ChaptersPlugin(Plugin[ChaptersOptions]):
|
||||||
|
|
|
||||||
|
|
@ -12,8 +12,9 @@ from ytdl_sub.config.plugin.plugin_operation import PluginOperation
|
||||||
from ytdl_sub.config.validators.options import OptionsDictValidator
|
from ytdl_sub.config.validators.options import OptionsDictValidator
|
||||||
from ytdl_sub.entries.entry import Entry
|
from ytdl_sub.entries.entry import Entry
|
||||||
from ytdl_sub.entries.script.variable_definitions import VARIABLES as v
|
from ytdl_sub.entries.script.variable_definitions import VARIABLES as v
|
||||||
from ytdl_sub.utils.chapters import Chapters, ytdl_sub_split_by_chapters_parent_uid
|
from ytdl_sub.utils.chapters import Chapters
|
||||||
from ytdl_sub.utils.chapters import Timestamp
|
from ytdl_sub.utils.chapters import Timestamp
|
||||||
|
from ytdl_sub.utils.chapters import ytdl_sub_split_by_chapters_parent_uid
|
||||||
from ytdl_sub.utils.exceptions import ValidationException
|
from ytdl_sub.utils.exceptions import ValidationException
|
||||||
from ytdl_sub.utils.ffmpeg import FFMPEG
|
from ytdl_sub.utils.ffmpeg import FFMPEG
|
||||||
from ytdl_sub.utils.file_handler import FileHandler
|
from ytdl_sub.utils.file_handler import FileHandler
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,8 @@ from typing import List
|
||||||
from typing import Tuple
|
from typing import Tuple
|
||||||
|
|
||||||
from ytdl_sub.entries.entry import Entry
|
from ytdl_sub.entries.entry import Entry
|
||||||
from ytdl_sub.entries.script.variable_definitions import VARIABLES, Variable
|
from ytdl_sub.entries.script.variable_definitions import VARIABLES
|
||||||
|
from ytdl_sub.entries.script.variable_definitions import Variable
|
||||||
from ytdl_sub.entries.script.variable_definitions import VariableDefinitions
|
from ytdl_sub.entries.script.variable_definitions import VariableDefinitions
|
||||||
from ytdl_sub.utils.file_handler import FileMetadata
|
from ytdl_sub.utils.file_handler import FileMetadata
|
||||||
|
|
||||||
|
|
@ -231,8 +232,9 @@ class Chapters:
|
||||||
# If more than 3 timestamps were parsed, return it
|
# If more than 3 timestamps were parsed, return it
|
||||||
if len(timestamps) >= 3:
|
if len(timestamps) >= 3:
|
||||||
return Chapters(timestamps=timestamps, titles=titles)
|
return Chapters(timestamps=timestamps, titles=titles)
|
||||||
|
|
||||||
# Otherwise return empty chapters
|
# Otherwise return empty chapters
|
||||||
return Chapters(timestamps=[], titles=[])
|
return cls.from_empty()
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def from_yt_dlp_chapters(cls, chapters: List[Dict[str, str | float]]):
|
def from_yt_dlp_chapters(cls, chapters: List[Dict[str, str | float]]):
|
||||||
|
|
@ -258,11 +260,11 @@ class Chapters:
|
||||||
Chapters object
|
Chapters object
|
||||||
"""
|
"""
|
||||||
if chapters := (
|
if chapters := (
|
||||||
entry.get(ytdl_sub_chapters_from_comments, list) or entry.get(v.chapters, list)
|
entry.try_get(ytdl_sub_chapters_from_comments, list) or entry.get(v.chapters, list)
|
||||||
):
|
):
|
||||||
return cls.from_yt_dlp_chapters(chapters)
|
return cls.from_yt_dlp_chapters(chapters)
|
||||||
|
|
||||||
return Chapters(timestamps=[], titles=[])
|
return cls.from_empty()
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def from_empty(cls) -> "Chapters":
|
def from_empty(cls) -> "Chapters":
|
||||||
|
|
|
||||||
|
|
@ -69,16 +69,12 @@ def mock_entry_to_dict(
|
||||||
"title_sanitized": "entry {title}",
|
"title_sanitized": "entry {title}",
|
||||||
"ext": ext,
|
"ext": ext,
|
||||||
"description": "",
|
"description": "",
|
||||||
"comments": "",
|
|
||||||
"requested_subtitles": "",
|
|
||||||
"sponsorblock_chapters": "",
|
|
||||||
"creator": "abc123",
|
"creator": "abc123",
|
||||||
"creator_sanitized": "abc123",
|
"creator_sanitized": "abc123",
|
||||||
"channel": "abc123",
|
"channel": "abc123",
|
||||||
"channel_sanitized": "abc123",
|
"channel_sanitized": "abc123",
|
||||||
"channel_id": uid,
|
"channel_id": uid,
|
||||||
"extractor": extractor,
|
"extractor": extractor,
|
||||||
"extractor_key": "test_extractor_key",
|
|
||||||
"uploader": "abc123",
|
"uploader": "abc123",
|
||||||
"uploader_id": "abc123",
|
"uploader_id": "abc123",
|
||||||
"uploader_url": "https://yourname.here",
|
"uploader_url": "https://yourname.here",
|
||||||
|
|
|
||||||
|
|
@ -8,14 +8,9 @@ class TestEntry(object):
|
||||||
def test_entry_to_dict(self, mock_entry, mock_entry_to_dict):
|
def test_entry_to_dict(self, mock_entry, mock_entry_to_dict):
|
||||||
out = mock_entry.to_dict()
|
out = mock_entry.to_dict()
|
||||||
|
|
||||||
# Delete non-legacy variables to reuse old to_dict comparision
|
# HACK: Ensure legacy variables are in new output and equal
|
||||||
del out[v.entry_metadata.variable_name]
|
for key, expected_value in mock_entry_to_dict.items():
|
||||||
del out[v.ytdl_sub_input_url.variable_name]
|
assert out[key] == expected_value, f"{key} does not equal"
|
||||||
del out[v.playlist_metadata.variable_name]
|
|
||||||
del out[v.source_metadata.variable_name]
|
|
||||||
del out[v.sibling_metadata.variable_name]
|
|
||||||
del out[v.playlist_max_upload_date.variable_name]
|
|
||||||
assert out == mock_entry_to_dict
|
|
||||||
|
|
||||||
def test_entry_missing_kwarg(self, mock_entry):
|
def test_entry_missing_kwarg(self, mock_entry):
|
||||||
key = "dne"
|
key = "dne"
|
||||||
|
|
|
||||||
|
|
@ -1,8 +0,0 @@
|
||||||
from ytdl_sub.entries.script.variable_definitions import VARIABLES
|
|
||||||
|
|
||||||
|
|
||||||
class TestEntry(object):
|
|
||||||
def test_entry_to_dict(self, mock_entry, mock_entry_to_dict):
|
|
||||||
output = mock_entry.script.resolve().as_native()
|
|
||||||
del output[VARIABLES.entry_metadata.variable_name]
|
|
||||||
assert output == mock_entry_to_dict
|
|
||||||
Loading…
Reference in a new issue