mirror of
https://github.com/ytdl-org/youtube-dl
synced 2025-02-04 01:30:12 +09:00
made changes according to request also I really appreciate help by @dirkf
This commit is contained in:
parent
7bf92fd726
commit
bf428499a0
@ -1,8 +1,5 @@
|
|||||||
from .common import InfoExtractor
|
from .common import InfoExtractor
|
||||||
import re
|
from ..utils import get_element_by_class, compat_urlparse
|
||||||
import requests
|
|
||||||
import urllib.parse
|
|
||||||
from ..utils import clean_html
|
|
||||||
|
|
||||||
|
|
||||||
class WikimediaIE(InfoExtractor):
|
class WikimediaIE(InfoExtractor):
|
||||||
@ -29,8 +26,7 @@ class WikimediaIE(InfoExtractor):
|
|||||||
'author': 'ZDF/Terra X/Gruppe 5/Luise Wagner, Jonas Sichert, Andreas Hougardy'}
|
'author': 'ZDF/Terra X/Gruppe 5/Luise Wagner, Jonas Sichert, Andreas Hougardy'}
|
||||||
|
|
||||||
def _real_extract(self, url):
|
def _real_extract(self, url):
|
||||||
mobj = re.match(self._VALID_URL, url)
|
video_id = self._match_id(url)
|
||||||
video_id = mobj.group('id')
|
|
||||||
|
|
||||||
if not video_id.endswith('.webm'):
|
if not video_id.endswith('.webm'):
|
||||||
raise Exception("invalid video url")
|
raise Exception("invalid video url")
|
||||||
@ -39,32 +35,23 @@ class WikimediaIE(InfoExtractor):
|
|||||||
self.report_extraction(video_id)
|
self.report_extraction(video_id)
|
||||||
video_url = self._html_search_regex(r'<source [^>]*src="([^"]+)"', webpage,
|
video_url = self._html_search_regex(r'<source [^>]*src="([^"]+)"', webpage,
|
||||||
u'video URL')
|
u'video URL')
|
||||||
licenze = self._html_search_regex(f"(?<=td>This)(.*)(?=license.)", webpage, u'video license')
|
licenze = self._html_search_regex(r'\bThis\s*(.*?)\s*license\b', webpage, u'video license')
|
||||||
licenze = "This " + licenze + " license."
|
licenze = "This " + licenze + " license."
|
||||||
|
|
||||||
description = self._html_search_regex(f'(?<=<div class="description mw-content-ltr de" dir="ltr" lang="de">)('
|
description = get_element_by_class('description', webpage)
|
||||||
f'.*)(?=</div>)', webpage,
|
|
||||||
u'video description')
|
|
||||||
|
|
||||||
author = re.search(r'<td>([^\<]*?)<\/td>', str(webpage))
|
author = self._html_search_regex(r'<td>([^\<]*?)<\/td>', str(webpage), u"video author")
|
||||||
author = clean_html(author.group(0))
|
|
||||||
resp = {}
|
|
||||||
|
|
||||||
subtitle_url = f'https://commons.wikimedia.org/w/api.php?' \
|
info = {}
|
||||||
f'action=timedtext&lang=nl&title=File%3A{urllib.parse.quote(video_id)}&trackformat=srt'
|
subtitles = 'https://commons.wikimedia.org/w/api.php?action=timedtext&lang=nl&title=File%3A{}' \
|
||||||
|
'&trackformat=srt'.format(compat_urlparse.quote_plus(video_id))
|
||||||
subtitles = requests.post(subtitle_url).text
|
info['url'] = video_url
|
||||||
if 'timedtext-notfound' not in subtitles:
|
info['description'] = description
|
||||||
with open(video_id + '.srt', 'w+', encoding='utf') as f:
|
info['ext'] = 'webm'
|
||||||
f.write(subtitles)
|
info['id'] = video_id
|
||||||
else:
|
info['title'] = self._og_search_title(webpage).replace("File:", "")
|
||||||
print("subtitles not found")
|
info['license'] = licenze
|
||||||
|
info['author'] = author
|
||||||
resp['url'] = video_url
|
info['subtitles'] = {"nl": [{"ext": "srt", "url": subtitles}]}
|
||||||
resp['description'] = description
|
print("ih")
|
||||||
resp['ext'] = 'webm'
|
return info
|
||||||
resp['id'] = video_id
|
|
||||||
resp['title'] = self._og_search_title(webpage)
|
|
||||||
resp['license'] = licenze
|
|
||||||
resp['author'] = author
|
|
||||||
return [resp]
|
|
||||||
|
Loading…
Reference in New Issue
Block a user