multiple values

This commit is contained in:
jbannon 2022-06-26 22:07:11 +00:00
parent 1abd94508f
commit 5100ed6ba2
4 changed files with 39 additions and 4 deletions

View file

@ -32,6 +32,8 @@ class YoutubeVideoVariables(EntryVariables):
Returns Returns
------- -------
The track title of a music video if it is available, otherwise it falls back to the title. 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 # Try to get the track, fall back on title
if self.kwargs_contains("track"): if self.kwargs_contains("track"):
@ -54,6 +56,8 @@ class YoutubeVideoVariables(EntryVariables):
Returns Returns
------- -------
The artist of a music video if it is available, otherwise it falls back to the channel. 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"): if self.kwargs_contains("artist"):
return self.kwargs("artist") return self.kwargs("artist")

View file

@ -2,7 +2,9 @@ import hashlib
import os.path import os.path
from pathlib import Path from pathlib import Path
from typing import Dict from typing import Dict
from typing import List
from typing import Optional from typing import Optional
from typing import Union
class ExpectedDownload: class ExpectedDownload:
@ -10,10 +12,11 @@ class ExpectedDownload:
To test ytdl-sub downloads work, we compare each downloaded file's md5 hash to an To test ytdl-sub downloads work, we compare each downloaded file's md5 hash to an
expected md5 hash defined in this class. 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 self.expected_md5_file_hashes = expected_md5_file_hashes
@property @property
@ -48,7 +51,10 @@ class ExpectedDownload:
with open(full_path, "rb") as file: with open(full_path, "rb") as file:
md5_hash = hashlib.md5(file.read()).hexdigest() 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 for {str(relative_path)} does not match: "
f"{md5_hash} != {expected_md5_hash}" f"{md5_hash} != {expected_md5_hash}"
) )

View file

@ -66,7 +66,10 @@ def expected_playlist_download():
return ExpectedDownload( return ExpectedDownload(
expected_md5_file_hashes={ expected_md5_file_hashes={
Path("JMC - Jesse's Minecraft Server.jpg"): "348e3007fc590d0b1e2f6682501b0b5f", 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", Path("JMC - Jesse's Minecraft Server.nfo"): "10df5dcdb65ab18ecf21b3503c77e48b",
} }
) )

View 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