Merge remote-tracking branch 'rbrito/swap-dimensions'
[youtube-dl] / youtube_dl / extractor / clipfish.py
1 import re
2 import time
3 import xml.etree.ElementTree
4
5 from .common import InfoExtractor
6
7
8 class ClipfishIE(InfoExtractor):
9     IE_NAME = u'clipfish'
10
11     _VALID_URL = r'^https?://(?:www\.)?clipfish\.de/.*?/video/(?P<id>[0-9]+)/'
12     _TEST = {
13         u'url': u'http://www.clipfish.de/special/supertalent/video/4028320/supertalent-2013-ivana-opacak-singt-nobodys-perfect/',
14         u'file': u'4028320.f4v',
15         u'md5': u'5e38bda8c329fbfb42be0386a3f5a382',
16         u'info_dict': {
17             u'title': u'Supertalent 2013: Ivana Opacak singt Nobody\'s Perfect',
18             u'duration': 399,
19         }
20     }
21
22     def _real_extract(self, url):
23         mobj = re.match(self._VALID_URL, url)
24         video_id = mobj.group(1)
25
26         info_url = ('http://www.clipfish.de/devxml/videoinfo/%s?ts=%d' %
27                     (video_id, int(time.time())))
28         info_xml = self._download_webpage(
29             info_url, video_id, note=u'Downloading info page')
30         doc = xml.etree.ElementTree.fromstring(info_xml)
31         title = doc.find('title').text
32         video_url = doc.find('filename').text
33         thumbnail = doc.find('imageurl').text
34         duration_str = doc.find('duration').text
35         m = re.match(
36             r'^(?P<hours>[0-9]+):(?P<minutes>[0-9]{2}):(?P<seconds>[0-9]{2}):(?P<ms>[0-9]*)$',
37             duration_str)
38         if m:
39             duration = (
40                 (int(m.group('hours')) * 60 * 60) +
41                 (int(m.group('minutes')) * 60) +
42                 (int(m.group('seconds')))
43             )
44         else:
45             duration = None
46
47         return {
48             'id': video_id,
49             'title': title,
50             'url': video_url,
51             'thumbnail': thumbnail,
52             'duration': duration,
53         }