mirror of
https://github.com/ihabunek/twitch-dl
synced 2024-08-30 18:32:25 +00:00
Simplify and test get_game_ids
This commit is contained in:
parent
5aa323e3e5
commit
f815934e15
@ -3,9 +3,12 @@ These tests depend on the channel having some videos and clips published.
|
||||
"""
|
||||
|
||||
import httpx
|
||||
import pytest
|
||||
|
||||
from twitchdl import twitch
|
||||
from twitchdl.commands.download import get_clip_authenticated_url
|
||||
from twitchdl.commands.videos import get_game_ids
|
||||
from twitchdl.exceptions import ConsoleError
|
||||
from twitchdl.playlists import enumerate_vods, load_m3u8, parse_playlists
|
||||
|
||||
TEST_CHANNEL = "bananasaurus_rex"
|
||||
@ -53,3 +56,15 @@ def test_get_clips():
|
||||
assert clip["slug"] == slug
|
||||
|
||||
assert get_clip_authenticated_url(slug, "source")
|
||||
|
||||
|
||||
def test_get_games():
|
||||
assert get_game_ids([]) == []
|
||||
assert get_game_ids(["Bioshock"]) == ["15866"]
|
||||
assert get_game_ids(["Bioshock", "Portal"]) == ["15866", "6187"]
|
||||
|
||||
|
||||
def test_get_games_not_found():
|
||||
with pytest.raises(ConsoleError) as ex:
|
||||
get_game_ids(["the game which does not exist"])
|
||||
assert str(ex.value) == "Game 'the game which does not exist' not found"
|
||||
|
@ -20,7 +20,7 @@ def videos(
|
||||
sort: twitch.VideosSort,
|
||||
type: twitch.VideosType,
|
||||
):
|
||||
game_ids = _get_game_ids(games)
|
||||
game_ids = get_game_ids(games)
|
||||
|
||||
# Set different defaults for limit for compact display
|
||||
limit = limit or (40 if compact else 10)
|
||||
@ -67,16 +67,13 @@ def videos(
|
||||
)
|
||||
|
||||
|
||||
def _get_game_ids(names: List[str]) -> List[str]:
|
||||
if not names:
|
||||
return []
|
||||
def get_game_ids(names: List[str]) -> List[str]:
|
||||
return [get_game_id(name) for name in names]
|
||||
|
||||
game_ids = []
|
||||
for name in names:
|
||||
print_log(f"Looking up game '{name}'...")
|
||||
game_id = twitch.get_game_id(name)
|
||||
if not game_id:
|
||||
raise ConsoleError(f"Game '{name}' not found")
|
||||
game_ids.append(int(game_id))
|
||||
|
||||
return game_ids
|
||||
def get_game_id(name: str) -> str:
|
||||
print_log(f"Looking up game '{name}'...")
|
||||
game_id = twitch.get_game_id(name)
|
||||
if not game_id:
|
||||
raise ConsoleError(f"Game '{name}' not found")
|
||||
return game_id
|
||||
|
@ -351,6 +351,7 @@ def get_channel_videos(
|
||||
after: Optional[str] = None,
|
||||
):
|
||||
game_ids = game_ids or []
|
||||
game_ids_str = f"[{','.join(game_ids)}]"
|
||||
|
||||
query = f"""
|
||||
{{
|
||||
@ -361,7 +362,7 @@ def get_channel_videos(
|
||||
sort: {sort.upper()},
|
||||
after: "{after or ''}",
|
||||
options: {{
|
||||
gameIDs: {game_ids}
|
||||
gameIDs: {game_ids_str}
|
||||
}}
|
||||
) {{
|
||||
totalCount
|
||||
|
Loading…
Reference in New Issue
Block a user