2018-10-09 19:50:49 +02:00
|
|
|
from __future__ import unicode_literals
|
|
|
|
|
|
|
|
import re
|
|
|
|
|
|
|
|
from .common import InfoExtractor
|
|
|
|
|
2019-03-14 12:24:19 +01:00
|
|
|
from ..utils import (
|
|
|
|
remove_end,
|
|
|
|
int_or_none
|
|
|
|
)
|
|
|
|
|
|
|
|
|
2018-10-09 19:50:49 +02:00
|
|
|
class WeltIE(InfoExtractor):
|
|
|
|
IE_NAME = 'welt.de'
|
2019-03-14 12:24:19 +01:00
|
|
|
_VALID_URL = r'''https?://(?:www\.)?welt\.de/[^\.]+/(?P<id>[a-z]+\d+)(?:/.*)?'''
|
2018-10-09 19:50:49 +02:00
|
|
|
_TESTS = [
|
|
|
|
{
|
2019-03-14 12:24:19 +01:00
|
|
|
# All videos have a predefined lifetime, usually just 30-45 days
|
|
|
|
'url': 'https://www.welt.de/mediathek/dokumentation/natur-und-wildlife/sendung157940018/Mega-Croc-vs-Superschlange.html',
|
2018-10-09 19:50:49 +02:00
|
|
|
'info_dict': {
|
2019-03-14 12:24:19 +01:00
|
|
|
'id': 'sendung157940018',
|
2018-10-09 19:50:49 +02:00
|
|
|
'ext': 'mp4',
|
2019-03-14 12:24:19 +01:00
|
|
|
'title': 'Mega Croc vs. Superschlange',
|
2018-10-09 19:50:49 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
]
|
|
|
|
|
|
|
|
def _real_extract(self, url):
|
|
|
|
video_id = self._match_id(url)
|
|
|
|
webpage = self._download_webpage(url, video_id)
|
2019-03-14 12:24:19 +01:00
|
|
|
title = remove_end(self._html_search_regex(r'<title>([^<]+)</title>', webpage, 'title')
|
|
|
|
.strip(), ' - Video - WELT')
|
|
|
|
|
|
|
|
sources = self._search_regex(r'(["\'])?sources\1\s*:\s*\[({\s*\1file\1\s*:\s*\1([^\1,])+\1\s*}\s*,?)+', webpage, 'sources', group=0)
|
|
|
|
files = re.findall(r'http[^\'"]+', sources)
|
2018-10-09 19:50:49 +02:00
|
|
|
|
2019-03-14 12:24:19 +01:00
|
|
|
formats = []
|
|
|
|
for url in files:
|
|
|
|
number = re.search(r'_(\d+)\.mp4', url).group(1)
|
|
|
|
formats.append({
|
|
|
|
'url': url,
|
|
|
|
'quality_key': int_or_none(number)
|
|
|
|
})
|
|
|
|
self._remove_duplicate_formats(formats)
|
|
|
|
formats = sorted(formats, key=lambda x: x['quality_key'])
|
|
|
|
quality_counter = -1
|
|
|
|
for i in range(len(formats) - 1, 0, -1):
|
|
|
|
formats[i] = {'url': formats[i]['url'], 'quality': quality_counter}
|
|
|
|
quality_counter -= 1
|
|
|
|
|
|
|
|
return {
|
|
|
|
'id': video_id,
|
|
|
|
'ext': 'mp4',
|
2018-10-09 19:50:49 +02:00
|
|
|
'title': title,
|
2019-03-14 12:24:19 +01:00
|
|
|
'formats': formats
|
|
|
|
}
|