[youtube] Fix extraction.
[youtube-dl] / youtube_dl / extractor / footyroom.py
1 # coding: utf-8
2 from __future__ import unicode_literals
3
4 from .common import InfoExtractor
5 from .streamable import StreamableIE
6
7
8 class FootyRoomIE(InfoExtractor):
9     _VALID_URL = r'https?://footyroom\.com/matches/(?P<id>\d+)'
10     _TESTS = [{
11         'url': 'http://footyroom.com/matches/79922154/hull-city-vs-chelsea/review',
12         'info_dict': {
13             'id': '79922154',
14             'title': 'VIDEO Hull City 0 - 2 Chelsea',
15         },
16         'playlist_count': 2,
17         'add_ie': [StreamableIE.ie_key()],
18     }, {
19         'url': 'http://footyroom.com/matches/75817984/georgia-vs-germany/review',
20         'info_dict': {
21             'id': '75817984',
22             'title': 'VIDEO Georgia 0 - 2 Germany',
23         },
24         'playlist_count': 1,
25         'add_ie': ['Playwire']
26     }]
27
28     def _real_extract(self, url):
29         playlist_id = self._match_id(url)
30
31         webpage = self._download_webpage(url, playlist_id)
32
33         playlist = self._parse_json(self._search_regex(
34             r'DataStore\.media\s*=\s*([^;]+)', webpage, 'media data'),
35             playlist_id)
36
37         playlist_title = self._og_search_title(webpage)
38
39         entries = []
40         for video in playlist:
41             payload = video.get('payload')
42             if not payload:
43                 continue
44             playwire_url = self._html_search_regex(
45                 r'data-config="([^"]+)"', payload,
46                 'playwire url', default=None)
47             if playwire_url:
48                 entries.append(self.url_result(self._proto_relative_url(
49                     playwire_url, 'http:'), 'Playwire'))
50
51             streamable_url = StreamableIE._extract_url(payload)
52             if streamable_url:
53                 entries.append(self.url_result(
54                     streamable_url, StreamableIE.ie_key()))
55
56         return self.playlist_result(entries, playlist_id, playlist_title)