def test_get_clips_raises_attribute_exception_for_invalid_clip_ids(): responses.add(responses.GET, '{}clips'.format(BASE_HELIX_URL), body=json.dumps(example_get_clips_response), status=200, content_type='application/json') client = TwitchHelix('client id') kwargs = {'clip_ids': ['12345'] * 101} with pytest.raises(TwitchAttributeException): client.get_clips(**kwargs) assert len(responses.calls) == 0
def test_get_clips_raises_attribute_exception_if_no_param_is_set(): responses.add(responses.GET, '{}clips'.format(BASE_HELIX_URL), body=json.dumps(example_get_clips_response), status=200, content_type='application/json') client = TwitchHelix('client id') with pytest.raises(TwitchAttributeException) as e: client.get_clips() assert ('At least one of the following parameters must be provided ' '[broadcaster_id, clip_ids, game_id]') in str(e) assert len(responses.calls) == 0
def test_get_clips_passes_correct_params_when_broadcaster_or_game_is_set(param, value): responses.add( responses.GET, "{}clips".format(BASE_HELIX_URL), body=json.dumps(example_get_clips_cursor_response), status=200, content_type="application/json", ) client = TwitchHelix("client id") kwargs = { param: value, "after": "eyJiIjpudWxsLCJhIjp7Ik9mZnNldCI6MjB9fQ==", "before": "eyJiIjp7Ik9mZnNldCI6MH0sImEiOnsiT2Zmc2V0Ijo0MH19==", "page_size": 100, } clips = client.get_clips(**kwargs) clip = clips.next() assert len(responses.calls) == 1 assert isinstance(clips, APICursor) assert isinstance(clip, Clip) url = responses.calls[0].request.url assert url.startswith("https://api.twitch.tv/helix/clips?") assert "{}=23161357".format(param) in url assert "after=eyJiIjpudWxsLCJhIjp7Ik9mZnNldCI6MjB9fQ%3D%3D" in url assert "before=eyJiIjp7Ik9mZnNldCI6MH0sImEiOnsiT2Zmc2V0Ijo0MH19%3D%3D" in url assert "first=100" in url
def test_get_clips_next_returns_clip_object(param, value): responses.add( responses.GET, "{}clips".format(BASE_HELIX_URL), body=json.dumps(example_get_clips_cursor_response), status=200, content_type="application/json", ) client = TwitchHelix("client id") kwargs = {param: value} clips = client.get_clips(**kwargs) clip = clips.next() assert len(responses.calls) == 1 assert isinstance(clips, APICursor) assert clips._cursor == example_get_clips_cursor_response["pagination"]["cursor"] assert isinstance(clip, Clip) assert clip.id == example_get_clips_cursor_response["data"][0]["id"] assert ( clip.broadcaster_id == example_get_clips_cursor_response["data"][0]["broadcaster_id"] ) assert clip.created_at == datetime(2017, 11, 30, 22, 34, 17)
def test_get_clips_passes_correct_params_when_clip_ids_are_set(): responses.add(responses.GET, '{}clips'.format(BASE_HELIX_URL), body=json.dumps(example_get_clips_response), status=200, content_type='application/json') client = TwitchHelix('client id') clips = client.get_clips(clip_ids=['AwkwardHelplessSalamanderSwiftRage']) assert len(responses.calls) == 1 assert isinstance(clips, list) clip = clips[0] assert isinstance(clip, Clip) assert responses.calls[0].request.url == ( 'https://api.twitch.tv/helix/clips?id=AwkwardHelplessSalamanderSwiftRage' )
def test_get_clips_returns_list_of_clip_objects_when_clip_ids_are_set(): responses.add(responses.GET, '{}clips'.format(BASE_HELIX_URL), body=json.dumps(example_get_clips_response), status=200, content_type='application/json') client = TwitchHelix('client id') clips = client.get_clips(clip_ids=['AwkwardHelplessSalamanderSwiftRage']) assert len(responses.calls) == 1 assert isinstance(clips, list) clip = clips[0] assert isinstance(clip, Clip) assert clip.id == example_get_clips_response['data'][0]['id'] assert clip.broadcaster_id == example_get_clips_response['data'][0]['broadcaster_id'] assert clip.created_at == datetime(2017, 11, 30, 22, 34, 18)
def clips(): client = TwitchHelix() clip = client.get_clips(clip_ids=['AwkwardHelplessSalamanderSwiftRage']) print(clip)
'outtmpl': 'download/clips/%(title)s.%(ext)s'.strip('[?<>:\"\\/|*]'), 'quiet': True, 'simulate': False } with open('twitch_clientID.txt') as f: twitch_clientID = f.readline().rstrip() client = TwitchHelix(client_id=twitch_clientID) yesterday_date = ( datetime.now() - timedelta(days=clips_from_days_ago)).strftime('%Y-%m-%dT00:00:00Z') clip_array = [] if download_top_game_clips: clip_iterator = client.get_clips(game_id=game_ID, started_at=yesterday_date) for clip in islice(clip_iterator, 0, number_of_clips_to_download): print('---------------------------------------') print('Twitch Channel: ' + clip.broadcaster_name + ' (' + clip.broadcaster_id + ')') print('Clip Title: \t' + clip.title + ' (' + clip.id + ')') print('Clip Chimp: \t' + clip.creator_name) print('Clip URL: \t' + clip.url) ydl_opts = { 'outtmpl': 'download/clips/' + clip.id + '.%(ext)s'.strip('[?<>:\"\\/|*]'), 'quiet': True, 'simulate':
import imageio imageio.plugins.ffmpeg.download() from moviepy.editor import VideoFileClip, concatenate_videoclips import os #Unique identifier for any streamer's channel. 191002666 = twitch.tv/cawlink channelid = '191002666' #Twitch API Credentials, create a clipr_secrets.json file in the same directory, or input manually with open('clipr_secrets.json', 'r') as f: clipr_secrets = json.load(f) CLIENT_ID = clipr_secrets['client_id'] token = clipr_secrets['client_token'] helix = TwitchHelix(client_id=CLIENT_ID, oauth_token=token) clips = helix.get_clips(channelid) #Get all clips from the current month monthly_clips = [] month = datetime.now().month year = datetime.now().year #Download them locally... directory = 'clips/' + str(month) + str(year) i = 1 for clip in range(len(clips)): if clips[clip]['created_at'].month == month and clips[clip][ 'created_at'].year == year: monthly_clips.append(clips[clip]) clip_links = [] for clip in monthly_clips: