[regiotv] Add new extractor (closes #7797)
[youtube-dl] / youtube_dl / extractor / regiotv.py
1 # -*- coding: utf-8 -*-
2 from __future__ import unicode_literals
3
4 import re
5
6 from .common import InfoExtractor
7
8 from ..utils import (
9     sanitized_Request,
10     xpath_with_ns,
11 )
12
13
14 class RegioTVIE(InfoExtractor):
15     _VALID_URL = r'https?://(?:www\.)?regio-tv\.de/video/(?P<id>[0-9]+).html'
16     _TESTS = [
17         {
18             'url': 'http://www.regio-tv.de/video/395808.html',
19             'info_dict': {
20                 'id': '395808',
21                 'ext': 'mp4',
22                 'title': u'Wir in Ludwigsburg',
23                 'description': u'Mit unseren zuckers\xfc\xdfen Adventskindern, au\xdferdem besuchen wir die Abendsterne!',
24             }
25         },
26     ]
27
28     def _real_extract(self, url):
29         mobj = re.match(self._VALID_URL, url)
30         video_id = mobj.group('id')
31
32         webpage = self._download_webpage(url, video_id)
33         key = self._html_search_regex(r''',key: "(.*?)"''', webpage, 'key')
34
35         title = self._html_search_regex(
36             r'<meta property="og:title" content="\s*(.*?)\s*"\s*/?\s*>',
37             webpage, 'title')
38
39         soapxml = '<?xml version="1.0" encoding="utf-8"?><soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"><soap:Body><getHTML5VideoData xmlns="http://v.telvi.de/"><key xsi:type="xsd:string">%s</key></getHTML5VideoData></soap:Body></soap:Envelope>' % key
40         request = sanitized_Request('http://v.telvi.de/?wsdl', soapxml)
41         request.add_header('Origin', 'http://www.regio-tv.de')
42         request.add_header('Referer', url)
43         video_data = self._download_xml(request, video_id, 'video data')
44
45         NS_MAP = {
46             'xsi': 'http://www.w3.org/2001/XMLSchema-instance',
47             'soap': 'http://schemas.xmlsoap.org/soap/envelope/',
48         }
49
50         url = video_data.find(xpath_with_ns('.//video', NS_MAP)).text
51         thumbnail = video_data.find(xpath_with_ns('.//image', NS_MAP)).text
52
53         description = self._html_search_meta('description', webpage)
54
55         return {
56             'id': video_id,
57             'title': title,
58             'url': url,
59             'thumbnail': thumbnail,
60             'description': description,
61         }