[pornhd] Improve formats extraction

This commit is contained in:
Sergey M․ 2016-06-18 05:37:53 +07:00
parent d0d93f76ea
commit e6fe993c31
No known key found for this signature in database
GPG key ID: 2C393E0F18A9236D

View file

@ -7,7 +7,6 @@ from .common import InfoExtractor
from ..utils import ( from ..utils import (
int_or_none, int_or_none,
js_to_json, js_to_json,
qualities,
) )
@ -46,18 +45,19 @@ class PornHdIE(InfoExtractor):
thumbnail = self._search_regex( thumbnail = self._search_regex(
r"'poster'\s*:\s*'([^']+)'", webpage, 'thumbnail', fatal=False) r"'poster'\s*:\s*'([^']+)'", webpage, 'thumbnail', fatal=False)
quality = qualities(['sd', 'hd'])
sources = json.loads(js_to_json(self._search_regex( sources = json.loads(js_to_json(self._search_regex(
r"(?s)'sources'\s*:\s*(\{.+?\})\s*\}[;,)]", r"(?s)'sources'\s*:\s*(\{.+?\})\s*\}[;,)]",
webpage, 'sources'))) webpage, 'sources')))
formats = [] formats = []
for qname, video_url in sources.items(): for format_id, video_url in sources.items():
if not video_url: if not video_url:
continue continue
height = int_or_none(self._search_regex(
r'^(\d+)[pP]', format_id, 'height', default=None))
formats.append({ formats.append({
'url': video_url, 'url': video_url,
'format_id': qname, 'format_id': format_id,
'quality': quality(qname), 'height': height,
}) })
self._sort_formats(formats) self._sort_formats(formats)