]> git.bitcoin.ninja Git - youtube-dl/blob - youtube_dl/extractor/clippit.py
[pornhub] Improve locked videos detection (closes #22449, closes #22780)
[youtube-dl] / youtube_dl / extractor / clippit.py
1 # coding: utf-8
2
3 from __future__ import unicode_literals
4
5 from .common import InfoExtractor
6 from ..utils import (
7     parse_iso8601,
8     qualities,
9 )
10
11 import re
12
13
14 class ClippitIE(InfoExtractor):
15
16     _VALID_URL = r'https?://(?:www\.)?clippituser\.tv/c/(?P<id>[a-z]+)'
17     _TEST = {
18         'url': 'https://www.clippituser.tv/c/evmgm',
19         'md5': '963ae7a59a2ec4572ab8bf2f2d2c5f09',
20         'info_dict': {
21             'id': 'evmgm',
22             'ext': 'mp4',
23             'title': 'Bye bye Brutus. #BattleBots  - Clippit',
24             'uploader': 'lizllove',
25             'uploader_url': 'https://www.clippituser.tv/p/lizllove',
26             'timestamp': 1472183818,
27             'upload_date': '20160826',
28             'description': 'BattleBots | ABC',
29             'thumbnail': r're:^https?://.*\.jpg$',
30         }
31     }
32
33     def _real_extract(self, url):
34         video_id = self._match_id(url)
35         webpage = self._download_webpage(url, video_id)
36
37         title = self._html_search_regex(r'<title.*>(.+?)</title>', webpage, 'title')
38
39         FORMATS = ('sd', 'hd')
40         quality = qualities(FORMATS)
41         formats = []
42         for format_id in FORMATS:
43             url = self._html_search_regex(r'data-%s-file="(.+?)"' % format_id,
44                                           webpage, 'url', fatal=False)
45             if not url:
46                 continue
47             match = re.search(r'/(?P<height>\d+)\.mp4', url)
48             formats.append({
49                 'url': url,
50                 'format_id': format_id,
51                 'quality': quality(format_id),
52                 'height': int(match.group('height')) if match else None,
53             })
54
55         uploader = self._html_search_regex(r'class="username".*>\s+(.+?)\n',
56                                            webpage, 'uploader', fatal=False)
57         uploader_url = ('https://www.clippituser.tv/p/' + uploader
58                         if uploader else None)
59
60         timestamp = self._html_search_regex(r'datetime="(.+?)"',
61                                             webpage, 'date', fatal=False)
62         thumbnail = self._html_search_regex(r'data-image="(.+?)"',
63                                             webpage, 'thumbnail', fatal=False)
64
65         return {
66             'id': video_id,
67             'title': title,
68             'formats': formats,
69             'uploader': uploader,
70             'uploader_url': uploader_url,
71             'timestamp': parse_iso8601(timestamp),
72             'description': self._og_search_description(webpage),
73             'thumbnail': thumbnail,
74         }