]> jfr.im git - yt-dlp.git/blame - youtube_dl/extractor/pornovoisines.py
[pornovoisines] Add extractor
[yt-dlp.git] / youtube_dl / extractor / pornovoisines.py
CommitLineData
575dad3c
RLN
1# coding: utf-8
2from __future__ import unicode_literals
3
4import re
5import datetime
6import random
7
8from ..compat import compat_urllib_parse
9from .common import InfoExtractor
10
11class PornoVoisinesIE(InfoExtractor):
12 _VALID_URL = r'^((?:http://)?(?:www\.)?pornovoisines.com)/showvideo/(\d+)/([^/]+)'
13
14 VIDEO_URL_TEMPLATE = 'http://stream%d.pornovoisines.com' \
15 '/static/media/video/transcoded/%s-640x360-1000-trscded.mp4'
16
17 SERVER_NUMBERS = (1, 2)
18
19 _TEST = {
20 'url': 'http://www.pornovoisines.com/showvideo/1285/recherche-appartement/',
21 'md5': '5ac670803bc12e9e7f9f662ce64cf1d1',
22 'info_dict': {
23 'id': '1285',
24 'display_id': 'recherche-appartement',
25 'ext': 'mp4',
26 'title': "Recherche appartement",
27 'upload_date': '20140925',
28 'view_count': int,
29 'duration': 120,
30 'categories': ["Débutante", "Scénario", "Sodomie"],
31 'description': 're:^Pour la .+ original...$',
32 'thumbnail': 're:^http://',
33 'uploader': "JMTV",
34 'average_rating': float,
35 'comment_count': int,
36 'age_limit': 18,
37 }
38 }
39
40 @classmethod
41 def build_video_url(cls, id):
42 server_nr = random.choice(cls.SERVER_NUMBERS)
43 return cls.VIDEO_URL_TEMPLATE % (server_nr, id)
44
45 @staticmethod
46 def parse_upload_date(str):
47 return datetime.datetime.strptime(str, "%d-%m-%Y").strftime("%Y%m%d")
48
49 @staticmethod
50 def parse_categories(str):
51 return map(lambda s: s.strip(), str.split(','))
52
53 def _real_extract(self, url):
54 mobj = re.match(self._VALID_URL, url)
55 url_prefix = mobj.group(1)
56 id = mobj.group(2)
57 display_id = mobj.group(3)
58
59 webpage = self._download_webpage(url, id)
60
61 title = self._html_search_regex(r'<h1>(.+?)</h1>', webpage, 'title',
62 flags=re.DOTALL)
63 url = self.build_video_url(id)
64 upload_date = self.parse_upload_date(
65 self._search_regex(r'Publié le (\d\d-\d\d-\d{4})', webpage,
66 'upload date'))
67 view_count = int(self._search_regex(r'(\d+) vues', webpage, 'view count'))
68 duration = int(self._search_regex('Durée (\d+)', webpage, 'duration'))
69 categories = self.parse_categories(self._html_search_regex(
70 r'<li class="categorie">(.+?)</li>', webpage, "categories",
71 flags=re.DOTALL))
72 description = self._html_search_regex(
73 r'<article id="descriptif">(.+?)</article>', webpage, "description",
74 flags=re.DOTALL)
75 thumbnail = url_prefix + self._html_search_regex(re.compile(
76 '<div id="mediaspace' + id + '">.*?<img src="(.+?)"', re.DOTALL),
77 webpage, "thumbnail")
78 uploader = re.sub(r' *\| *$', '',
79 self._html_search_regex(r'<li class="auteur">(.+?)</li>', webpage,
80 "uploader", flags=re.DOTALL))
81 average_rating = float(self._search_regex(r'Note : (\d+,\d+)',
82 webpage, "average rating").replace(',', '.'))
83 comment_count = int(self._search_regex(r'\((\d+)\)', webpage,
84 "comment count"))
85
86 return {
87 'id': id,
88 'display_id': display_id,
89 'url': url,
90 'title': title,
91 'upload_date': upload_date,
92 'view_count': view_count,
93 'duration': duration,
94 'categories': categories,
95 'description': description,
96 'thumbnail': thumbnail,
97 'uploader': uploader,
98 'average_rating': average_rating,
99 'comment_count': comment_count,
100 'age_limit': 18,
101 }