1
0
mirror of https://github.com/l1ving/youtube-dl synced 2024-11-22 12:02:57 +08:00
youtube-dl/youtube_dl/extractor/pornovoisines.py

97 lines
3.3 KiB
Python
Raw Normal View History

2015-03-23 03:25:44 +08:00
# coding: utf-8
from __future__ import unicode_literals
import re
import random
from .common import InfoExtractor
2015-04-04 21:13:37 +08:00
from ..utils import (
int_or_none,
float_or_none,
unified_strdate,
)
2015-03-23 03:25:44 +08:00
class PornoVoisinesIE(InfoExtractor):
2015-04-04 21:13:37 +08:00
_VALID_URL = r'http://(?:www\.)?pornovoisines\.com/showvideo/(?P<id>\d+)/(?P<display_id>[^/]+)'
2015-03-23 03:25:44 +08:00
2015-04-04 21:13:37 +08:00
_VIDEO_URL_TEMPLATE = 'http://stream%d.pornovoisines.com' \
2015-03-23 03:25:44 +08:00
'/static/media/video/transcoded/%s-640x360-1000-trscded.mp4'
2015-04-04 21:13:37 +08:00
_SERVER_NUMBERS = (1, 2)
2015-03-23 03:25:44 +08:00
_TEST = {
'url': 'http://www.pornovoisines.com/showvideo/1285/recherche-appartement/',
'md5': '5ac670803bc12e9e7f9f662ce64cf1d1',
'info_dict': {
'id': '1285',
'display_id': 'recherche-appartement',
'ext': 'mp4',
2015-04-04 21:13:37 +08:00
'title': 'Recherche appartement',
'description': 'md5:819ea0b785e2a04667a1a01cdc89594e',
'thumbnail': 're:^https?://.*\.jpg$',
2015-03-23 03:25:44 +08:00
'upload_date': '20140925',
'duration': 120,
2015-04-04 21:13:37 +08:00
'view_count': int,
2015-03-23 03:25:44 +08:00
'average_rating': float,
'categories': ['Débutantes', 'Scénario', 'Sodomie'],
2015-03-23 03:25:44 +08:00
'age_limit': 18,
}
}
@classmethod
2015-04-04 21:13:37 +08:00
def build_video_url(cls, num):
return cls._VIDEO_URL_TEMPLATE % (random.choice(cls._SERVER_NUMBERS), num)
2015-03-23 03:25:44 +08:00
def _real_extract(self, url):
mobj = re.match(self._VALID_URL, url)
2015-04-04 21:13:37 +08:00
video_id = mobj.group('id')
display_id = mobj.group('display_id')
webpage = self._download_webpage(url, video_id)
video_url = self.build_video_url(video_id)
title = self._html_search_regex(
r'<h1>(.+?)</h1>', webpage, 'title', flags=re.DOTALL)
2015-03-23 03:25:44 +08:00
description = self._html_search_regex(
2015-04-04 21:13:37 +08:00
r'<article id="descriptif">(.+?)</article>',
webpage, "description", fatal=False, flags=re.DOTALL)
thumbnail = self._search_regex(
r'<div id="mediaspace%s">\s*<img src="/?([^"]+)"' % video_id,
webpage, 'thumbnail', fatal=False)
if thumbnail:
thumbnail = 'http://www.pornovoisines.com/%s' % thumbnail
upload_date = unified_strdate(self._search_regex(
r'Publié le ([\d-]+)', webpage, 'upload date', fatal=False))
duration = int_or_none(self._search_regex(
'Durée (\d+)', webpage, 'duration', fatal=False))
view_count = int_or_none(self._search_regex(
r'(\d+) vues', webpage, 'view count', fatal=False))
average_rating = self._search_regex(
r'Note\s*:\s*(\d+(?:,\d+)?)', webpage, 'average rating', fatal=False)
2015-04-04 21:13:37 +08:00
if average_rating:
average_rating = float_or_none(average_rating.replace(',', '.'))
categories = self._html_search_meta(
'keywords', webpage, 'categories', fatal=False)
if categories:
categories = [category.strip() for category in categories.split(',')]
2015-03-23 03:25:44 +08:00
return {
2015-04-04 21:13:37 +08:00
'id': video_id,
2015-03-23 03:25:44 +08:00
'display_id': display_id,
2015-04-04 21:13:37 +08:00
'url': video_url,
2015-03-23 03:25:44 +08:00
'title': title,
'description': description,
'thumbnail': thumbnail,
2015-04-04 21:13:37 +08:00
'upload_date': upload_date,
'duration': duration,
'view_count': view_count,
2015-03-23 03:25:44 +08:00
'average_rating': average_rating,
2015-04-04 21:13:37 +08:00
'categories': categories,
2015-03-23 03:25:44 +08:00
'age_limit': 18,
}