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
|
|
|
|
import m3u8
|
2021-04-25 13:25:01 +00:00
|
|
|
from twitchdl import twitch
|
2022-08-20 09:16:47 +00:00
|
|
|
from twitchdl.commands.download import _parse_playlists, get_clip_authenticated_url
|
2022-08-27 13:26:54 +00:00
|
|
|
from twitchdl.models import Game, VideosPage
|
2021-04-25 13:25:01 +00:00
|
|
|
|
|
|
|
TEST_CHANNEL = "bananasaurus_rex"
|
|
|
|
|
|
|
|
|
|
|
|
def test_get_videos():
|
2022-08-27 13:26:54 +00:00
|
|
|
page = twitch.get_channel_videos(TEST_CHANNEL, 3, "time")
|
|
|
|
assert isinstance(page, VideosPage)
|
|
|
|
assert len(page.videos) > 0
|
2021-04-25 13:25:01 +00:00
|
|
|
|
2022-08-27 13:26:54 +00:00
|
|
|
video_id = page.videos[0].id
|
2021-04-25 13:25:01 +00:00
|
|
|
video = twitch.get_video(video_id)
|
2022-08-27 13:26:54 +00:00
|
|
|
assert video and video.id == video_id
|
2021-04-25 13:25:01 +00:00
|
|
|
|
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
|
|
|
|
|
|
|
|
playlists = twitch.get_playlists(video_id, access_token)
|
|
|
|
assert playlists.startswith("#EXTM3U")
|
|
|
|
|
2022-08-27 13:26:54 +00:00
|
|
|
_, _, url = next(_parse_playlists(playlists))
|
2022-08-19 07:35:00 +00:00
|
|
|
playlist = httpx.get(url).text
|
|
|
|
assert playlist.startswith("#EXTM3U")
|
|
|
|
|
|
|
|
playlist = m3u8.loads(playlist)
|
|
|
|
vod_path = playlist.segments[0].uri
|
|
|
|
assert vod_path == "0.ts"
|
|
|
|
|
2021-04-25 13:25:01 +00:00
|
|
|
|
|
|
|
def test_get_clips():
|
2022-08-27 09:58:19 +00:00
|
|
|
page = twitch.get_channel_clips(TEST_CHANNEL, "all_time", 3)
|
|
|
|
assert len(page.clips) > 0
|
|
|
|
|
|
|
|
slug = page.clips[0].slug
|
2022-08-20 09:16:47 +00:00
|
|
|
clip = twitch.get_clip(slug)
|
2022-08-27 09:58:19 +00:00
|
|
|
assert clip.slug == slug
|
|
|
|
|
|
|
|
assert get_clip_authenticated_url(slug, "source").startswith("https")
|
|
|
|
|
|
|
|
|
|
|
|
def test_get_game():
|
2022-08-27 10:44:23 +00:00
|
|
|
game = twitch.find_game("The Witness")
|
|
|
|
assert isinstance(game, Game)
|
|
|
|
assert game.id == "17324"
|
|
|
|
assert game.name == "The Witness"
|
|
|
|
assert game.description
|
|
|
|
|
|
|
|
game = twitch.find_game("Does Not Exist Hopefully")
|
|
|
|
assert game is None
|