# The API does not return the url of the live stream

**URL:** <https://discuss.dev.twitch.com/t/the-api-does-not-return-the-url-of-the-live-stream/30235>\
**Category:** API\
**Created:** [January 31, 2021, 2:34am UTC](https://discuss.dev.twitch.com/t/the-api-does-not-return-the-url-of-the-live-stream/30235 "2021-01-31T02:34:11Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![oo92](https://d3ovvz0v2ajtpu.cloudfront.net/user_avatar/discuss.dev.twitch.com/oo92/32/11337_2.png) [@oo92](https://discuss.dev.twitch.com/u/oo92)\
**Post date:** [January 31, 2021, 2:34am UTC](https://discuss.dev.twitch.com/t/the-api-does-not-return-the-url-of-the-live-stream/30235/1 "2021-01-31T02:34:11Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![BarryCarlyon](https://d3ovvz0v2ajtpu.cloudfront.net/user_avatar/discuss.dev.twitch.com/barrycarlyon/32/253_2.png) [@BarryCarlyon](https://discuss.dev.twitch.com/u/BarryCarlyon)\
**Post date:** [January 31, 2021, 2:39am UTC](https://discuss.dev.twitch.com/t/the-api-does-not-return-the-url-of-the-live-stream/30235/2 "2021-01-31T02:39:37Z")

</div>

> [@oo92](#):
>
> 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

> [@oo92](#):
>
> `streamlink.streams`

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

> **[Reference](https://dev.twitch.tv/docs/api/reference/)**
>
> Twitch Developer tools and services to integrate Twitch into your development or create interactive experience on twitch.tv.

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

> [@Is it possible to get the live video using the API?](https://discuss.dev.twitch.com/t/is-it-possible-to-get-the-live-video-using-the-api/29412/9):
>
> The Twitch API doesn’t return/provide the ability to connect to the video stream to get screenshots.

---

<div class="post-metadata">

**Author:** ![oo92](https://d3ovvz0v2ajtpu.cloudfront.net/user_avatar/discuss.dev.twitch.com/oo92/32/11337_2.png) [@oo92](https://discuss.dev.twitch.com/u/oo92)\
**Post date:** [January 31, 2021, 2:56am UTC](https://discuss.dev.twitch.com/t/the-api-does-not-return-the-url-of-the-live-stream/30235/3 "2021-01-31T02:56:10Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![BarryCarlyon](https://d3ovvz0v2ajtpu.cloudfront.net/user_avatar/discuss.dev.twitch.com/barrycarlyon/32/253_2.png) [@BarryCarlyon](https://discuss.dev.twitch.com/u/BarryCarlyon)\
**Post date:** [January 31, 2021, 2:57am UTC](https://discuss.dev.twitch.com/t/the-api-does-not-return-the-url-of-the-live-stream/30235/4 "2021-01-31T02:57:46Z")

</div>

> [@BarryCarlyon](#):
>
> You also refer to
> 
> > [@oo92](#):
> >
> > `streamlink.streams`
> 
> 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.

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

---

<div class="post-metadata">

**Author:** ![oo92](https://d3ovvz0v2ajtpu.cloudfront.net/user_avatar/discuss.dev.twitch.com/oo92/32/11337_2.png) [@oo92](https://discuss.dev.twitch.com/u/oo92)\
**Post date:** [January 31, 2021, 2:59am UTC](https://discuss.dev.twitch.com/t/the-api-does-not-return-the-url-of-the-live-stream/30235/5 "2021-01-31T02:59:13Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![BarryCarlyon](https://d3ovvz0v2ajtpu.cloudfront.net/user_avatar/discuss.dev.twitch.com/barrycarlyon/32/253_2.png) [@BarryCarlyon](https://discuss.dev.twitch.com/u/BarryCarlyon)\
**Post date:** [January 31, 2021, 3:02am UTC](https://discuss.dev.twitch.com/t/the-api-does-not-return-the-url-of-the-live-stream/30235/6 "2021-01-31T03:02:17Z")

</div>

> [@oo92](#):
>
> 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

> **[Reference](https://dev.twitch.tv/docs/api/reference/)**
>
> Twitch Developer tools and services to integrate Twitch into your development or create interactive experience on twitch.tv.

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

This is identical to what I told you In December

> [@Is it possible to get the live video using the API?](https://discuss.dev.twitch.com/t/is-it-possible-to-get-the-live-video-using-the-api/29412/2):
>
> You can get the screenshot from the streams API use the “preview” key For anything else it works better if you integrate “client side” in the actual streaming software. You cannot directly connect to the video feed and take a screenshot. There are not API’s for that.

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

> [@BarryCarlyon](#):
>
> You also refer to
> 
> > [@oo92](#):
> >
> > `streamlink.streams`
> 
> 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.

And whatever streamlink was doing no longer works.

Becuase

> [@Is it possible to get the live video using the API?](https://discuss.dev.twitch.com/t/is-it-possible-to-get-the-live-video-using-the-api/29412/2):
>
> You cannot _directly_ connect to the video feed and take a screenshot. There are no API’s for that.

---

<div class="post-metadata">

**Author:** ![oo92](https://d3ovvz0v2ajtpu.cloudfront.net/user_avatar/discuss.dev.twitch.com/oo92/32/11337_2.png) [@oo92](https://discuss.dev.twitch.com/u/oo92)\
**Post date:** [January 31, 2021, 3:03am UTC](https://discuss.dev.twitch.com/t/the-api-does-not-return-the-url-of-the-live-stream/30235/7 "2021-01-31T03:03:05Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![BarryCarlyon](https://d3ovvz0v2ajtpu.cloudfront.net/user_avatar/discuss.dev.twitch.com/barrycarlyon/32/253_2.png) [@BarryCarlyon](https://discuss.dev.twitch.com/u/BarryCarlyon)\
**Post date:** [January 31, 2021, 3:03am UTC](https://discuss.dev.twitch.com/t/the-api-does-not-return-the-url-of-the-live-stream/30235/8 "2021-01-31T03:03:31Z")

</div>

> [@oo92](#):
>
> So you guys updated

I am not Twitch staff

> [@oo92](#):
>
> So you guys updated the API and closed that loophole. Am I correct?

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

---

<div class="post-metadata">

**Author:** ![oo92](https://d3ovvz0v2ajtpu.cloudfront.net/user_avatar/discuss.dev.twitch.com/oo92/32/11337_2.png) [@oo92](https://discuss.dev.twitch.com/u/oo92)\
**Post date:** [January 31, 2021, 3:06am UTC](https://discuss.dev.twitch.com/t/the-api-does-not-return-the-url-of-the-live-stream/30235/9 "2021-01-31T03:06:17Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![Dist](https://d3ovvz0v2ajtpu.cloudfront.net/user_avatar/discuss.dev.twitch.com/dist/32/7192_2.png) [@Dist](https://discuss.dev.twitch.com/u/Dist)\
**Post date:** [January 31, 2021, 3:06am UTC](https://discuss.dev.twitch.com/t/the-api-does-not-return-the-url-of-the-live-stream/30235/10 "2021-01-31T03:06:58Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![BarryCarlyon](https://d3ovvz0v2ajtpu.cloudfront.net/user_avatar/discuss.dev.twitch.com/barrycarlyon/32/253_2.png) [@BarryCarlyon](https://discuss.dev.twitch.com/u/BarryCarlyon)\
**Post date:** [January 31, 2021, 3:07am UTC](https://discuss.dev.twitch.com/t/the-api-does-not-return-the-url-of-the-live-stream/30235/11 "2021-01-31T03:07:53Z")

</div>

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.

> [@Is it possible to get the live video using the API?](https://discuss.dev.twitch.com/t/is-it-possible-to-get-the-live-video-using-the-api/29412/2):
>
> For anything else it works better if you integrate “client side” in the actual streaming software.
> 
> You cannot _directly_ connect to the video feed and take a screenshot. There are not API’s for that.

---

<div class="post-metadata">

**Author:** ![BarryCarlyon](https://d3ovvz0v2ajtpu.cloudfront.net/user_avatar/discuss.dev.twitch.com/barrycarlyon/32/253_2.png) [@BarryCarlyon](https://discuss.dev.twitch.com/u/BarryCarlyon)\
**Post date:** [January 31, 2021, 9:50pm UTC](https://discuss.dev.twitch.com/t/the-api-does-not-return-the-url-of-the-live-stream/30235/12 "2021-01-31T21:50:31Z")

</div>



---

<div class="post-metadata">

**Author:** ![BarryCarlyon](https://d3ovvz0v2ajtpu.cloudfront.net/user_avatar/discuss.dev.twitch.com/barrycarlyon/32/253_2.png) [@BarryCarlyon](https://discuss.dev.twitch.com/u/BarryCarlyon)\
**Post date:** [January 31, 2021, 9:50pm UTC](https://discuss.dev.twitch.com/t/the-api-does-not-return-the-url-of-the-live-stream/30235/13 "2021-01-31T21:50:35Z")

</div>


