Merge remote-tracking branch 'lenaten/karaoketv'
[ytdl] / youtube_dl / extractor / karaoketv.py
1 # coding: utf-8
2 from __future__ import unicode_literals
3
4 import re
5 import json
6 import sys
7
8 from .common import InfoExtractor
9 from ..utils import compat_urllib_parse, ExtractorError
10
11
12 class KaraoketvIE(InfoExtractor):
13     _VALID_URL = r'http://karaoketv\.co\.il/\?container=songs&id=(?P<id>[0-9]+)'
14     _TEST = {
15         'url': 'http://karaoketv.co.il/?container=songs&id=171568',
16         'info_dict': {
17             'id': '171568',
18             'ext': 'mp4',
19             'title': 'אל העולם שלך - רותם כהן - שרים קריוקי',
20         }
21     }
22
23     def _real_extract(self, url):
24
25         # BUG: SSL23_GET_SERVER_HELLO:unknown protocol 
26         if sys.hexversion < 0x03000000:
27             raise ExtractorError("Only python 3 supported.\n")
28
29         mobj = re.match(self._VALID_URL, url)
30         
31         video_id = mobj.group('id')
32
33         webpage = self._download_webpage(url, video_id)
34
35         settings_json = compat_urllib_parse.unquote_plus(self._search_regex(r'config=(.*)', self._og_search_video_url(webpage ,video_id), ''))
36         
37         urls_info_webpage = self._download_webpage(settings_json, 'Downloading settings json')
38
39         urls_info_json = json.loads(urls_info_webpage.replace('\'', '"'))
40
41         url = urls_info_json['playlist'][0]['url']
42
43         return {
44             'id': video_id,
45             'title': self._og_search_title(webpage),
46             'url': url,
47         }