multiple values
This commit is contained in:
parent
1abd94508f
commit
5100ed6ba2
4 changed files with 39 additions and 4 deletions
|
|
@ -32,6 +32,8 @@ class YoutubeVideoVariables(EntryVariables):
|
|||
Returns
|
||||
-------
|
||||
The track title of a music video if it is available, otherwise it falls back to the title.
|
||||
NOTE: Even if a video has music metadata, this variable does not always get pulled via
|
||||
yt-dlp. Use with caution.
|
||||
"""
|
||||
# Try to get the track, fall back on title
|
||||
if self.kwargs_contains("track"):
|
||||
|
|
@ -54,6 +56,8 @@ class YoutubeVideoVariables(EntryVariables):
|
|||
Returns
|
||||
-------
|
||||
The artist of a music video if it is available, otherwise it falls back to the channel.
|
||||
NOTE: Even if a video has music metadata, this variable does not always get pulled via
|
||||
yt-dlp. Use with caution.
|
||||
"""
|
||||
if self.kwargs_contains("artist"):
|
||||
return self.kwargs("artist")
|
||||
|
|
|
|||
|
|
@ -2,7 +2,9 @@ import hashlib
|
|||
import os.path
|
||||
from pathlib import Path
|
||||
from typing import Dict
|
||||
from typing import List
|
||||
from typing import Optional
|
||||
from typing import Union
|
||||
|
||||
|
||||
class ExpectedDownload:
|
||||
|
|
@ -10,10 +12,11 @@ class ExpectedDownload:
|
|||
To test ytdl-sub downloads work, we compare each downloaded file's md5 hash to an
|
||||
expected md5 hash defined in this class.
|
||||
|
||||
If the hash value is None, only assert the file exists
|
||||
If the hash value is None, only assert the file exists. If the hash value is a list,
|
||||
try all the hashes (used in case the GitHub env produces different deterministic value).
|
||||
"""
|
||||
|
||||
def __init__(self, expected_md5_file_hashes: Dict[Path, Optional[str]]):
|
||||
def __init__(self, expected_md5_file_hashes: Dict[Path, Optional[Union[str, List[str]]]]):
|
||||
self.expected_md5_file_hashes = expected_md5_file_hashes
|
||||
|
||||
@property
|
||||
|
|
@ -48,7 +51,10 @@ class ExpectedDownload:
|
|||
with open(full_path, "rb") as file:
|
||||
md5_hash = hashlib.md5(file.read()).hexdigest()
|
||||
|
||||
assert md5_hash == expected_md5_hash, (
|
||||
if isinstance(expected_md5_hash, str):
|
||||
expected_md5_hash = [expected_md5_hash]
|
||||
|
||||
assert md5_hash in expected_md5_hash, (
|
||||
f"MD5 hash for {str(relative_path)} does not match: "
|
||||
f"{md5_hash} != {expected_md5_hash}"
|
||||
)
|
||||
|
|
|
|||
|
|
@ -66,7 +66,10 @@ def expected_playlist_download():
|
|||
return ExpectedDownload(
|
||||
expected_md5_file_hashes={
|
||||
Path("JMC - Jesse's Minecraft Server.jpg"): "348e3007fc590d0b1e2f6682501b0b5f",
|
||||
Path("JMC - Jesse's Minecraft Server.mkv"): "6053c47a8690519b0a33c13fa4b01ac0",
|
||||
Path("JMC - Jesse's Minecraft Server.mkv"): [
|
||||
"6053c47a8690519b0a33c13fa4b01ac0",
|
||||
"6053c47a8690519b0a33c13fa4b01ac0",
|
||||
],
|
||||
Path("JMC - Jesse's Minecraft Server.nfo"): "10df5dcdb65ab18ecf21b3503c77e48b",
|
||||
}
|
||||
)
|
||||
|
|
|
|||
22
tests/unit/utils/test_chapters.py
Normal file
22
tests/unit/utils/test_chapters.py
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
import pytest
|
||||
|
||||
from ytdl_sub.utils.chapters import Timestamp
|
||||
|
||||
|
||||
class TestTimestamp:
|
||||
@pytest.mark.parametrize(
|
||||
"timestamp_str, timestamp_int",
|
||||
[
|
||||
("0:00", 0),
|
||||
("0:24", 24),
|
||||
("1:11", 71),
|
||||
("01:11", 71),
|
||||
("00:22", 22),
|
||||
("1:01:01", 3600 + 60 + 1),
|
||||
("01:01:01", 3600 + 60 + 1),
|
||||
("00:00:00", 0),
|
||||
],
|
||||
)
|
||||
def test_timestamp_from_str(self, timestamp_str, timestamp_int):
|
||||
ts = Timestamp.from_str(timestamp_str=timestamp_str)
|
||||
assert ts.timestamp_sec == timestamp_int
|
||||
Loading…
Reference in a new issue