[ynet] Add new extractor
[youtube-dl] / youtube_dl / extractor / ynet.py
1 # coding: utf-8
2 from __future__ import unicode_literals
3
4 import re
5 import base64
6 import json
7
8 from .common import InfoExtractor
9 from youtube_dl.utils import compat_urllib_parse_urlparse, compat_urllib_parse
10
11 class YnetIE(InfoExtractor):
12     _VALID_URL = r'http://.*ynet\.co\.il/.*/0,7340,(?P<id>L(-[0-9]+)+),00\.html'
13     _TEST = {
14         'url': 'http://hot.ynet.co.il/home/0,7340,L-11659-99244,00.html',
15         'info_dict': {
16             'id': 'L-11659-99244',
17             'ext': 'flv',
18             'title': 'md5:3dba12d2837ee2ad9652cc64af652b16',
19             'thumbnail': 'http://hot.ynet.co.il/PicServer4/2014/09/23/5606015/AMERICAN_COMMUNE1_T.jpg',
20         }
21     }
22
23     def _real_extract(self, url):
24         mobj = re.match(self._VALID_URL, url)
25         
26         id = mobj.group('id')
27         
28         webpage = self._download_webpage(url, id)
29
30         content = compat_urllib_parse.unquote_plus(self._og_search_video_url(webpage).decode('utf-8'))
31
32         player_url = re.match('(http.*\.swf)\?' ,content).group(1)
33         
34         config = json.loads(re.match('.*config\=(.*)' ,content).group(1))
35                 
36         f4m_url = config['clip']['url']    
37
38         title = re.sub(': Video$', '', self._og_search_title(webpage))
39
40         return {
41             'id': id,
42             'title': title,
43             'formats': self._extract_f4m_formats(f4m_url, id),
44             'thumbnail': self._og_search_thumbnail(webpage),
45             'player_url': player_url,
46         }
47