all tests passing

This commit is contained in:
Jesse Bannon 2023-12-13 12:28:48 -08:00
parent 9294bae75f
commit c17403e9c3
8 changed files with 15 additions and 33 deletions

View file

@ -34,8 +34,6 @@ class BaseEntry(ABC):
self._working_directory = working_directory
self._kwargs = entry_dict
self._additional_variables: Dict[str, str | int] = {}
@property
def uid(self: "BaseEntry") -> str:
"""

View file

@ -581,7 +581,6 @@ class VariableDefinitions:
def ytdl_sub_input_url(self) -> Variable:
return Variable("ytdl_sub_input_url")
@property
def download_index(self) -> Variable:
"""

View file

@ -11,8 +11,9 @@ from ytdl_sub.config.validators.options import OptionsDictValidator
from ytdl_sub.downloaders.ytdl_options_builder import YTDLOptionsBuilder
from ytdl_sub.entries.entry import Entry
from ytdl_sub.entries.script.variable_definitions import VARIABLES as v
from ytdl_sub.utils.chapters import Chapters, ytdl_sub_chapters_from_comments, \
ytdl_sub_split_by_chapters_parent_uid
from ytdl_sub.utils.chapters import Chapters
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.file_handler import FileMetadata
from ytdl_sub.validators.regex_validator import RegexListValidator
@ -195,9 +196,7 @@ class ChaptersOptions(OptionsDictValidator):
def added_variables(
self, resolved_variables: Set[str], unresolved_variables: Set[str]
) -> Dict[PluginOperation, Set[str]]:
return {
PluginOperation.MODIFY_ENTRY: {"ytdl_sub_chapters_from_comments"}
}
return {PluginOperation.MODIFY_ENTRY: {"ytdl_sub_chapters_from_comments"}}
class ChaptersPlugin(Plugin[ChaptersOptions]):

View file

@ -12,8 +12,9 @@ from ytdl_sub.config.plugin.plugin_operation import PluginOperation
from ytdl_sub.config.validators.options import OptionsDictValidator
from ytdl_sub.entries.entry import Entry
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 ytdl_sub_split_by_chapters_parent_uid
from ytdl_sub.utils.exceptions import ValidationException
from ytdl_sub.utils.ffmpeg import FFMPEG
from ytdl_sub.utils.file_handler import FileHandler

View file

@ -4,7 +4,8 @@ from typing import List
from typing import Tuple
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.utils.file_handler import FileMetadata
@ -231,8 +232,9 @@ class Chapters:
# If more than 3 timestamps were parsed, return it
if len(timestamps) >= 3:
return Chapters(timestamps=timestamps, titles=titles)
# Otherwise return empty chapters
return Chapters(timestamps=[], titles=[])
return cls.from_empty()
@classmethod
def from_yt_dlp_chapters(cls, chapters: List[Dict[str, str | float]]):
@ -258,11 +260,11 @@ class Chapters:
Chapters object
"""
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 Chapters(timestamps=[], titles=[])
return cls.from_empty()
@classmethod
def from_empty(cls) -> "Chapters":

View file

@ -69,16 +69,12 @@ def mock_entry_to_dict(
"title_sanitized": "entry title",
"ext": ext,
"description": "",
"comments": "",
"requested_subtitles": "",
"sponsorblock_chapters": "",
"creator": "abc123",
"creator_sanitized": "abc123",
"channel": "abc123",
"channel_sanitized": "abc123",
"channel_id": uid,
"extractor": extractor,
"extractor_key": "test_extractor_key",
"uploader": "abc123",
"uploader_id": "abc123",
"uploader_url": "https://yourname.here",

View file

@ -8,14 +8,9 @@ class TestEntry(object):
def test_entry_to_dict(self, mock_entry, mock_entry_to_dict):
out = mock_entry.to_dict()
# Delete non-legacy variables to reuse old to_dict comparision
del out[v.entry_metadata.variable_name]
del out[v.ytdl_sub_input_url.variable_name]
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
# HACK: Ensure legacy variables are in new output and equal
for key, expected_value in mock_entry_to_dict.items():
assert out[key] == expected_value, f"{key} does not equal"
def test_entry_missing_kwarg(self, mock_entry):
key = "dne"

View file

@ -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