[yourporn] Fix extraction and extract duration (closes #18815, closes #18852)
[youtube-dl] / youtube_dl / extractor / yourporn.py
1 from __future__ import unicode_literals
2
3 from .common import InfoExtractor
4 from ..utils import (
5     parse_duration,
6     urljoin
7 )
8
9
10 class YourPornIE(InfoExtractor):
11     _VALID_URL = r'https?://(?:www\.)?yourporn\.sexy/post/(?P<id>[^/?#&.]+)'
12     _TEST = {
13         'url': 'https://yourporn.sexy/post/57ffcb2e1179b.html',
14         'md5': '6f8682b6464033d87acaa7a8ff0c092e',
15         'info_dict': {
16             'id': '57ffcb2e1179b',
17             'ext': 'mp4',
18             'title': 'md5:c9f43630bd968267672651ba905a7d35',
19             'thumbnail': r're:^https?://.*\.jpg$',
20             'age_limit': 18
21         },
22     }
23
24     def _real_extract(self, url):
25         video_id = self._match_id(url)
26
27         webpage = self._download_webpage(url, video_id)
28
29         video_url = urljoin(url, self._parse_json(
30             self._search_regex(
31                 r'data-vnfo=(["\'])(?P<data>{.+?})\1', webpage, 'data info',
32                 group='data'),
33             video_id)[video_id]).replace('/cdn/', '/cdn4/')
34
35         title = (self._search_regex(
36             r'<[^>]+\bclass=["\']PostEditTA[^>]+>([^<]+)', webpage, 'title',
37             default=None) or self._og_search_description(webpage)).strip()
38
39         thumbnail = self._og_search_thumbnail(webpage)
40
41         duration = parse_duration(self._search_regex(r'duration:[^0-9]*([0-9:]+)',
42                                                      webpage, 'duration', default=None))
43         return {
44             'id': video_id,
45             'url': video_url,
46             'title': title,
47             'duration': duration,
48             'thumbnail': thumbnail,
49             'age_limit': 18
50         }