]> Raphaƫl G. Git Repositories - youtubedl/blob - youtube_dl/extractor/clipfish.py
Imported Upstream version 2015.11.10
[youtubedl] / youtube_dl / extractor / clipfish.py
1 from __future__ import unicode_literals
2
3 import re
4
5 from .common import InfoExtractor
6 from ..utils import (
7 determine_ext,
8 int_or_none,
9 js_to_json,
10 parse_iso8601,
11 remove_end,
12 )
13
14
15 class ClipfishIE(InfoExtractor):
16 _VALID_URL = r'https?://(?:www\.)?clipfish\.de/(?:[^/]+/)+video/(?P<id>[0-9]+)'
17 _TEST = {
18 'url': 'http://www.clipfish.de/special/game-trailer/video/3966754/fifa-14-e3-2013-trailer/',
19 'md5': '79bc922f3e8a9097b3d68a93780fd475',
20 'info_dict': {
21 'id': '3966754',
22 'ext': 'mp4',
23 'title': 'FIFA 14 - E3 2013 Trailer',
24 'timestamp': 1370938118,
25 'upload_date': '20130611',
26 'duration': 82,
27 }
28 }
29
30 def _real_extract(self, url):
31 video_id = self._match_id(url)
32
33 webpage = self._download_webpage(url, video_id)
34
35 video_info = self._parse_json(
36 js_to_json(self._html_search_regex(
37 '(?s)videoObject\s*=\s*({.+?});', webpage, 'video object')),
38 video_id)
39
40 formats = []
41 for video_url in re.findall(r'var\s+videourl\s*=\s*"([^"]+)"', webpage):
42 ext = determine_ext(video_url)
43 if ext == 'm3u8':
44 formats.append({
45 'url': video_url.replace('de.hls.fra.clipfish.de', 'hls.fra.clipfish.de'),
46 'ext': 'mp4',
47 'format_id': 'hls',
48 })
49 else:
50 formats.append({
51 'url': video_url,
52 'format_id': ext,
53 })
54 self._sort_formats(formats)
55
56 title = remove_end(self._og_search_title(webpage), ' - Video')
57 thumbnail = self._og_search_thumbnail(webpage)
58 duration = int_or_none(video_info.get('length'))
59 timestamp = parse_iso8601(self._html_search_meta('uploadDate', webpage, 'upload date'))
60
61 return {
62 'id': video_id,
63 'title': title,
64 'formats': formats,
65 'thumbnail': thumbnail,
66 'duration': duration,
67 'timestamp': timestamp,
68 }