[izlesene] Fix extraction (closes #16233)
[youtube-dl] / youtube_dl / extractor / izlesene.py
1 # coding: utf-8
2 from __future__ import unicode_literals
3
4 from .common import InfoExtractor
5 from ..compat import compat_urllib_parse_unquote
6 from ..utils import (
7     determine_ext,
8     float_or_none,
9     get_element_by_id,
10     int_or_none,
11     parse_iso8601,
12     str_to_int,
13 )
14
15
16 class IzleseneIE(InfoExtractor):
17     _VALID_URL = r'''(?x)
18         https?://(?:(?:www|m)\.)?izlesene\.com/
19         (?:video|embedplayer)/(?:[^/]+/)?(?P<id>[0-9]+)
20         '''
21     _TESTS = [
22         {
23             'url': 'http://www.izlesene.com/video/sevincten-cildirtan-dogum-gunu-hediyesi/7599694',
24             'md5': '4384f9f0ea65086734b881085ee05ac2',
25             'info_dict': {
26                 'id': '7599694',
27                 'ext': 'mp4',
28                 'title': 'Sevinçten Çıldırtan Doğum Günü Hediyesi',
29                 'description': 'md5:253753e2655dde93f59f74b572454f6d',
30                 'thumbnail': r're:^https?://.*\.jpg',
31                 'uploader_id': 'pelikzzle',
32                 'timestamp': int,
33                 'upload_date': '20140702',
34                 'duration': 95.395,
35                 'age_limit': 0,
36             }
37         },
38         {
39             'url': 'http://www.izlesene.com/video/tarkan-dortmund-2006-konseri/17997',
40             'md5': '97f09b6872bffa284cb7fa4f6910cb72',
41             'info_dict': {
42                 'id': '17997',
43                 'ext': 'mp4',
44                 'title': 'Tarkan Dortmund 2006 Konseri',
45                 'thumbnail': r're:^https://.*\.jpg',
46                 'uploader_id': 'parlayankiz',
47                 'timestamp': int,
48                 'upload_date': '20061112',
49                 'duration': 253.666,
50                 'age_limit': 0,
51             }
52         },
53     ]
54
55     def _real_extract(self, url):
56         video_id = self._match_id(url)
57
58         url = 'http://www.izlesene.com/video/%s' % video_id
59         webpage = self._download_webpage(url, video_id)
60
61         title = self._og_search_title(webpage)
62         description = self._og_search_description(webpage, default=None)
63         thumbnail = self._proto_relative_url(
64             self._og_search_thumbnail(webpage), scheme='http:')
65
66         uploader = self._html_search_regex(
67             r"adduserUsername\s*=\s*'([^']+)';",
68             webpage, 'uploader', fatal=False)
69         timestamp = parse_iso8601(self._html_search_meta(
70             'uploadDate', webpage, 'upload date'))
71
72         duration = float_or_none(self._html_search_regex(
73             r'videoduration\s*=\s*\'([^\']+)\'',
74             webpage, 'duration', fatal=False), scale=1000)
75
76         view_count = str_to_int(get_element_by_id('videoViewCount', webpage))
77         comment_count = self._html_search_regex(
78             r'comment_count\s*=\s*\'([^\']+)\';',
79             webpage, 'comment_count', fatal=False)
80
81         streams_json = self._html_search_regex(
82             r'_videoObj\s*=\s*(.+);', webpage, 'streams')
83         streams = self._parse_json(streams_json, video_id)
84
85         formats = []
86         for stream in streams.get('media').get('level'):
87             url = stream.get('source')
88             ext = determine_ext(url, 'mp4')
89             quality = stream.get('value')
90             formats.append({
91                 'format_id': '%sp' % quality,
92                 'url': compat_urllib_parse_unquote(url),
93                 'ext': ext,
94             })
95
96         return {
97             'id': video_id,
98             'title': title,
99             'description': description,
100             'thumbnail': thumbnail,
101             'uploader_id': uploader,
102             'timestamp': timestamp,
103             'duration': duration,
104             'view_count': int_or_none(view_count),
105             'comment_count': int_or_none(comment_count),
106             'age_limit': self._family_friendly_search(webpage),
107             'formats': formats,
108         }