~ubuntu-branches/ubuntu/vivid/youtube-dl/vivid

« back to all changes in this revision

Viewing changes to youtube_dl/extractor/twitch.py

  • Committer: Package Import Robot
  • Author(s): Rogério Brito
  • Date: 2015-03-01 02:12:13 UTC
  • mfrom: (44.1.24 sid)
  • Revision ID: package-import@ubuntu.com-20150301021213-8w657cue71kp77sz
Tags: 2015.02.28-1
Imported Upstream version 2015.02.28. Closes: #778765.

Show diffs side-by-side

added added

removed removed

Lines of Context:
34
34
                expected=True)
35
35
 
36
36
    def _download_json(self, url, video_id, note='Downloading JSON metadata'):
37
 
        response = super(TwitchBaseIE, self)._download_json(url, video_id, note)
 
37
        headers = {
 
38
            'Referer': 'http://api.twitch.tv/crossdomain/receiver.html?v=2',
 
39
            'X-Requested-With': 'XMLHttpRequest',
 
40
        }
 
41
        for cookie in self._downloader.cookiejar:
 
42
            if cookie.name == 'api_token':
 
43
                headers['Twitch-Api-Token'] = cookie.value
 
44
        request = compat_urllib_request.Request(url, headers=headers)
 
45
        response = super(TwitchBaseIE, self)._download_json(request, video_id, note)
38
46
        self._handle_error(response)
39
47
        return response
40
48
 
349
357
            % (self._USHER_BASE, channel_id, compat_urllib_parse.urlencode(query).encode('utf-8')),
350
358
            channel_id, 'mp4')
351
359
 
 
360
        # prefer the 'source' stream, the others are limited to 30 fps
 
361
        def _sort_source(f):
 
362
            if f.get('m3u8_media') is not None and f['m3u8_media'].get('NAME') == 'Source':
 
363
                return 1
 
364
            return 0
 
365
        formats = sorted(formats, key=_sort_source)
 
366
 
352
367
        view_count = stream.get('viewers')
353
368
        timestamp = parse_iso8601(stream.get('created_at'))
354
369