]> Raphaƫl G. Git Repositories - youtubedl/blob - youtube_dl/extractor/promptfile.py
debian/{compat,control}: Update to debhelper compatibility level 12.
[youtubedl] / youtube_dl / extractor / promptfile.py
1 # coding: utf-8
2 from __future__ import unicode_literals
3
4 import re
5
6 from .common import InfoExtractor
7 from ..utils import (
8 determine_ext,
9 ExtractorError,
10 urlencode_postdata,
11 )
12
13
14 class PromptFileIE(InfoExtractor):
15 _VALID_URL = r'https?://(?:www\.)?promptfile\.com/l/(?P<id>[0-9A-Z\-]+)'
16 _TEST = {
17 'url': 'http://www.promptfile.com/l/86D1CE8462-576CAAE416',
18 'md5': '5a7e285a26e0d66d9a263fae91bc92ce',
19 'info_dict': {
20 'id': '86D1CE8462-576CAAE416',
21 'ext': 'mp4',
22 'title': 'oceans.mp4',
23 'thumbnail': r're:^https?://.*\.jpg$',
24 }
25 }
26
27 def _real_extract(self, url):
28 video_id = self._match_id(url)
29 webpage = self._download_webpage(url, video_id)
30
31 if re.search(r'<div.+id="not_found_msg".+>(?!We are).+</div>[^-]', webpage) is not None:
32 raise ExtractorError('Video %s does not exist' % video_id,
33 expected=True)
34
35 chash = self._search_regex(
36 r'val\("([^"]*)"\s*\+\s*\$\("#chash"\)', webpage, 'chash')
37 fields = self._hidden_inputs(webpage)
38 keys = list(fields.keys())
39 chash_key = keys[0] if len(keys) == 1 else next(
40 key for key in keys if key.startswith('cha'))
41 fields[chash_key] = chash + fields[chash_key]
42
43 webpage = self._download_webpage(
44 url, video_id, 'Downloading video page',
45 data=urlencode_postdata(fields),
46 headers={'Content-type': 'application/x-www-form-urlencoded'})
47
48 video_url = self._search_regex(
49 (r'<a[^>]+href=(["\'])(?P<url>(?:(?!\1).)+)\1[^>]*>\s*Download File',
50 r'<a[^>]+href=(["\'])(?P<url>https?://(?:www\.)?promptfile\.com/file/(?:(?!\1).)+)\1'),
51 webpage, 'video url', group='url')
52 title = self._html_search_regex(
53 r'<span.+title="([^"]+)">', webpage, 'title')
54 thumbnail = self._html_search_regex(
55 r'<div id="player_overlay">.*button>.*?<img src="([^"]+)"',
56 webpage, 'thumbnail', fatal=False, flags=re.DOTALL)
57
58 formats = [{
59 'format_id': 'sd',
60 'url': video_url,
61 'ext': determine_ext(title),
62 }]
63 self._sort_formats(formats)
64
65 return {
66 'id': video_id,
67 'title': title,
68 'thumbnail': thumbnail,
69 'formats': formats,
70 }