fixed issues.

This commit is contained in:
Ehtisham Sabir 2022-05-05 07:05:38 +05:00
parent b3d2887ed8
commit 67c58034ef

View File

@ -1,70 +1,69 @@
# coding: utf-8
from __future__ import unicode_literals
from .common import InfoExtractor
from ..utils import get_element_by_class, determine_ext, clean_html, KNOWN_EXTENSIONS
import re
from ..utils import (
clean_html,
determine_ext,
get_element_by_class,
urljoin,
compat_parse_qs,
ExtractorError)
class WikimediaIE(InfoExtractor):
_NETRC_MACHINE = 'wikimediaorg'
IE_NAME = 'wikimedia.org'
_NETRC_MACHINE = 'wikimediaorg'
_API_BASE_URL = 'https://commons.wikimedia.org/'
_VALID_URL = r'https://commons.wikimedia.org/wiki/File:(?P<id>[^/]+)'
_VALID_URL = 'https://commons.wikimedia.org/wiki/File:(?P<id>[^/]+)'
_TEST = {
'url': 'https://commons.wikimedia.org/wiki/File:Die_Temperaturkurve_der_Erde_(ZDF,_Terra_X)_720p_HD_50FPS.webm',
'info_dict': {
'description': 'md5:D6F4C7BF1C0DB1EAE80371B1F93EA85E',
'ext': 'webm',
'id': 'Die_Temperaturkurve_der_Erde_(ZDF,_Terra_X)_720p_HD_50FPS',
'description': 'md5:7cd84f76e7081f1be033d0b155b4a460',
'ext': 'webm', 'id': 'Die_Temperaturkurve_der_Erde_(ZDF,_Terra_X)_720p_HD_50FPS',
'title': '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',
'subtitles': {'de': [
{'ext': 'srt',
'url': 'https://commons.wikimedia.org/w/api.php?action=timedtext&amp&title=File%3ADie_Temperaturkurve_der_Erde_%28ZDF%2C_Terra_X%29_720p_HD_50FPS.webm&amp&lang=de&amp&trackformat=srt'}],
'en-gb': [
{'ext': 'srt',
'url': 'https://commons.wikimedia.org/w/api.php?action=timedtext&amp&title=File%3ADie_Temperaturkurve_der_Erde_%28ZDF%2C_Terra_X%29_720p_HD_50FPS.webm&amp&lang=en-gb&amp&trackformat=srt'}],
'nl': [
{'ext': 'srt',
'url': 'https://commons.wikimedia.org/w/api.php?action=timedtext&amp&title=File%3ADie_Temperaturkurve_der_Erde_%28ZDF%2C_Terra_X%29_720p_HD_50FPS.webm&amp&lang=nl&amp&trackformat=srt'}
]}
}
'license': 'md5:62907cddf705a9f7ae7076c15407a977',
'author': None, 'subtitles': {'de': [{'ext': 'srt',
'url': 'https://commons.wikimedia.org/w/api.php?action=timedtext&amp;title=File%3ADie_Temperaturkurve_der_Erde_%28ZDF%2C_Terra_X%29_720p_HD_50FPS.webm&amp;lang=de&amp;trackformat=vtt '}],
'en-gb': [{'ext': 'srt',
'url': 'https://commons.wikimedia.org/w/api.php?action=timedtext&amp;title=File%3ADie_Temperaturkurve_der_Erde_%28ZDF%2C_Terra_X%29_720p_HD_50FPS.webm&amp;lang=en-gb&amp;trackformat=vtt '}],
'nl': [{'ext': 'srt',
'url': 'https://commons.wikimedia.org/w/api.php?action=timedtext&amp;title=File%3ADie_Temperaturkurve_der_Erde_%28ZDF%2C_Terra_X%29_720p_HD_50FPS.webm&amp;lang=nl&amp;trackformat=vtt '}],
'en': [{'ext': 'srt',
'url': 'https://commons.wikimedia.org/w/api.php?action=timedtext&amp;title=File%3ADie_Temperaturkurve_der_Erde_%28ZDF%2C_Terra_X%29_720p_HD_50FPS_-_redub_NL.webm&amp;lang=en&amp;trackformat=vtt '}]}}
}
def _real_extract(self, url):
video_id = self._match_id(url)
ext = determine_ext(url)
if not ext.lower() in KNOWN_EXTENSIONS:
raise Exception("invalid video url")
ext = determine_ext(url, None)
if ext is None:
raise ExtractorError('invalid video url', expected=True)
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')
licenze = self._html_search_regex(r'\bThis\s*(.*?)\s*license\b', webpage, u'video license')
licenze = "This " + licenze + " license."
video_url = self._html_search_regex('<source [^>]*src="([^"]+)"', webpage,
'video URL')
license = get_element_by_class('layouttemplate licensetpl mw-content-ltr', webpage)
license = clean_html(license)
description = get_element_by_class('description', webpage)
author = self._html_search_regex(r'<td>([^\<]*?)<\/td>', str(webpage), u"video author")
info = {}
info['url'] = video_url
info['description'] = clean_html(description)
info['ext'] = ext
info['id'] = video_id.replace('.' + ext, "")
info['title'] = self._og_search_title(webpage).replace("File:", "")
info['license'] = licenze
info['author'] = author
author = self._html_search_regex('<td\b[Author>]*>[\n\s]([^<]+?)\s*</td>', webpage, 'video author',
default=None)
info = {'url': video_url, 'description': clean_html(description), 'ext': ext,
'id': video_id.replace('.' + ext, ''), 'title': self._og_search_title(webpage).replace('File:', ''),
'license': license, 'author': author}
subtitles = {}
for sub in re.findall(r'\bsrc=\"\/w\/api\s*(.*?)\s*srt\b', str(webpage)):
sub = 'https://commons.wikimedia.org/w/api' + sub + 'srt'
lang = sub[sub.find('lang=') + 5:]
lang = lang[:lang.find('&')]
sub = sub.replace(';', '&')
info['subtitles'][lang] = [{"ext": "srt", "url": sub}]
for sub in re.findall(r'''\bsrc\s*=\s*[\"\'](\/w\/api(.*?)[\s\"])\b''', webpage):
sub = sub[0].replace('"', '''''')
sub = urljoin('https://commons.wikimedia.org', sub)
qs = compat_parse_qs(sub)
lang = qs.get('lang', [None])[-1]
if not lang:
continue
subtitles[lang] = [{'ext': 'srt', 'url': sub}]
info['subtitles'] = subtitles
return info