]> Raphaƫl G. Git Repositories - youtubedl/blob - youtube_dl/extractor/fktv.py
Imported Upstream version 2014.06.07
[youtubedl] / youtube_dl / extractor / fktv.py
1 import re
2 import random
3 import json
4
5 from .common import InfoExtractor
6 from ..utils import (
7 determine_ext,
8 get_element_by_id,
9 clean_html,
10 )
11
12
13 class FKTVIE(InfoExtractor):
14 IE_NAME = u'fernsehkritik.tv'
15 _VALID_URL = r'(?:http://)?(?:www\.)?fernsehkritik\.tv/folge-(?P<ep>[0-9]+)(?:/.*)?'
16
17 _TEST = {
18 u'url': u'http://fernsehkritik.tv/folge-1',
19 u'file': u'00011.flv',
20 u'info_dict': {
21 u'title': u'Folge 1 vom 10. April 2007',
22 u'description': u'md5:fb4818139c7cfe6907d4b83412a6864f',
23 },
24 }
25
26 def _real_extract(self, url):
27 mobj = re.match(self._VALID_URL, url)
28 episode = int(mobj.group('ep'))
29
30 server = random.randint(2, 4)
31 video_thumbnail = 'http://fernsehkritik.tv/images/magazin/folge%d.jpg' % episode
32 start_webpage = self._download_webpage('http://fernsehkritik.tv/folge-%d/Start' % episode,
33 episode)
34 playlist = self._search_regex(r'playlist = (\[.*?\]);', start_webpage,
35 u'playlist', flags=re.DOTALL)
36 files = json.loads(re.sub('{[^{}]*?}', '{}', playlist))
37 # TODO: return a single multipart video
38 videos = []
39 for i, _ in enumerate(files, 1):
40 video_id = '%04d%d' % (episode, i)
41 video_url = 'http://dl%d.fernsehkritik.tv/fernsehkritik%d%s.flv' % (server, episode, '' if i == 1 else '-%d' % i)
42 videos.append({
43 'id': video_id,
44 'url': video_url,
45 'ext': determine_ext(video_url),
46 'title': clean_html(get_element_by_id('eptitle', start_webpage)),
47 'description': clean_html(get_element_by_id('contentlist', start_webpage)),
48 'thumbnail': video_thumbnail
49 })
50 return videos
51
52
53 class FKTVPosteckeIE(InfoExtractor):
54 IE_NAME = u'fernsehkritik.tv:postecke'
55 _VALID_URL = r'(?:http://)?(?:www\.)?fernsehkritik\.tv/inline-video/postecke\.php\?(.*&)?ep=(?P<ep>[0-9]+)(&|$)'
56 _TEST = {
57 u'url': u'http://fernsehkritik.tv/inline-video/postecke.php?iframe=true&width=625&height=440&ep=120',
58 u'file': u'0120.flv',
59 u'md5': u'262f0adbac80317412f7e57b4808e5c4',
60 u'info_dict': {
61 u"title": u"Postecke 120"
62 }
63 }
64
65 def _real_extract(self, url):
66 mobj = re.match(self._VALID_URL, url)
67 episode = int(mobj.group('ep'))
68
69 server = random.randint(2, 4)
70 video_id = '%04d' % episode
71 video_url = 'http://dl%d.fernsehkritik.tv/postecke/postecke%d.flv' % (server, episode)
72 video_title = 'Postecke %d' % episode
73 return {
74 'id': video_id,
75 'url': video_url,
76 'ext': determine_ext(video_url),
77 'title': video_title,
78 }