Merge branch 'puls4' of https://github.com/HanYOLO/youtube-dl into HanYOLO-puls4
[youtube-dl] / youtube_dl / extractor / puls4.py
1 # -*- coding: utf-8 -*-
2
3 from __future__ import unicode_literals
4
5 from .common import InfoExtractor
6
7 import re
8
9
10 class Puls4IE(InfoExtractor):
11
12     _VALID_URL = r'https?://www.puls4.com/video/.+?/play/(?P<id>[0-9]+)'
13     _TESTS = [{
14         'url': 'http://www.puls4.com/video/pro-und-contra/play/2716816',
15         'md5': '49f6a6629747eeec43cef6a46b5df81d',
16         'info_dict': {
17             'id': '2716816',
18             'ext': 'mp4',
19             'title': 'Pro und Contra vom 23.02.2015'}},
20         {
21         'url': 'http://www.puls4.com/video/kult-spielfilme/play/1298106',
22         'md5': '6a48316c8903ece8dab9b9a7bf7a59ec',
23         'info_dict': {
24             'id': '1298106',
25             'ext': 'mp4',
26             'title': 'Lucky Fritz'}}
27     ]
28
29     def _real_extract(self, url):
30         video_id = self._match_id(url)
31         webpage = self._download_webpage(url, video_id)
32
33         # if fsk-button
34         real_url = self._html_search_regex(r'\"fsk-button\".+?href=\"([^"]+)',
35                                            webpage, 'fsk_button', default=None)
36         if real_url:
37             webpage = self._download_webpage(real_url, video_id)
38
39         title = self._html_search_regex(
40             r'<div id="bg_brandableContent">.+?<h1>(.+?)</h1>',
41             webpage, 'title', flags=re.DOTALL)
42
43         sd_url = self._html_search_regex(
44             r'{\"url\":\"([^"]+?)\",\"hd\":false',
45             webpage, 'sd_url').replace('\\', '')
46
47         formats = [{'format_id': 'sd', 'url': sd_url, 'quality': -2}]
48
49         hd_url = self._html_search_regex(
50             r'{\"url\":\"([^"]+?)\",\"hd\":true',
51             webpage, 'hd_url', default=None)
52         if hd_url:
53             hd_url = hd_url.replace('\\', '')
54             formats.append({'format_id': 'hd', 'url': hd_url, 'quality': -1})
55
56         return {
57             'id': video_id,
58             'title': title,
59             'formats': formats,
60             'ext': 'mp4'
61         }