The API does not return the url of the live stream

Hi. I am using Python’s Twitch library to download 60-second video clips from live twitch streams. My goal is to then save these clips as .mp4 files locally. This is my code:

client = TwitchClient(client_id='<client-id>')
streams_now = client.streams.get_live_streams(limit=100)
print(streams_now)
epoch = str(math.ceil(time.time()))

if not os.path.exists(current_dir + '/twitch_videos/'):
    os.mkdir(current_dir + '/twitch_videos/')

counter = 0

for i in range(0, 100):
    username = streams_now[i]['channel']['name']
    id = streams_now[i]['id']
    game = streams_now[i]['game']
    game = game.translate(str.maketrans({':': '-', ' ': '-', "'": '', '!': '', '&': '_', '.': '', '+': '_'}))
    streaming = streamlink.streams('http://twitch.tv/' + username)
    stream = streams_now['Best'].url


    twitch_stream = ffmpeg.input(stream)

    twitch_stream = ffmpeg.filter(twitch_stream,
                                  'fps',
                                  fps=1,
                                  round='up')

    twitch_stream = ffmpeg.output(twitch_stream,
                                  current_dir + '/twitch_videos/' + '%d_' + username + '_' + epoch + '.mp4',
                                  sc_threshold='0',
                                  g='60',
                                  f='segment',
                                  segment_time='600',
                                  segment_format_options='movflags=+faststart',
                                  reset_timestamps='1')

    ffmpeg.run(twitch_stream)

But I wasn’t getting any downloads. This code did work before so I decided to look at what the API was giving me. This is what I saw from a single stream.

[{'id': 41521995070, 'game': 'Minecraft', 'broadcast_platform': 'live', 'community_id': '', 'community_ids': [], 'viewers': 65902, 'video_height': 1080, 'average_fps': 60, 'delay': 0, 'created_at': datetime.datetime(2021, 1, 30, 21, 44, 53), 'is_playlist': False, 'stream_type': 'live', 'preview': {'small': 'https://static-cdn.jtvnw.net/previews-ttv/live_user_xqcow-80x45.jpg', 'medium': 'https://static-cdn.jtvnw.net/previews-ttv/live_user_xqcow-320x180.jpg', 'large': 'https://static-cdn.jtvnw.net/previews-ttv/live_user_xqcow-640x360.jpg', 'template': 'https://static-cdn.jtvnw.net/previews-ttv/live_user_xqcow-{width}x{height}.jpg'}, 'channel': {'mature': False, 'status': 'GOING CRAZY AND DOING IT ALL - BE THERE', 'broadcaster_language': 'en', 'broadcaster_software': '', 'display_name': 'xQcOW', 'game': 'Minecraft', 'language': 'en', 'id': 71092938, 'name': 'xqcow', 'created_at': datetime.datetime(2014, 9, 12, 23, 50, 5, 989719), 'updated_at': datetime.datetime(2021, 1, 31, 1, 51, 35, 180819), 'partner': True, 'logo': 'https://static-cdn.jtvnw.net/jtv_user_pictures/xqcow-profile_image-9298dca608632101-300x300.jpeg', 'video_banner': 'https://static-cdn.jtvnw.net/jtv_user_pictures/a766d7ca-03cb-456e-9a6c-9d109eff47f1-channel_offline_image-1920x1080.png', 'profile_banner': 'https://static-cdn.jtvnw.net/jtv_user_pictures/83e86af1-9a6c-42b1-98e2-3f6238a744b5-profile_banner-480.png', 'profile_banner_background_color': '', 'url': 'https://www.twitch.tv/xqcow', 'views': 267341733, 'followers': 7529138, 'broadcaster_type': '', 'description': 'Overwatch Professional tank player and full time streamer. EZ Clap', 'private_video': False, 'privacy_options_enabled': False}},

The API is not returning a live stream URL (the one with the extension like m8…something). I realize that this is the reason why I was not able to download these 1-minute clips. Is there a reason why the API is doing this?

This is no documented/supported API that provides m3u8 URLS to the Twitch stream.

You cannot do what you describe.

You also refer to

Streamlink access Twitch is a not supported way.

You are trying to do something that the API does not support you doing. And streamlink may constitute a violation of the Developer or Twitch Terms of Services.

Please refer to

For supported API’s.

There are no API’s that provide direct access to the stream or links to clips to download or links to highlights of VOD’s to download.

Edit: I also told you this in your previous post that asked the same thing

We were previously able to take screenshots from streams using ffmpeg. We were using ffmpeg’s command as opposed to the Python library but this was something we were able to do previously. Another test we did involved downloading a 60s video clip from a stream, which was also successful. But now, we are not able to do this.

The API doesn’t support doing what you are trying to do.

There are no supported endpoints that let you connect to the stream to extract audio/video

Okay so I think I am confused with the wording. When you say “does not support you doing”, do you mean that it [doesn’t have/never had] that functionality before or is it a practise Twitch is against?

Both!

There are no endpoints listed at

That have in the past, or currently, provide access to the video feed.

This is identical to what I told you In December

Nothing has changed, you are doing something you are not supposed to do, you found a loop hole via streamlink

And whatever streamlink was doing no longer works.

Becuase

So you guys updated the API and closed that loophole. Am I correct?

I am not Twitch staff

No idea, becuase I don’t use undocumented/unsupported stuff.

Got it. So if we want to grab screenshots or download 60 second clips from Twitch programmatically, how can we do this? I’m not trying to act dumb here. We actually do need this data from Twitch and we need to do it programmatically. So what ways do you suggest?

It’s also worth pointing out that attempting to steal a broadcasters content (as they are the rights owners to the content they broadcast) you may be committing copyright infringement on top of potentially violating the Twitch Developer Agreement and ToS.

We’re not legal experts on this forum, but I suggest you consult with your legal advisors before even attempting to do what you’re trying to do as you are legally liable here.

1 Like

Without permission from the streamer you can’t and shouldn’t

Ideally you’d want to run something locally on the streamers computer.

What you are doing may constititute a violation of the Dev or Twitch TOS’s

Like I already told you in your original thread in December.