]> git.bitcoin.ninja Git - youtube-dl/blob - youtube_dl/extractor/byutv.py
Merge remote-tracking branch 'dstftw/download-referer-header' (closes #2628)
[youtube-dl] / youtube_dl / extractor / byutv.py
1 from __future__ import unicode_literals
2
3 import json
4 import re
5
6 from .common import InfoExtractor
7 from ..utils import (
8     ExtractorError,
9 )
10
11
12 class BYUtvIE(InfoExtractor):
13     _VALID_URL = r'^https?://(?:www\.)?byutv.org/watch/[0-9a-f-]+/(?P<video_id>[^/?#]+)'
14     _TEST = {
15         'url': 'http://www.byutv.org/watch/44e80f7b-e3ba-43ba-8c51-b1fd96c94a79/granite-flats-talking',
16         'info_dict': {
17             'id': 'granite-flats-talking',
18             'ext': 'mp4',
19             'description': 'md5:1a7ae3e153359b7cc355ef3963441e5f',
20             'title': 'Talking',
21             'thumbnail': 're:^https?://.*promo.*'
22         },
23         'params': {
24             'skip_download': True,
25         }
26     }
27
28     def _real_extract(self, url):
29         mobj = re.match(self._VALID_URL, url)
30         video_id = mobj.group('video_id')
31
32         webpage = self._download_webpage(url, video_id)
33         episode_code = self._search_regex(
34             r'(?s)episode:(.*?\}),\s*\n', webpage, 'episode information')
35         episode_json = re.sub(
36             r'(\n\s+)([a-zA-Z]+):\s+\'(.*?)\'', r'\1"\2": "\3"', episode_code)
37         ep = json.loads(episode_json)
38
39         if ep['providerType'] == 'Ooyala':
40             return {
41                 '_type': 'url_transparent',
42                 'ie_key': 'Ooyala',
43                 'url': 'ooyala:%s' % ep['providerId'],
44                 'id': video_id,
45                 'title': ep['title'],
46                 'description': ep.get('description'),
47                 'thumbnail': ep.get('imageThumbnail'),
48             }
49         else:
50             raise ExtractorError('Unsupported provider %s' % ep['provider'])