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