]> Raphaƫl G. Git Repositories - youtubedl/blob - youtube_dl/extractor/clipsyndicate.py
d4fc869732a8ae15e60f0963ef3418abac1a9201
[youtubedl] / youtube_dl / extractor / clipsyndicate.py
1 import re
2 import xml.etree.ElementTree
3
4 from .common import InfoExtractor
5 from ..utils import (
6 find_xpath_attr,
7 )
8
9
10 class ClipsyndicateIE(InfoExtractor):
11 _VALID_URL = r'http://www\.clipsyndicate\.com/video/play(list/\d+)?/(?P<id>\d+)'
12
13 _TEST = {
14 u'url': u'http://www.clipsyndicate.com/video/play/4629301/brick_briscoe',
15 u'md5': u'4d7d549451bad625e0ff3d7bd56d776c',
16 u'info_dict': {
17 u'id': u'4629301',
18 u'ext': u'mp4',
19 u'title': u'Brick Briscoe',
20 u'duration': 612,
21 },
22 }
23
24 def _real_extract(self, url):
25 mobj = re.match(self._VALID_URL, url)
26 video_id = mobj.group('id')
27 js_player = self._download_webpage(
28 'http://eplayer.clipsyndicate.com/embed/player.js?va_id=%s' % video_id,
29 video_id, u'Downlaoding player')
30 # it includes a required token
31 flvars = self._search_regex(r'flvars: "(.*?)"', js_player, u'flvars')
32
33 playlist_page = self._download_webpage(
34 'http://eplayer.clipsyndicate.com/osmf/playlist?%s' % flvars,
35 video_id, u'Downloading video info')
36 # Fix broken xml
37 playlist_page = re.sub('&', '&amp;', playlist_page)
38 pdoc = xml.etree.ElementTree.fromstring(playlist_page.encode('utf-8'))
39
40 track_doc = pdoc.find('trackList/track')
41 def find_param(name):
42 node = find_xpath_attr(track_doc, './/param', 'name', name)
43 if node is not None:
44 return node.attrib['value']
45
46 return {
47 'id': video_id,
48 'title': find_param('title'),
49 'url': track_doc.find('location').text,
50 'thumbnail': find_param('thumbnail'),
51 'duration': int(find_param('duration')),
52 }