1
0
mirror of https://github.com/ytdl-org/youtube-dl.git synced 2024-12-15 09:11:22 +01:00
youtube-dl/youtube_dl/extractor/promptfile.py

71 lines
2.4 KiB
Python
Raw Normal View History

2014-08-28 23:20:10 +02:00
# coding: utf-8
from __future__ import unicode_literals
import re
from .common import InfoExtractor
from ..utils import (
determine_ext,
ExtractorError,
urlencode_postdata,
)
2014-08-28 23:20:10 +02:00
class PromptFileIE(InfoExtractor):
_VALID_URL = r'https?://(?:www\.)?promptfile\.com/l/(?P<id>[0-9A-Z\-]+)'
_TEST = {
'url': 'http://www.promptfile.com/l/86D1CE8462-576CAAE416',
'md5': '5a7e285a26e0d66d9a263fae91bc92ce',
2014-08-28 23:20:10 +02:00
'info_dict': {
'id': '86D1CE8462-576CAAE416',
2014-08-28 23:20:10 +02:00
'ext': 'mp4',
'title': 'oceans.mp4',
'thumbnail': r're:^https?://.*\.jpg$',
2014-08-28 23:20:10 +02:00
}
}
def _real_extract(self, url):
video_id = self._match_id(url)
2014-08-28 23:20:10 +02:00
webpage = self._download_webpage(url, video_id)
if re.search(r'<div.+id="not_found_msg".+>(?!We are).+</div>[^-]', webpage) is not None:
2014-08-28 23:20:10 +02:00
raise ExtractorError('Video %s does not exist' % video_id,
expected=True)
2016-09-26 18:39:54 +02:00
chash = self._search_regex(
r'val\("([^"]*)"\s*\+\s*\$\("#chash"\)', webpage, 'chash')
fields = self._hidden_inputs(webpage)
2016-09-26 18:39:54 +02:00
keys = list(fields.keys())
chash_key = keys[0] if len(keys) == 1 else next(
key for key in keys if key.startswith('cha'))
fields[chash_key] = chash + fields[chash_key]
2014-08-28 23:20:10 +02:00
webpage = self._download_webpage(
2016-09-26 18:39:54 +02:00
url, video_id, 'Downloading video page',
data=urlencode_postdata(fields),
headers={'Content-type': 'application/x-www-form-urlencoded'})
2014-08-28 23:20:10 +02:00
2016-09-26 18:39:54 +02:00
video_url = self._search_regex(
(r'<a[^>]+href=(["\'])(?P<url>(?:(?!\1).)+)\1[^>]*>\s*Download File',
r'<a[^>]+href=(["\'])(?P<url>https?://(?:www\.)?promptfile\.com/file/(?:(?!\1).)+)\1'),
webpage, 'video url', group='url')
2014-08-28 23:20:10 +02:00
title = self._html_search_regex(
r'<span.+title="([^"]+)">', webpage, 'title')
thumbnail = self._html_search_regex(
r'<div id="player_overlay">.*button>.*?<img src="([^"]+)"',
webpage, 'thumbnail', fatal=False, flags=re.DOTALL)
formats = [{
'format_id': 'sd',
2016-09-26 18:39:54 +02:00
'url': video_url,
2014-08-28 23:20:10 +02:00
'ext': determine_ext(title),
}]
self._sort_formats(formats)
2014-08-28 23:20:10 +02:00
return {
'id': video_id,
'title': title,
'thumbnail': thumbnail,
'formats': formats,
}