]> Raphaël G. Git Repositories - youtubedl/blob - youtube_dl/extractor/izlesene.py
Imported Upstream version 2014.08.05
[youtubedl] / youtube_dl / extractor / izlesene.py
1 # coding: utf-8
2 from __future__ import unicode_literals
3
4 import re
5
6 from .common import InfoExtractor
7 from ..utils import (
8 get_element_by_id,
9 parse_iso8601,
10 determine_ext,
11 int_or_none,
12 str_to_int,
13 )
14
15
16 class IzleseneIE(InfoExtractor):
17 _VALID_URL = r'https?://(?:(?:www|m)\.)?izlesene\.com/(?:video|embedplayer)/(?:[^/]+/)?(?P<id>[0-9]+)'
18 _STREAM_URL = 'http://panel.izlesene.com/api/streamurl/{id:}/{format:}'
19 _TEST = {
20 'url': 'http://www.izlesene.com/video/sevincten-cildirtan-dogum-gunu-hediyesi/7599694',
21 'md5': '4384f9f0ea65086734b881085ee05ac2',
22 'info_dict': {
23 'id': '7599694',
24 'ext': 'mp4',
25 'title': 'Sevinçten Çıldırtan Doğum Günü Hediyesi',
26 'description': 'Annesi oğluna doğum günü hediyesi olarak minecraft cd si alıyor, ve çocuk hunharca seviniyor',
27 'thumbnail': 're:^http://.*\.jpg',
28 'uploader_id': 'pelikzzle',
29 'timestamp': 1404298698,
30 'upload_date': '20140702',
31 'duration': 95.395,
32 'age_limit': 0,
33 }
34 }
35
36 def _real_extract(self, url):
37 mobj = re.match(self._VALID_URL, url)
38 video_id = mobj.group('id')
39 url = 'http://www.izlesene.com/video/%s' % video_id
40
41 webpage = self._download_webpage(url, video_id)
42
43 title = self._og_search_title(webpage)
44 description = self._og_search_description(webpage)
45 thumbnail = self._og_search_thumbnail(webpage)
46
47 uploader = self._html_search_regex(
48 r"adduserUsername\s*=\s*'([^']+)';", webpage, 'uploader', fatal=False, default='')
49 timestamp = parse_iso8601(self._html_search_meta(
50 'uploadDate', webpage, 'upload date', fatal=False))
51
52 duration = int_or_none(self._html_search_regex(
53 r'"videoduration"\s*:\s*"([^"]+)"', webpage, 'duration', fatal=False))
54 if duration:
55 duration /= 1000.0
56
57 view_count = str_to_int(get_element_by_id('videoViewCount', webpage))
58 comment_count = self._html_search_regex(
59 r'comment_count\s*=\s*\'([^\']+)\';', webpage, 'uploader', fatal=False)
60
61 family_friendly = self._html_search_meta(
62 'isFamilyFriendly', webpage, 'age limit', fatal=False)
63
64 content_url = self._html_search_meta(
65 'contentURL', webpage, 'content URL', fatal=False)
66 ext = determine_ext(content_url, 'mp4')
67
68 # Might be empty for some videos.
69 qualities = self._html_search_regex(
70 r'"quality"\s*:\s*"([^"]+)"', webpage, 'qualities', fatal=False, default='')
71
72 formats = []
73 for quality in qualities.split('|'):
74 json = self._download_json(
75 self._STREAM_URL.format(id=video_id, format=quality), video_id,
76 note='Getting video URL for "%s" quality' % quality,
77 errnote='Failed to get video URL for "%s" quality' % quality
78 )
79 formats.append({
80 'url': json.get('streamurl'),
81 'ext': ext,
82 'format_id': '%sp' % quality if quality else 'sd',
83 })
84
85 return {
86 'id': video_id,
87 'title': title,
88 'description': description,
89 'thumbnail': thumbnail,
90 'uploader_id': uploader,
91 'timestamp': timestamp,
92 'duration': duration,
93 'view_count': int_or_none(view_count),
94 'comment_count': int_or_none(comment_count),
95 'age_limit': 18 if family_friendly == 'False' else 0,
96 'formats': formats,
97 }