]> jfr.im git - yt-dlp.git/blob - yt_dlp/extractor/izlesene.py
[ie/orf:on] Improve extraction (#9677)
[yt-dlp.git] / yt_dlp / extractor / izlesene.py
1 from .common import InfoExtractor
2 from ..compat import (
3 compat_str,
4 compat_urllib_parse_unquote,
5 )
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 webpage = self._download_webpage('http://www.izlesene.com/video/%s' % video_id, video_id)
59
60 video = self._parse_json(
61 self._search_regex(
62 r'videoObj\s*=\s*({.+?})\s*;\s*\n', webpage, 'streams'),
63 video_id)
64
65 title = video.get('videoTitle') or self._og_search_title(webpage)
66
67 formats = []
68 for stream in video['media']['level']:
69 source_url = stream.get('source')
70 if not source_url or not isinstance(source_url, compat_str):
71 continue
72 ext = determine_ext(url, 'mp4')
73 quality = stream.get('value')
74 height = int_or_none(quality)
75 formats.append({
76 'format_id': '%sp' % quality if quality else 'sd',
77 'url': compat_urllib_parse_unquote(source_url),
78 'ext': ext,
79 'height': height,
80 })
81
82 description = self._og_search_description(webpage, default=None)
83 thumbnail = video.get('posterURL') or self._proto_relative_url(
84 self._og_search_thumbnail(webpage), scheme='http:')
85
86 uploader = self._html_search_regex(
87 r"adduserUsername\s*=\s*'([^']+)';",
88 webpage, 'uploader', fatal=False)
89 timestamp = parse_iso8601(self._html_search_meta(
90 'uploadDate', webpage, 'upload date'))
91
92 duration = float_or_none(video.get('duration') or self._html_search_regex(
93 r'videoduration["\']?\s*=\s*(["\'])(?P<value>(?:(?!\1).)+)\1',
94 webpage, 'duration', fatal=False, group='value'), scale=1000)
95
96 view_count = str_to_int(get_element_by_id('videoViewCount', webpage))
97 comment_count = self._html_search_regex(
98 r'comment_count\s*=\s*\'([^\']+)\';',
99 webpage, 'comment_count', fatal=False)
100
101 return {
102 'id': video_id,
103 'title': title,
104 'description': description,
105 'thumbnail': thumbnail,
106 'uploader_id': uploader,
107 'timestamp': timestamp,
108 'duration': duration,
109 'view_count': int_or_none(view_count),
110 'comment_count': int_or_none(comment_count),
111 'age_limit': self._family_friendly_search(webpage),
112 'formats': formats,
113 }