More refactoring for PietsmietIE

This commit is contained in:
Martin Hartkorn 2018-07-08 15:30:46 +02:00
parent f2c7a7f1b1
commit 97f828ce1e

View File

@ -16,7 +16,7 @@ from ..utils import (
class PietsmietIE(InfoExtractor): class PietsmietIE(InfoExtractor):
_VALID_URL = r'https?://(?:www\.)?pietsmiet\.de/gallery/(categories|playlists)/[\w-]+/(?P<id>\d+)-.*/?' _VALID_URL = r'https?://(?:www\.)?pietsmiet\.de/gallery/(categories|playlists)/[\w-]+/(?P<id>\d+)-'
_TESTS = [ _TESTS = [
{ {
'url': 'https://www.pietsmiet.de/gallery/categories/8-frag-pietsmiet/29844-fps-912', 'url': 'https://www.pietsmiet.de/gallery/categories/8-frag-pietsmiet/29844-fps-912',
@ -49,25 +49,27 @@ class PietsmietIE(InfoExtractor):
data_video_config = data_video_config.replace(']', '],', 1) + '}' data_video_config = data_video_config.replace(']', '],', 1) + '}'
data_video = self._parse_json(js_to_json(unescapeHTML(data_video_config)), page_id) data_video = self._parse_json(js_to_json(unescapeHTML(data_video_config)), page_id)
title = compat_urllib_parse_unquote(data_video['abouttext'])
formats = [] formats = []
m3u8_manifest_urls = filter(lambda x: x['file'].endswith('m3u8'), data_video['sources']) for src in data_video['sources']:
for f in m3u8_manifest_urls: if src['file'].endswith('m3u8'):
# HLS format
m3u8_formats = self._extract_m3u8_formats( m3u8_formats = self._extract_m3u8_formats(
f['file'], page_id, 'mp4', 'm3u8_native', m3u8_id='hls') src['file'], page_id, 'mp4', 'm3u8_native', m3u8_id='hls')
formats.extend(m3u8_formats) formats.extend(m3u8_formats)
else:
mp4_urls = filter(lambda x: not x['file'].endswith('m3u8'), data_video['sources']) # Standard mp4
for m in mp4_urls: label = src.get('label')
label = m.get('label')
format_height = 0 format_height = 0
if label: if label:
# Calculate resolution for HTTP format but should always be 1280x720 # Calculate resolution for HTTP format. Should always be 1280x720
# for newer videos but older videos don't have HLS for all resolutions
format_height_raw = self._search_regex( format_height_raw = self._search_regex(
'([0-9]+)p', label, 'http video height', '([0-9]+)p', label, 'http video height',
default=720, fatal=False) default=720)
format_height = int_or_none(format_height_raw) format_height = int_or_none(format_height_raw)
if format_height > 0: if format_height > 0:
@ -75,16 +77,16 @@ class PietsmietIE(InfoExtractor):
formats.append({ formats.append({
'format_id': 'http-{0}'.format(label), 'format_id': 'http-{0}'.format(label),
'url': "https:{0}".format(m['file']), 'url': "https:{0}".format(src['file']),
'ext': m.get('type'), 'ext': src.get('type'),
'width': int_or_none(format_width), 'width': int_or_none(format_width),
'height': format_height, 'height': format_height,
'fps': 30.0, 'fps': 30.0,
}) })
else: else:
formats.append({ formats.append({
'url': "https:{0}".format(m['file']), 'url': 'https:{0}'.format(src['file']),
'ext': m.get('type'), 'ext': src.get('type'),
'fps': 30.0, 'fps': 30.0,
}) })
@ -93,7 +95,7 @@ class PietsmietIE(InfoExtractor):
return { return {
'id': page_id, 'id': page_id,
'display_id': page_id, 'display_id': page_id,
'title': compat_urllib_parse_unquote(data_video['abouttext']), 'title': title,
'formats': formats, 'formats': formats,
'thumbnail': 'http://www.pietsmiet.de/{0}'.format(data_video.get('image')), 'thumbnail': 'http://www.pietsmiet.de/{0}'.format(data_video.get('image')),
} }