]> Raphaël G. Git Repositories - youtubedl/blob - youtube_dl/extractor/fivetv.py
New upstream version 2019.09.01
[youtubedl] / 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 https?://
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 # redirect to https://www.5-tv.ru/projects/1000095/izvestia-glavnoe/
43 'url': 'http://www.5-tv.ru/glavnoe/#itemDetails',
44 'info_dict': {
45 'id': 'glavnoe',
46 'ext': 'mp4',
47 'title': r're:^Итоги недели с \d+ по \d+ \w+ \d{4} года$',
48 'thumbnail': r're:^https?://.*\.jpg$',
49 },
50 'skip': 'redirect to «Известия. Главное» project page',
51 }, {
52 'url': 'http://www.5-tv.ru/glavnoe/broadcasts/508645/',
53 'only_matching': True,
54 }, {
55 'url': 'http://5-tv.ru/films/1507502/',
56 'only_matching': True,
57 }, {
58 'url': 'http://5-tv.ru/programs/broadcast/508713/',
59 'only_matching': True,
60 }, {
61 'url': 'http://5-tv.ru/angel/',
62 'only_matching': True,
63 }, {
64 'url': 'http://www.5-tv.ru/schedule/?iframe=true&width=900&height=450',
65 'only_matching': True,
66 }]
67
68 def _real_extract(self, url):
69 mobj = re.match(self._VALID_URL, url)
70 video_id = mobj.group('id') or mobj.group('path')
71
72 webpage = self._download_webpage(url, video_id)
73
74 video_url = self._search_regex(
75 [r'<div[^>]+?class="(?:flow)?player[^>]+?data-href="([^"]+)"',
76 r'<a[^>]+?href="([^"]+)"[^>]+?class="videoplayer"'],
77 webpage, 'video url')
78
79 title = self._og_search_title(webpage, default=None) or self._search_regex(
80 r'<title>([^<]+)</title>', webpage, 'title')
81 duration = int_or_none(self._og_search_property(
82 'video:duration', webpage, 'duration', default=None))
83
84 return {
85 'id': video_id,
86 'url': video_url,
87 'title': title,
88 'description': self._og_search_description(webpage, default=None),
89 'thumbnail': self._og_search_thumbnail(webpage, default=None),
90 'duration': duration,
91 }