3c1f7f19581a0a648d86fa641f9e165cf6fc187d
[youtube-dl] / youtube_dl / extractor / gamekings.py
1 from __future__ import unicode_literals
2
3 import re
4
5 from .common import InfoExtractor
6 from ..utils import (
7     xpath_text,
8     xpath_with_ns
9  )
10
11
12 class GamekingsIE(InfoExtractor):
13     _VALID_URL = r'http://www\.gamekings\.tv/videos/(?P<name>[0-9a-z\-]+)'
14     _TESTS = [
15         {
16         'url': 'http://www.gamekings.tv/videos/phoenix-wright-ace-attorney-dual-destinies-review/',
17         # MD5 is flaky, seems to change regularly
18         # 'md5': '2f32b1f7b80fdc5cb616efb4f387f8a3',
19         'info_dict': {
20             'id': '20130811',
21             'ext': 'mp4',
22             'title': 'Phoenix Wright: Ace Attorney \u2013 Dual Destinies Review',
23             'description': 'md5:36fd701e57e8c15ac8682a2374c99731',
24             }
25         },
26         {
27         'url': 'http://www.gamekings.tv/videos/the-legend-of-zelda-majoras-mask/',
28         'info_dict': {
29             'id': '118933752',
30             'ext': 'mp4',
31             'title': 'The Legend of Zelda: Majora’s Mask',
32             'description': 'md5:9917825fe0e9f4057601fe1e38860de3'
33             }
34         }
35     ]
36
37     def _real_extract(self, url):
38
39         mobj = re.match(self._VALID_URL, url)
40         name = mobj.group('name')
41         webpage = self._download_webpage(url, name)
42
43         playlist_id = re.search(r'(?:gogoVideo)\(\d+,"?(?P<playlist_id>.*)"', webpage, re.MULTILINE).group('playlist_id')
44         playlist_url = 'http://www.gamekings.tv/wp-content/themes/gk2010/rss_playlist.php?id=' + playlist_id
45         playlist_rss = self._download_xml(playlist_url, playlist_id)
46         
47
48         NS_MAP = {
49             'jwplayer': 'http://rss.jwpcdn.com/'
50          }
51
52         item = playlist_rss.find('./channel/item')
53         
54         image = xpath_text(item, xpath_with_ns('./jwplayer:image', NS_MAP), 'image')
55         file_node = item.find(xpath_with_ns('./jwplayer:source', NS_MAP))
56         
57         video_url = file_node.get('file')
58         video = re.search(r'[0-9]+', video_url)
59         video_id = video.group(0)
60         
61         # Todo: Add medium format
62
63         return {
64             'id': video_id,
65             'ext': 'mp4',
66             'url': video_url,
67             'title': self._og_search_title(webpage),
68             'description': self._og_search_description(webpage),
69         }