]> jfr.im git - yt-dlp.git/blame - youtube_dl/extractor/izlesene.py
Fix "invalid escape sequences" error on Python 3.6
[yt-dlp.git] / youtube_dl / extractor / izlesene.py
CommitLineData
366b1f3c
NJ
1# coding: utf-8
2from __future__ import unicode_literals
3
4import re
5
6from .common import InfoExtractor
dfe7dd9b 7from ..compat import compat_urllib_parse_unquote
f4776371 8from ..utils import (
f4776371 9 determine_ext,
2c5c1f48 10 float_or_none,
81b22aee
NJ
11 get_element_by_id,
12 int_or_none,
13 parse_iso8601,
f4776371
S
14 str_to_int,
15)
366b1f3c
NJ
16
17
18class IzleseneIE(InfoExtractor):
f1d15e6d
NJ
19 _VALID_URL = r'''(?x)
20 https?://(?:(?:www|m)\.)?izlesene\.com/
21 (?:video|embedplayer)/(?:[^/]+/)?(?P<id>[0-9]+)
22 '''
f1d15e6d
NJ
23 _TESTS = [
24 {
25 'url': 'http://www.izlesene.com/video/sevincten-cildirtan-dogum-gunu-hediyesi/7599694',
26 'md5': '4384f9f0ea65086734b881085ee05ac2',
27 'info_dict': {
28 'id': '7599694',
29 'ext': 'mp4',
30 'title': 'Sevinçten Çıldırtan Doğum Günü Hediyesi',
31 'description': 'md5:253753e2655dde93f59f74b572454f6d',
ec85ded8 32 'thumbnail': r're:^https?://.*\.jpg',
f1d15e6d 33 'uploader_id': 'pelikzzle',
c33c547d 34 'timestamp': int,
f1d15e6d
NJ
35 'upload_date': '20140702',
36 'duration': 95.395,
37 'age_limit': 0,
38 }
39 },
40 {
41 'url': 'http://www.izlesene.com/video/tarkan-dortmund-2006-konseri/17997',
42 'md5': '97f09b6872bffa284cb7fa4f6910cb72',
43 'info_dict': {
44 'id': '17997',
45 'ext': 'mp4',
46 'title': 'Tarkan Dortmund 2006 Konseri',
ec85ded8 47 'thumbnail': r're:^https://.*\.jpg',
f1d15e6d 48 'uploader_id': 'parlayankiz',
c33c547d 49 'timestamp': int,
f1d15e6d
NJ
50 'upload_date': '20061112',
51 'duration': 253.666,
52 'age_limit': 0,
53 }
54 },
55 ]
366b1f3c
NJ
56
57 def _real_extract(self, url):
81b22aee 58 video_id = self._match_id(url)
366b1f3c 59
81b22aee 60 url = 'http://www.izlesene.com/video/%s' % video_id
366b1f3c
NJ
61 webpage = self._download_webpage(url, video_id)
62
63 title = self._og_search_title(webpage)
c9d44887 64 description = self._og_search_description(webpage, default=None)
1414df5c
NJ
65 thumbnail = self._proto_relative_url(
66 self._og_search_thumbnail(webpage), scheme='http:')
f4776371
S
67
68 uploader = self._html_search_regex(
f1d15e6d 69 r"adduserUsername\s*=\s*'([^']+)';",
dfe7dd9b 70 webpage, 'uploader', fatal=False)
f4776371 71 timestamp = parse_iso8601(self._html_search_meta(
dfe7dd9b 72 'uploadDate', webpage, 'upload date'))
f4776371 73
2c5c1f48 74 duration = float_or_none(self._html_search_regex(
f1d15e6d 75 r'"videoduration"\s*:\s*"([^"]+)"',
2c5c1f48 76 webpage, 'duration', fatal=False), scale=1000)
f4776371
S
77
78 view_count = str_to_int(get_element_by_id('videoViewCount', webpage))
366b1f3c 79 comment_count = self._html_search_regex(
f1d15e6d
NJ
80 r'comment_count\s*=\s*\'([^\']+)\';',
81 webpage, 'comment_count', fatal=False)
366b1f3c 82
f4776371
S
83 content_url = self._html_search_meta(
84 'contentURL', webpage, 'content URL', fatal=False)
85 ext = determine_ext(content_url, 'mp4')
366b1f3c
NJ
86
87 # Might be empty for some videos.
f1d15e6d 88 streams = self._html_search_regex(
dfe7dd9b 89 r'"qualitylevel"\s*:\s*"([^"]+)"', webpage, 'streams', default='')
366b1f3c
NJ
90
91 formats = []
f1d15e6d
NJ
92 if streams:
93 for stream in streams.split('|'):
94 quality, url = re.search(r'\[(\w+)\](.+)', stream).groups()
95 formats.append({
96 'format_id': '%sp' % quality if quality else 'sd',
dfe7dd9b 97 'url': compat_urllib_parse_unquote(url),
f1d15e6d
NJ
98 'ext': ext,
99 })
100 else:
101 stream_url = self._search_regex(
dfe7dd9b 102 r'"streamurl"\s*:\s*"([^"]+)"', webpage, 'stream URL')
366b1f3c 103 formats.append({
f1d15e6d 104 'format_id': 'sd',
dfe7dd9b 105 'url': compat_urllib_parse_unquote(stream_url),
366b1f3c 106 'ext': ext,
366b1f3c
NJ
107 })
108
109 return {
110 'id': video_id,
111 'title': title,
366b1f3c
NJ
112 'description': description,
113 'thumbnail': thumbnail,
f4776371
S
114 'uploader_id': uploader,
115 'timestamp': timestamp,
366b1f3c
NJ
116 'duration': duration,
117 'view_count': int_or_none(view_count),
366b1f3c 118 'comment_count': int_or_none(comment_count),
641eb10d 119 'age_limit': self._family_friendly_search(webpage),
f4776371 120 'formats': formats,
366b1f3c 121 }