2021-04-25 13:25:01 +00:00
|
|
|
"""
|
|
|
|
These tests depend on the channel having some videos and clips published.
|
|
|
|
"""
|
|
|
|
|
2022-08-19 07:35:00 +00:00
|
|
|
import httpx
|
2024-04-24 12:31:50 +00:00
|
|
|
import pytest
|
2024-04-10 06:04:21 +00:00
|
|
|
|
2021-04-25 13:25:01 +00:00
|
|
|
from twitchdl import twitch
|
2024-04-10 06:04:21 +00:00
|
|
|
from twitchdl.commands.download import get_clip_authenticated_url
|
2024-04-24 12:31:50 +00:00
|
|
|
from twitchdl.commands.videos import get_game_ids
|
|
|
|
from twitchdl.exceptions import ConsoleError
|
2024-04-10 06:04:21 +00:00
|
|
|
from twitchdl.playlists import enumerate_vods, load_m3u8, parse_playlists
|
2021-04-25 13:25:01 +00:00
|
|
|
|
|
|
|
TEST_CHANNEL = "bananasaurus_rex"
|
|
|
|
|
|
|
|
|
|
|
|
def test_get_videos():
|
|
|
|
videos = twitch.get_channel_videos(TEST_CHANNEL, 3, "time")
|
|
|
|
assert videos["pageInfo"]
|
|
|
|
assert len(videos["edges"]) > 0
|
|
|
|
|
|
|
|
video_id = videos["edges"][0]["node"]["id"]
|
|
|
|
video = twitch.get_video(video_id)
|
2024-04-10 06:04:21 +00:00
|
|
|
assert video is not None
|
2021-04-25 13:25:01 +00:00
|
|
|
assert video["id"] == video_id
|
|
|
|
|
2022-08-19 07:35:00 +00:00
|
|
|
access_token = twitch.get_access_token(video_id)
|
|
|
|
assert "signature" in access_token
|
|
|
|
assert "value" in access_token
|
|
|
|
|
2024-04-10 06:04:21 +00:00
|
|
|
playlists_txt = twitch.get_playlists(video_id, access_token)
|
|
|
|
assert playlists_txt.startswith("#EXTM3U")
|
|
|
|
|
|
|
|
playlists = parse_playlists(playlists_txt)
|
|
|
|
playlist_url = playlists[0].url
|
2022-08-19 07:35:00 +00:00
|
|
|
|
2024-04-10 06:04:21 +00:00
|
|
|
playlist_txt = httpx.get(playlist_url).text
|
|
|
|
assert playlist_txt.startswith("#EXTM3U")
|
2022-08-19 07:35:00 +00:00
|
|
|
|
2024-04-10 06:04:21 +00:00
|
|
|
playlist_m3u8 = load_m3u8(playlist_txt)
|
|
|
|
vods = enumerate_vods(playlist_m3u8)
|
|
|
|
assert vods[0].path == "0.ts"
|
2022-08-19 07:35:00 +00:00
|
|
|
|
2021-04-25 13:25:01 +00:00
|
|
|
|
|
|
|
def test_get_clips():
|
|
|
|
"""
|
|
|
|
This test depends on the channel having some videos published.
|
|
|
|
"""
|
|
|
|
clips = twitch.get_channel_clips(TEST_CHANNEL, "all_time", 3)
|
|
|
|
assert clips["pageInfo"]
|
|
|
|
assert len(clips["edges"]) > 0
|
|
|
|
|
2022-08-20 09:16:47 +00:00
|
|
|
slug = clips["edges"][0]["node"]["slug"]
|
|
|
|
clip = twitch.get_clip(slug)
|
2024-04-10 06:04:21 +00:00
|
|
|
assert clip is not None
|
2022-08-20 09:16:47 +00:00
|
|
|
assert clip["slug"] == slug
|
|
|
|
|
|
|
|
assert get_clip_authenticated_url(slug, "source")
|
2024-04-24 12:31:50 +00:00
|
|
|
|
|
|
|
|
|
|
|
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"
|