[tbs] Add new extractor(#10222)
[youtube-dl] / youtube_dl / extractor / tbs.py
1 # coding: utf-8
2 from __future__ import unicode_literals
3
4 import re
5
6 from .turner import TurnerBaseIE
7 from ..utils import (
8     extract_attributes,
9     ExtractorError,
10 )
11
12
13 class TBSIE(TurnerBaseIE):
14     _VALID_URL = r'https?://(?:www\.)?(?P<site>tbs|tntdrama)\.com/videos/(?:[^/]+/)+(?P<id>[^/?#]+)\.html'
15     _TESTS = [{
16         'url': 'http://www.tbs.com/videos/people-of-earth/season-1/extras/2007318/theatrical-trailer.html',
17         'md5': '9e61d680e2285066ade7199e6408b2ee',
18         'info_dict': {
19             'id': '2007318',
20             'ext': 'mp4',
21             'title': 'Theatrical Trailer',
22             'description': 'Catch the latest comedy from TBS, People of Earth, premiering Halloween night--Monday, October 31, at 9/8c.',
23         }
24     }, {
25         'url': 'http://www.tntdrama.com/videos/good-behavior/season-1/extras/1538823/you-better-run.html',
26         'md5': 'ce53c6ead5e9f3280b4ad2031a6fab56',
27         'info_dict': {
28             'id': '1538823',
29             'ext': 'mp4',
30             'title': 'You Better Run',
31             'description': 'Letty Raines must figure out what she\'s running toward while running away from her past. Good Behavior premieres November 15 at 9/8c.',
32         }
33     }]
34
35     def _real_extract(self, url):
36         domain, display_id = re.match(self._VALID_URL, url).groups()
37         site = domain[:3]
38         webpage = self._download_webpage(url, display_id)
39         video_params = extract_attributes(self._search_regex(r'(<[^>]+id="page-video"[^>]*>)', webpage, 'video params'))
40         if video_params.get('isAuthRequired') == 'true':
41             raise ExtractorError(
42                 'This video is only available via cable service provider subscription that'
43                 ' is not currently supported.', expected=True)
44         query = None
45         clip_id = video_params.get('clipid')
46         if clip_id:
47             query = 'id=' + clip_id
48         else:
49             query = 'titleId=' + video_params['titleid']
50         return self._extract_cvp_info(
51             'http://www.%s.com/service/cvpXml?%s' % (domain, query), display_id, {
52                 'default': {
53                     'media_src': 'http://ht.cdn.turner.com/%s/big' % site,
54                 },
55                 'secure': {
56                     'media_src': 'http://apple-secure.cdn.turner.com/%s/big' % site,
57                     'tokenizer_src': 'http://www.%s.com/video/processors/services/token_ipadAdobe.do' % domain,
58                 },
59             })