Fix "invalid escape sequences" error on Python 3.6
[youtube-dl] / youtube_dl / extractor / fivetv.py
1 # coding: utf-8
2 from __future__ import unicode_literals
3
4 import re
5
6 from .common import InfoExtractor
7 from ..utils import int_or_none
8
9
10 class FiveTVIE(InfoExtractor):
11     _VALID_URL = r'''(?x)
12                     http://
13                         (?:www\.)?5-tv\.ru/
14                         (?:
15                             (?:[^/]+/)+(?P<id>\d+)|
16                             (?P<path>[^/?#]+)(?:[/?#])?
17                         )
18                     '''
19
20     _TESTS = [{
21         'url': 'http://5-tv.ru/news/96814/',
22         'md5': 'bbff554ad415ecf5416a2f48c22d9283',
23         'info_dict': {
24             'id': '96814',
25             'ext': 'mp4',
26             'title': 'Россияне выбрали имя для общенациональной платежной системы',
27             'description': 'md5:a8aa13e2b7ad36789e9f77a74b6de660',
28             'thumbnail': r're:^https?://.*\.jpg$',
29             'duration': 180,
30         },
31     }, {
32         'url': 'http://5-tv.ru/video/1021729/',
33         'info_dict': {
34             'id': '1021729',
35             'ext': 'mp4',
36             'title': '3D принтер',
37             'description': 'md5:d76c736d29ef7ec5c0cf7d7c65ffcb41',
38             'thumbnail': r're:^https?://.*\.jpg$',
39             'duration': 180,
40         },
41     }, {
42         'url': 'http://www.5-tv.ru/glavnoe/#itemDetails',
43         'info_dict': {
44             'id': 'glavnoe',
45             'ext': 'mp4',
46             'title': 'Итоги недели с 8 по 14 июня 2015 года',
47             'thumbnail': r're:^https?://.*\.jpg$',
48         },
49     }, {
50         'url': 'http://www.5-tv.ru/glavnoe/broadcasts/508645/',
51         'only_matching': True,
52     }, {
53         'url': 'http://5-tv.ru/films/1507502/',
54         'only_matching': True,
55     }, {
56         'url': 'http://5-tv.ru/programs/broadcast/508713/',
57         'only_matching': True,
58     }, {
59         'url': 'http://5-tv.ru/angel/',
60         'only_matching': True,
61     }, {
62         'url': 'http://www.5-tv.ru/schedule/?iframe=true&width=900&height=450',
63         'only_matching': True,
64     }]
65
66     def _real_extract(self, url):
67         mobj = re.match(self._VALID_URL, url)
68         video_id = mobj.group('id') or mobj.group('path')
69
70         webpage = self._download_webpage(url, video_id)
71
72         video_url = self._search_regex(
73             r'<a[^>]+?href="([^"]+)"[^>]+?class="videoplayer"',
74             webpage, 'video url')
75
76         title = self._og_search_title(webpage, default=None) or self._search_regex(
77             r'<title>([^<]+)</title>', webpage, 'title')
78         duration = int_or_none(self._og_search_property(
79             'video:duration', webpage, 'duration', default=None))
80
81         return {
82             'id': video_id,
83             'url': video_url,
84             'title': title,
85             'description': self._og_search_description(webpage, default=None),
86             'thumbnail': self._og_search_thumbnail(webpage, default=None),
87             'duration': duration,
88         }