]> Raphaël G. Git Repositories - youtubedl/blob - youtube_dl/extractor/pornovoisines.py
9688ed94898de231e6c7f1c9dc28d3779da10311
[youtubedl] / youtube_dl / extractor / pornovoisines.py
1 # coding: utf-8
2 from __future__ import unicode_literals
3
4 import re
5 import random
6
7 from .common import InfoExtractor
8 from ..utils import (
9 int_or_none,
10 float_or_none,
11 unified_strdate,
12 )
13
14
15 class PornoVoisinesIE(InfoExtractor):
16 _VALID_URL = r'http://(?:www\.)?pornovoisines\.com/showvideo/(?P<id>\d+)/(?P<display_id>[^/]+)'
17
18 _VIDEO_URL_TEMPLATE = 'http://stream%d.pornovoisines.com' \
19 '/static/media/video/transcoded/%s-640x360-1000-trscded.mp4'
20
21 _SERVER_NUMBERS = (1, 2)
22
23 _TEST = {
24 'url': 'http://www.pornovoisines.com/showvideo/1285/recherche-appartement/',
25 'md5': '5ac670803bc12e9e7f9f662ce64cf1d1',
26 'info_dict': {
27 'id': '1285',
28 'display_id': 'recherche-appartement',
29 'ext': 'mp4',
30 'title': 'Recherche appartement',
31 'description': 'md5:819ea0b785e2a04667a1a01cdc89594e',
32 'thumbnail': 're:^https?://.*\.jpg$',
33 'upload_date': '20140925',
34 'duration': 120,
35 'view_count': int,
36 'average_rating': float,
37 'categories': ['Débutante', 'Scénario', 'Sodomie'],
38 'age_limit': 18,
39 }
40 }
41
42 @classmethod
43 def build_video_url(cls, num):
44 return cls._VIDEO_URL_TEMPLATE % (random.choice(cls._SERVER_NUMBERS), num)
45
46 def _real_extract(self, url):
47 mobj = re.match(self._VALID_URL, url)
48 video_id = mobj.group('id')
49 display_id = mobj.group('display_id')
50
51 webpage = self._download_webpage(url, video_id)
52
53 video_url = self.build_video_url(video_id)
54
55 title = self._html_search_regex(
56 r'<h1>(.+?)</h1>', webpage, 'title', flags=re.DOTALL)
57 description = self._html_search_regex(
58 r'<article id="descriptif">(.+?)</article>',
59 webpage, "description", fatal=False, flags=re.DOTALL)
60
61 thumbnail = self._search_regex(
62 r'<div id="mediaspace%s">\s*<img src="/?([^"]+)"' % video_id,
63 webpage, 'thumbnail', fatal=False)
64 if thumbnail:
65 thumbnail = 'http://www.pornovoisines.com/%s' % thumbnail
66
67 upload_date = unified_strdate(self._search_regex(
68 r'Publié le ([\d-]+)', webpage, 'upload date', fatal=False))
69 duration = int_or_none(self._search_regex(
70 'Durée (\d+)', webpage, 'duration', fatal=False))
71 view_count = int_or_none(self._search_regex(
72 r'(\d+) vues', webpage, 'view count', fatal=False))
73 average_rating = self._search_regex(
74 r'Note : (\d+,\d+)', webpage, 'average rating', fatal=False)
75 if average_rating:
76 average_rating = float_or_none(average_rating.replace(',', '.'))
77
78 categories = self._html_search_meta(
79 'keywords', webpage, 'categories', fatal=False)
80 if categories:
81 categories = [category.strip() for category in categories.split(',')]
82
83 return {
84 'id': video_id,
85 'display_id': display_id,
86 'url': video_url,
87 'title': title,
88 'description': description,
89 'thumbnail': thumbnail,
90 'upload_date': upload_date,
91 'duration': duration,
92 'view_count': view_count,
93 'average_rating': average_rating,
94 'categories': categories,
95 'age_limit': 18,
96 }