2022-03-31 07:56:02 +09:00
|
|
|
|
from .common import InfoExtractor
|
|
|
|
|
import re
|
|
|
|
|
import requests
|
|
|
|
|
import urllib.parse
|
2022-04-01 07:09:52 +09:00
|
|
|
|
from ..utils import clean_html
|
2022-03-31 07:56:02 +09:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class WikimediaIE(InfoExtractor):
|
|
|
|
|
_NETRC_MACHINE = 'wikimediaorg'
|
|
|
|
|
IE_NAME = 'wikimedia.org'
|
|
|
|
|
_API_BASE_URL = 'https://commons.wikimedia.org/'
|
|
|
|
|
_VALID_URL = r'https://commons.wikimedia.org/wiki/File:(?P<id>[^/]+)'
|
|
|
|
|
|
2022-03-31 19:19:00 +09:00
|
|
|
|
_TEST = {
|
|
|
|
|
'url': 'https://upload.wikimedia.org/wikipedia/commons/transcoded/d/d7/Die_Temperaturkurve_der_Erde_%28ZDF'
|
|
|
|
|
'%2C_Terra_X%29_720p_HD_50FPS.webm/Die_Temperaturkurve_der_Erde_%28ZDF%2C_Terra_X%29_720p_HD_50FPS'
|
|
|
|
|
'.webm.480p.vp9.webm',
|
2022-04-01 07:09:52 +09:00
|
|
|
|
'description': 'Deutsch: Beschreibung auf der Seite: "Im Verlauf der Erdgeschichte glich das Klima einer '
|
|
|
|
|
'Achterbahnfahrt. Die „Fieberkurve“ unseres Planeten zeigt die globalen Temperaturschwankungen '
|
|
|
|
|
'bis heute – rekonstruiert anhand von historischen Klimadaten."\nZu Wikimedia Commons '
|
|
|
|
|
'hochgeladen von: PantheraLeo1359531.\nHinweise zur Weiterverwendung: '
|
|
|
|
|
'https://www.zdf.de/dokumentation/terra-x/terra-x-creative-commons-cc-100.html'
|
|
|
|
|
'.\nVereinfachender Verlauf in der Geschichte der Erde, für die Zukunft spätestens ab dem Jahr '
|
|
|
|
|
'2050 mit spekulativem Verlauf in der Prognose (ausgeprägtes Global-warming-Szenario ist '
|
|
|
|
|
'dargestellt).English: Climate change, Temperature in history of Earth, Video of Terra X.',
|
2022-03-31 19:19:00 +09:00
|
|
|
|
'ext': 'webm', 'id': 'Die_Temperaturkurve_der_Erde_(ZDF,_Terra_X)_720p_HD_50FPS.webm',
|
2022-04-01 07:09:52 +09:00
|
|
|
|
'title': 'File:Die Temperaturkurve der Erde (ZDF, Terra X) 720p HD 50FPS.webm - Wikimedia Commons',
|
|
|
|
|
'license': 'This file is licensed under the Creative Commons Attribution 4.0 International license.',
|
|
|
|
|
'author': 'ZDF/Terra X/Gruppe 5/Luise Wagner, Jonas Sichert, Andreas Hougardy'}
|
2022-03-31 19:19:00 +09:00
|
|
|
|
|
2022-03-31 07:56:02 +09:00
|
|
|
|
def _real_extract(self, url):
|
|
|
|
|
mobj = re.match(self._VALID_URL, url)
|
|
|
|
|
video_id = mobj.group('id')
|
|
|
|
|
|
2022-04-01 07:09:52 +09:00
|
|
|
|
if not video_id.endswith('.webm'):
|
|
|
|
|
raise Exception("invalid video url")
|
|
|
|
|
|
2022-03-31 07:56:02 +09:00
|
|
|
|
webpage = self._download_webpage(url, video_id)
|
|
|
|
|
self.report_extraction(video_id)
|
|
|
|
|
video_url = self._html_search_regex(r'<source [^>]*src="([^"]+)"', webpage,
|
|
|
|
|
u'video URL')
|
2022-03-31 19:19:00 +09:00
|
|
|
|
licenze = self._html_search_regex(f"(?<=td>This)(.*)(?=license.)", webpage, u'video license')
|
|
|
|
|
licenze = "This " + licenze + " license."
|
2022-04-01 07:09:52 +09:00
|
|
|
|
|
|
|
|
|
description = self._html_search_regex(f'(?<=<div class="description mw-content-ltr de" dir="ltr" lang="de">)('
|
|
|
|
|
f'.*)(?=</div>)', webpage,
|
|
|
|
|
u'video description')
|
|
|
|
|
|
|
|
|
|
author = re.search(r'<td>([^\<]*?)<\/td>', str(webpage))
|
|
|
|
|
author = clean_html(author.group(0))
|
2022-03-31 07:56:02 +09:00
|
|
|
|
resp = {}
|
|
|
|
|
|
|
|
|
|
subtitle_url = f'https://commons.wikimedia.org/w/api.php?' \
|
|
|
|
|
f'action=timedtext&lang=nl&title=File%3A{urllib.parse.quote(video_id)}&trackformat=srt'
|
2022-03-31 19:21:38 +09:00
|
|
|
|
|
|
|
|
|
subtitles = requests.post(subtitle_url).text
|
|
|
|
|
if 'timedtext-notfound' not in subtitles:
|
|
|
|
|
with open(video_id + '.srt', 'w+', encoding='utf') as f:
|
2022-03-31 07:56:02 +09:00
|
|
|
|
f.write(subtitles)
|
2022-03-31 19:21:38 +09:00
|
|
|
|
else:
|
|
|
|
|
print("subtitles not found")
|
|
|
|
|
|
2022-03-31 07:56:02 +09:00
|
|
|
|
resp['url'] = video_url
|
2022-04-01 07:09:52 +09:00
|
|
|
|
resp['description'] = description
|
2022-03-31 07:56:02 +09:00
|
|
|
|
resp['ext'] = 'webm'
|
|
|
|
|
resp['id'] = video_id
|
2022-04-01 07:09:52 +09:00
|
|
|
|
resp['title'] = self._og_search_title(webpage)
|
2022-03-31 19:19:00 +09:00
|
|
|
|
resp['license'] = licenze
|
2022-04-01 07:09:52 +09:00
|
|
|
|
resp['author'] = author
|
2022-03-31 07:56:02 +09:00
|
|
|
|
return [resp]
|