[clipfish] Use FIFA trailer as testcase (#1842)
[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 from ..utils import ExtractorError
7
8
9 class ClipfishIE(InfoExtractor):
10     IE_NAME = u'clipfish'
11
12     _VALID_URL = r'^https?://(?:www\.)?clipfish\.de/.*?/video/(?P<id>[0-9]+)/'
13     _TEST = {
14         u'url': u'http://www.clipfish.de/special/game-trailer/video/3966754/fifa-14-e3-2013-trailer/',
15         u'file': u'3966754.mp4',
16         u'md5': u'2521cd644e862936cf2e698206e47385',
17         u'info_dict': {
18             u'title': u'FIFA 14 - E3 2013 Trailer',
19             u'duration': 82,
20         }
21     }
22
23     def _real_extract(self, url):
24         mobj = re.match(self._VALID_URL, url)
25         video_id = mobj.group(1)
26
27         info_url = ('http://www.clipfish.de/devxml/videoinfo/%s?ts=%d' %
28                     (video_id, int(time.time())))
29         doc = self._download_xml(
30             info_url, video_id, note=u'Downloading info page')
31         title = doc.find('title').text
32         video_url = doc.find('filename').text
33         if video_url is None:
34             xml_bytes = xml.etree.ElementTree.tostring(doc)
35             raise ExtractorError(u'Cannot find video URL in document %r' %
36                                  xml_bytes)
37         thumbnail = doc.find('imageurl').text
38         duration_str = doc.find('duration').text
39         m = re.match(
40             r'^(?P<hours>[0-9]+):(?P<minutes>[0-9]{2}):(?P<seconds>[0-9]{2}):(?P<ms>[0-9]*)$',
41             duration_str)
42         if m:
43             duration = (
44                 (int(m.group('hours')) * 60 * 60) +
45                 (int(m.group('minutes')) * 60) +
46                 (int(m.group('seconds')))
47             )
48         else:
49             duration = None
50
51         return {
52             'id': video_id,
53             'title': title,
54             'url': video_url,
55             'thumbnail': thumbnail,
56             'duration': duration,
57         }