[Gamekings] Fix viewing of old videos
[youtube-dl] / youtube_dl / extractor / gamekings.py
1 # coding: utf-8
2 from __future__ import unicode_literals
3
4 from .common import InfoExtractor
5 from ..utils import (
6     xpath_text,
7     xpath_with_ns,
8 )
9
10
11 class GamekingsIE(InfoExtractor):
12     _VALID_URL = r'http://www\.gamekings\.nl/(?:videos|nieuws)/(?P<id>[^/]+)'
13     _TESTS = [{
14         'url': 'http://www.gamekings.nl/videos/phoenix-wright-ace-attorney-dual-destinies-review/',
15         # MD5 is flaky, seems to change regularly
16         # 'md5': '2f32b1f7b80fdc5cb616efb4f387f8a3',
17         'info_dict': {
18             'id': 'HkSQKetlGOU',
19             'ext': 'mp4',
20             'title': 'Phoenix Wright: Ace Attorney - Dual Destinies Review',
21             'description': 'md5:db88c0e7f47e9ea50df3271b9dc72e1d',
22             'thumbnail': 're:^https?://.*\.jpg$',
23             'uploader_id': 'UCJugRGo4STYMeFr5RoOShtQ',
24             'uploader': 'Gamekings Vault',
25             'upload_date': '20151123',
26         },
27     }, {
28         # vimeo video
29         'url': 'http://www.gamekings.nl/videos/the-legend-of-zelda-majoras-mask/',
30         'md5': '12bf04dfd238e70058046937657ea68d',
31         'info_dict': {
32             'id': 'the-legend-of-zelda-majoras-mask',
33             'ext': 'mp4',
34             'title': 'The Legend of Zelda: Majora’s Mask',
35             'description': 'md5:9917825fe0e9f4057601fe1e38860de3',
36             'thumbnail': 're:^https?://.*\.jpg$',
37         },
38     }, {
39         'url': 'http://www.gamekings.nl/nieuws/gamekings-extra-shelly-en-david-bereiden-zich-voor-op-de-livestream/',
40         'only_matching': True,
41     }]
42
43     def _real_extract(self, url):
44         video_id = self._match_id(url)
45
46         webpage = self._download_webpage(url, video_id)
47
48         playlist_id = self._search_regex(
49             r'gogoVideo\(.*,\s*"([^"]+)', webpage, 'playlist id')
50
51         # Check if a YouTube embed is used
52         if playlist_id.find('youtube') != -1:
53             return self.url_result(playlist_id, ie='Youtube')
54
55         playlist = self._download_xml(
56             'http://www.gamekings.tv/wp-content/themes/gk2010/rss_playlist.php?id=%s' % playlist_id,
57             video_id)
58
59         NS_MAP = {
60             'jwplayer': 'http://rss.jwpcdn.com/'
61         }
62
63         item = playlist.find('./channel/item')
64
65         thumbnail = xpath_text(item, xpath_with_ns('./jwplayer:image', NS_MAP), 'thumbnail')
66         video_url = item.find(xpath_with_ns('./jwplayer:source', NS_MAP)).get('file')
67
68         return {
69             'id': video_id,
70             'url': video_url,
71             'title': self._og_search_title(webpage),
72             'description': self._og_search_description(webpage),
73             'thumbnail': thumbnail,
74         }