[clipsyndicate] Support chic subdomain (fixes #6176)
[youtube-dl] / youtube_dl / extractor / clipsyndicate.py
1 from __future__ import unicode_literals
2
3 import re
4
5 from .common import InfoExtractor
6 from ..utils import (
7     find_xpath_attr,
8     fix_xml_ampersands
9 )
10
11
12 class ClipsyndicateIE(InfoExtractor):
13     _VALID_URL = r'http://(?:chic|www)\.clipsyndicate\.com/video/play(list/\d+)?/(?P<id>\d+)'
14
15     _TESTS = [{
16         'url': 'http://www.clipsyndicate.com/video/play/4629301/brick_briscoe',
17         'md5': '4d7d549451bad625e0ff3d7bd56d776c',
18         'info_dict': {
19             'id': '4629301',
20             'ext': 'mp4',
21             'title': 'Brick Briscoe',
22             'duration': 612,
23             'thumbnail': 're:^https?://.+\.jpg',
24         },
25     }, {
26         'url': 'http://chic.clipsyndicate.com/video/play/5844117/shark_attack',
27         'only_matching': True,
28     }]
29
30     def _real_extract(self, url):
31         mobj = re.match(self._VALID_URL, url)
32         video_id = mobj.group('id')
33         js_player = self._download_webpage(
34             'http://eplayer.clipsyndicate.com/embed/player.js?va_id=%s' % video_id,
35             video_id, 'Downlaoding player')
36         # it includes a required token
37         flvars = self._search_regex(r'flvars: "(.*?)"', js_player, 'flvars')
38
39         pdoc = self._download_xml(
40             'http://eplayer.clipsyndicate.com/osmf/playlist?%s' % flvars,
41             video_id, 'Downloading video info',
42             transform_source=fix_xml_ampersands)
43
44         track_doc = pdoc.find('trackList/track')
45
46         def find_param(name):
47             node = find_xpath_attr(track_doc, './/param', 'name', name)
48             if node is not None:
49                 return node.attrib['value']
50
51         return {
52             'id': video_id,
53             'title': find_param('title'),
54             'url': track_doc.find('location').text,
55             'thumbnail': find_param('thumbnail'),
56             'duration': int(find_param('duration')),
57         }