[byutv] Rely on _match_id and _parse_json
[youtube-dl] / youtube_dl / extractor / byutv.py
1 from __future__ import unicode_literals
2
3 import re
4
5 from .common import InfoExtractor
6 from ..utils import ExtractorError
7
8
9 class BYUtvIE(InfoExtractor):
10     _VALID_URL = r'^https?://(?:www\.)?byutv.org/watch/[0-9a-f-]+/(?P<id>[^/?#]+)'
11     _TEST = {
12         'url': 'http://www.byutv.org/watch/6587b9a3-89d2-42a6-a7f7-fd2f81840a7d/studio-c-season-5-episode-5',
13         'md5': '05850eb8c749e2ee05ad5a1c34668493',
14         'info_dict': {
15             'id': 'studio-c-season-5-episode-5',
16             'ext': 'mp4',
17             'description': 'md5:e07269172baff037f8e8bf9956bc9747',
18             'title': 'Season 5 Episode 5',
19             'thumbnail': 're:^https?://.*\.jpg$',
20             'duration': 1486.486,
21         },
22         'params': {
23             'skip_download': True,
24         },
25         'add_ie': ['Ooyala'],
26     }
27
28     def _real_extract(self, url):
29         video_id = self._match_id(url)
30
31         webpage = self._download_webpage(url, video_id)
32         episode_code = self._search_regex(
33             r'(?s)episode:(.*?\}),\s*\n', webpage, 'episode information')
34
35         ep = self._parse_json(
36             episode_code, video_id, transform_source=lambda s:
37             re.sub(r'(\n\s+)([a-zA-Z]+):\s+\'(.*?)\'', r'\1"\2": "\3"', s))
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'])