]> Raphaƫl G. Git Repositories - youtubedl/blob - youtube_dl/extractor/byutv.py
debian/control: Mark compliance with policy 4.1.1. No further changes needed.
[youtubedl] / 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/(?!event/)(?P<id>[0-9a-f-]+)(?:/(?P<display_id>[^/?#&]+))?'
11 _TESTS = [{
12 'url': 'http://www.byutv.org/watch/6587b9a3-89d2-42a6-a7f7-fd2f81840a7d/studio-c-season-5-episode-5',
13 'info_dict': {
14 'id': '6587b9a3-89d2-42a6-a7f7-fd2f81840a7d',
15 'display_id': 'studio-c-season-5-episode-5',
16 'ext': 'mp4',
17 'title': 'Season 5 Episode 5',
18 'description': 'md5:e07269172baff037f8e8bf9956bc9747',
19 'thumbnail': r're:^https?://.*\.jpg$',
20 'duration': 1486.486,
21 },
22 'params': {
23 'skip_download': True,
24 },
25 'add_ie': ['Ooyala'],
26 }, {
27 'url': 'http://www.byutv.org/watch/6587b9a3-89d2-42a6-a7f7-fd2f81840a7d',
28 'only_matching': True,
29 }]
30
31 def _real_extract(self, url):
32 mobj = re.match(self._VALID_URL, url)
33 video_id = mobj.group('id')
34 display_id = mobj.group('display_id') or video_id
35
36 webpage = self._download_webpage(url, display_id)
37 episode_code = self._search_regex(
38 r'(?s)episode:(.*?\}),\s*\n', webpage, 'episode information')
39
40 ep = self._parse_json(
41 episode_code, display_id, transform_source=lambda s:
42 re.sub(r'(\n\s+)([a-zA-Z]+):\s+\'(.*?)\'', r'\1"\2": "\3"', s))
43
44 if ep['providerType'] != 'Ooyala':
45 raise ExtractorError('Unsupported provider %s' % ep['provider'])
46
47 return {
48 '_type': 'url_transparent',
49 'ie_key': 'Ooyala',
50 'url': 'ooyala:%s' % ep['providerId'],
51 'id': video_id,
52 'display_id': display_id,
53 'title': ep['title'],
54 'description': ep.get('description'),
55 'thumbnail': ep.get('imageThumbnail'),
56 }
57
58
59 class BYUtvEventIE(InfoExtractor):
60 _VALID_URL = r'https?://(?:www\.)?byutv\.org/watch/event/(?P<id>[0-9a-f-]+)'
61 _TEST = {
62 'url': 'http://www.byutv.org/watch/event/29941b9b-8bf6-48d2-aebf-7a87add9e34b',
63 'info_dict': {
64 'id': '29941b9b-8bf6-48d2-aebf-7a87add9e34b',
65 'ext': 'mp4',
66 'title': 'Toledo vs. BYU (9/30/16)',
67 },
68 'params': {
69 'skip_download': True,
70 },
71 'add_ie': ['Ooyala'],
72 }
73
74 def _real_extract(self, url):
75 video_id = self._match_id(url)
76
77 webpage = self._download_webpage(url, video_id)
78
79 ooyala_id = self._search_regex(
80 r'providerId\s*:\s*(["\'])(?P<id>(?:(?!\1).)+)\1',
81 webpage, 'ooyala id', group='id')
82
83 title = self._search_regex(
84 r'class=["\']description["\'][^>]*>\s*<h1>([^<]+)</h1>', webpage,
85 'title').strip()
86
87 return {
88 '_type': 'url_transparent',
89 'ie_key': 'Ooyala',
90 'url': 'ooyala:%s' % ooyala_id,
91 'id': video_id,
92 'title': title,
93 }