]> Raphaël G. Git Repositories - youtubedl/blob - youtube_dl/extractor/pornovoisines.py
Update README.md
[youtubedl] / youtube_dl / extractor / pornovoisines.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 int_or_none,
9 float_or_none,
10 unified_strdate,
11 )
12
13
14 class PornoVoisinesIE(InfoExtractor):
15 _VALID_URL = r'https?://(?:www\.)?pornovoisines\.com/videos/show/(?P<id>\d+)/(?P<display_id>[^/.]+)'
16
17 _TEST = {
18 'url': 'http://www.pornovoisines.com/videos/show/919/recherche-appartement.html',
19 'md5': '6f8aca6a058592ab49fe701c8ba8317b',
20 'info_dict': {
21 'id': '919',
22 'display_id': 'recherche-appartement',
23 'ext': 'mp4',
24 'title': 'Recherche appartement',
25 'description': 'md5:fe10cb92ae2dd3ed94bb4080d11ff493',
26 'thumbnail': r're:^https?://.*\.jpg$',
27 'upload_date': '20140925',
28 'duration': 120,
29 'view_count': int,
30 'average_rating': float,
31 'categories': ['Débutante', 'Débutantes', 'Scénario', 'Sodomie'],
32 'age_limit': 18,
33 'subtitles': {
34 'fr': [{
35 'ext': 'vtt',
36 }]
37 },
38 }
39 }
40
41 def _real_extract(self, url):
42 mobj = re.match(self._VALID_URL, url)
43 video_id = mobj.group('id')
44 display_id = mobj.group('display_id')
45
46 settings_url = self._download_json(
47 'http://www.pornovoisines.com/api/video/%s/getsettingsurl/' % video_id,
48 video_id, note='Getting settings URL')['video_settings_url']
49 settings = self._download_json(settings_url, video_id)['data']
50
51 formats = []
52 for kind, data in settings['variants'].items():
53 if kind == 'HLS':
54 formats.extend(self._extract_m3u8_formats(
55 data, video_id, ext='mp4', entry_protocol='m3u8_native', m3u8_id='hls'))
56 elif kind == 'MP4':
57 for item in data:
58 formats.append({
59 'url': item['url'],
60 'height': item.get('height'),
61 'bitrate': item.get('bitrate'),
62 })
63 self._sort_formats(formats)
64
65 webpage = self._download_webpage(url, video_id)
66
67 title = self._og_search_title(webpage)
68 description = self._og_search_description(webpage)
69
70 # The webpage has a bug - there's no space between "thumb" and src=
71 thumbnail = self._html_search_regex(
72 r'<img[^>]+class=([\'"])thumb\1[^>]*src=([\'"])(?P<url>[^"]+)\2',
73 webpage, 'thumbnail', fatal=False, group='url')
74
75 upload_date = unified_strdate(self._search_regex(
76 r'Le\s*<b>([\d/]+)', webpage, 'upload date', fatal=False))
77 duration = settings.get('main', {}).get('duration')
78 view_count = int_or_none(self._search_regex(
79 r'(\d+) vues', webpage, 'view count', fatal=False))
80 average_rating = self._search_regex(
81 r'Note\s*:\s*(\d+(?:,\d+)?)', webpage, 'average rating', fatal=False)
82 if average_rating:
83 average_rating = float_or_none(average_rating.replace(',', '.'))
84
85 categories = self._html_search_regex(
86 r'(?s)Catégories\s*:\s*<b>(.+?)</b>', webpage, 'categories', fatal=False)
87 if categories:
88 categories = [category.strip() for category in categories.split(',')]
89
90 subtitles = {'fr': [{
91 'url': subtitle,
92 } for subtitle in settings.get('main', {}).get('vtt_tracks', {}).values()]}
93
94 return {
95 'id': video_id,
96 'display_id': display_id,
97 'formats': formats,
98 'title': title,
99 'description': description,
100 'thumbnail': thumbnail,
101 'upload_date': upload_date,
102 'duration': duration,
103 'view_count': view_count,
104 'average_rating': average_rating,
105 'categories': categories,
106 'age_limit': 18,
107 'subtitles': subtitles,
108 }