]> gitweb @ CieloNegro.org - youtube-dl.git/blob - youtube_dl/extractor/tvn24.py
[qqmusic:toplist] PEP 8
[youtube-dl.git] / youtube_dl / extractor / tvn24.py
1 # coding: utf-8
2 from __future__ import unicode_literals
3
4 from .common import InfoExtractor
5 from ..utils import (
6     int_or_none,
7     unescapeHTML,
8 )
9
10
11 class TVN24IE(InfoExtractor):
12     _VALID_URL = r'https?://(?:(?:[^/]+)\.)?tvn24(?:bis)?\.pl/(?:[^/]+/)*(?P<id>[^/]+)\.html'
13     _TESTS = [{
14         'url': 'http://www.tvn24.pl/wiadomosci-z-kraju,3/oredzie-artura-andrusa,702428.html',
15         'md5': 'fbdec753d7bc29d96036808275f2130c',
16         'info_dict': {
17             'id': '1584444',
18             'ext': 'mp4',
19             'title': '"Święta mają być wesołe, dlatego, ludziska, wszyscy pod jemiołę"',
20             'description': 'Wyjątkowe orędzie Artura Andrusa, jednego z gości "Szkła kontaktowego".',
21             'thumbnail': 're:http://.*[.]jpeg',
22         }
23     }, {
24         'url': 'http://fakty.tvn24.pl/ogladaj-online,60/53-konferencja-bezpieczenstwa-w-monachium,716431.html',
25         'only_matching': True,
26     }, {
27         'url': 'http://sport.tvn24.pl/pilka-nozna,105/ligue-1-kamil-glik-rozcial-glowe-monaco-tylko-remisuje-z-bastia,716522.html',
28         'only_matching': True,
29     }, {
30         'url': 'http://tvn24bis.pl/poranek,146,m/gen-koziej-w-tvn24-bis-wracamy-do-czasow-zimnej-wojny,715660.html',
31         'only_matching': True,
32     }]
33
34     def _real_extract(self, url):
35         video_id = self._match_id(url)
36
37         webpage = self._download_webpage(url, video_id)
38
39         title = self._og_search_title(webpage)
40
41         def extract_json(attr, name, fatal=True):
42             return self._parse_json(
43                 self._search_regex(
44                     r'\b%s=(["\'])(?P<json>(?!\1).+?)\1' % attr, webpage,
45                     name, group='json', fatal=fatal) or '{}',
46                 video_id, transform_source=unescapeHTML, fatal=fatal)
47
48         quality_data = extract_json('data-quality', 'formats')
49
50         formats = []
51         for format_id, url in quality_data.items():
52             formats.append({
53                 'url': url,
54                 'format_id': format_id,
55                 'height': int_or_none(format_id.rstrip('p')),
56             })
57         self._sort_formats(formats)
58
59         description = self._og_search_description(webpage)
60         thumbnail = self._og_search_thumbnail(
61             webpage, default=None) or self._html_search_regex(
62             r'\bdata-poster=(["\'])(?P<url>(?!\1).+?)\1', webpage,
63             'thumbnail', group='url')
64
65         share_params = extract_json(
66             'data-share-params', 'share params', fatal=False)
67         if isinstance(share_params, dict):
68             video_id = share_params.get('id') or video_id
69
70         return {
71             'id': video_id,
72             'title': title,
73             'description': description,
74             'thumbnail': thumbnail,
75             'formats': formats,
76         }