[lecturio] add support id based URLs(closes #21630)

This commit is contained in:
Remita Amine 2019-07-04 15:59:25 +01:00
parent a30c2f4055
commit c9fa84d88e

View File

@ -6,8 +6,8 @@ import re
from .common import InfoExtractor from .common import InfoExtractor
from ..compat import compat_str from ..compat import compat_str
from ..utils import ( from ..utils import (
clean_html,
determine_ext, determine_ext,
extract_attributes,
ExtractorError, ExtractorError,
float_or_none, float_or_none,
int_or_none, int_or_none,
@ -19,6 +19,7 @@ from ..utils import (
class LecturioBaseIE(InfoExtractor): class LecturioBaseIE(InfoExtractor):
_API_BASE_URL = 'https://app.lecturio.com/api/en/latest/html5/'
_LOGIN_URL = 'https://app.lecturio.com/en/login' _LOGIN_URL = 'https://app.lecturio.com/en/login'
_NETRC_MACHINE = 'lecturio' _NETRC_MACHINE = 'lecturio'
@ -67,51 +68,56 @@ class LecturioIE(LecturioBaseIE):
_VALID_URL = r'''(?x) _VALID_URL = r'''(?x)
https:// https://
(?: (?:
app\.lecturio\.com/[^/]+/(?P<id>[^/?#&]+)\.lecture| app\.lecturio\.com/([^/]+/(?P<nt>[^/?#&]+)\.lecture|(?:\#/)?lecture/c/\d+/(?P<id>\d+))|
(?:www\.)?lecturio\.de/[^/]+/(?P<id_de>[^/?#&]+)\.vortrag (?:www\.)?lecturio\.de/[^/]+/(?P<nt_de>[^/?#&]+)\.vortrag
) )
''' '''
_TESTS = [{ _TESTS = [{
'url': 'https://app.lecturio.com/medical-courses/important-concepts-and-terms-introduction-to-microbiology.lecture#tab/videos', 'url': 'https://app.lecturio.com/medical-courses/important-concepts-and-terms-introduction-to-microbiology.lecture#tab/videos',
'md5': 'f576a797a5b7a5e4e4bbdfc25a6a6870', 'md5': '9a42cf1d8282a6311bf7211bbde26fde',
'info_dict': { 'info_dict': {
'id': '39634', 'id': '39634',
'ext': 'mp4', 'ext': 'mp4',
'title': 'Important Concepts and Terms Introduction to Microbiology', 'title': 'Important Concepts and Terms Introduction to Microbiology',
}, },
'skip': 'Requires lecturio account credentials', 'skip': 'Requires lecturio account credentials',
}, { }, {
'url': 'https://www.lecturio.de/jura/oeffentliches-recht-staatsexamen.vortrag', 'url': 'https://www.lecturio.de/jura/oeffentliches-recht-staatsexamen.vortrag',
'only_matching': True, 'only_matching': True,
}, {
'url': 'https://app.lecturio.com/#/lecture/c/6434/39634',
'only_matching': True,
}] }]
_CC_LANGS = { _CC_LANGS = {
'Arabic': 'ar',
'Bulgarian': 'bg',
'German': 'de', 'German': 'de',
'English': 'en', 'English': 'en',
'Spanish': 'es', 'Spanish': 'es',
'Persian': 'fa',
'French': 'fr', 'French': 'fr',
'Japanese': 'ja',
'Polish': 'pl', 'Polish': 'pl',
'Pashto': 'ps',
'Russian': 'ru', 'Russian': 'ru',
} }
def _real_extract(self, url): def _real_extract(self, url):
mobj = re.match(self._VALID_URL, url) mobj = re.match(self._VALID_URL, url)
display_id = mobj.group('id') or mobj.group('id_de') nt = mobj.group('nt') or mobj.group('nt_de')
lecture_id = mobj.group('id')
webpage = self._download_webpage( display_id = nt or lecture_id
'https://app.lecturio.com/en/lecture/%s/player.html' % display_id, api_path = 'lectures/' + lecture_id if lecture_id else 'lecture/' + nt + '.json'
display_id) video = self._download_json(
self._API_BASE_URL + api_path, display_id)
lecture_id = self._search_regex(
r'lecture_id\s*=\s*(?:L_)?(\d+)', webpage, 'lecture id')
api_url = self._search_regex(
r'lectureDataLink\s*:\s*(["\'])(?P<url>(?:(?!\1).)+)\1', webpage,
'api url', group='url')
video = self._download_json(api_url, display_id)
title = video['title'].strip() title = video['title'].strip()
if not lecture_id:
pid = video.get('productId') or video.get('uid')
if pid:
spid = pid.split('_')
if spid and len(spid) == 2:
lecture_id = spid[1]
formats = [] formats = []
for format_ in video['content']['media']: for format_ in video['content']['media']:
@ -129,24 +135,30 @@ class LecturioIE(LecturioBaseIE):
continue continue
label = str_or_none(format_.get('label')) label = str_or_none(format_.get('label'))
filesize = int_or_none(format_.get('fileSize')) filesize = int_or_none(format_.get('fileSize'))
formats.append({ f = {
'url': file_url, 'url': file_url,
'format_id': label, 'format_id': label,
'filesize': float_or_none(filesize, invscale=1000) 'filesize': float_or_none(filesize, invscale=1000)
}) }
if label:
mobj = re.match(r'(\d+)p\s*\(([^)]+)\)', label)
if mobj:
f.update({
'format_id': mobj.group(2),
'height': int(mobj.group(1)),
})
formats.append(f)
self._sort_formats(formats) self._sort_formats(formats)
subtitles = {} subtitles = {}
automatic_captions = {} automatic_captions = {}
cc = self._parse_json( captions = video.get('captions') or []
self._search_regex( for cc in captions:
r'subtitleUrls\s*:\s*({.+?})\s*,', webpage, 'subtitles', cc_url = cc.get('url')
default='{}'), display_id, fatal=False)
for cc_label, cc_url in cc.items():
cc_url = url_or_none(cc_url)
if not cc_url: if not cc_url:
continue continue
lang = self._search_regex( cc_label = cc.get('translatedCode')
lang = cc.get('languageCode') or self._search_regex(
r'/([a-z]{2})_', cc_url, 'lang', r'/([a-z]{2})_', cc_url, 'lang',
default=cc_label.split()[0] if cc_label else 'en') default=cc_label.split()[0] if cc_label else 'en')
original_lang = self._search_regex( original_lang = self._search_regex(
@ -160,7 +172,7 @@ class LecturioIE(LecturioBaseIE):
}) })
return { return {
'id': lecture_id, 'id': lecture_id or nt,
'title': title, 'title': title,
'formats': formats, 'formats': formats,
'subtitles': subtitles, 'subtitles': subtitles,
@ -169,37 +181,40 @@ class LecturioIE(LecturioBaseIE):
class LecturioCourseIE(LecturioBaseIE): class LecturioCourseIE(LecturioBaseIE):
_VALID_URL = r'https://app\.lecturio\.com/[^/]+/(?P<id>[^/?#&]+)\.course' _VALID_URL = r'https://app\.lecturio\.com/(?:[^/]+/(?P<nt>[^/?#&]+)\.course|(?:#/)?course/c/(?P<id>\d+))'
_TEST = { _TESTS = [{
'url': 'https://app.lecturio.com/medical-courses/microbiology-introduction.course#/', 'url': 'https://app.lecturio.com/medical-courses/microbiology-introduction.course#/',
'info_dict': { 'info_dict': {
'id': 'microbiology-introduction', 'id': 'microbiology-introduction',
'title': 'Microbiology: Introduction', 'title': 'Microbiology: Introduction',
'description': 'md5:13da8500c25880c6016ae1e6d78c386a',
}, },
'playlist_count': 45, 'playlist_count': 45,
'skip': 'Requires lecturio account credentials', 'skip': 'Requires lecturio account credentials',
} }, {
'url': 'https://app.lecturio.com/#/course/c/6434',
'only_matching': True,
}]
def _real_extract(self, url): def _real_extract(self, url):
display_id = self._match_id(url) nt, course_id = re.match(self._VALID_URL, url).groups()
display_id = nt or course_id
webpage = self._download_webpage(url, display_id) api_path = 'courses/' + course_id if course_id else 'course/content/' + nt + '.json'
course = self._download_json(
self._API_BASE_URL + api_path, display_id)
entries = [] entries = []
for mobj in re.finditer( for lecture in course.get('lectures', []):
r'(?s)<[^>]+\bdata-url=(["\'])(?:(?!\1).)+\.lecture\b[^>]+>', lecture_id = str_or_none(lecture.get('id'))
webpage): lecture_url = lecture.get('url')
params = extract_attributes(mobj.group(0)) if lecture_url:
lecture_url = urljoin(url, params.get('data-url')) lecture_url = urljoin(url, lecture_url)
lecture_id = params.get('data-id') else:
lecture_url = 'https://app.lecturio.com/#/lecture/c/%s/%s' % (course_id, lecture_id)
entries.append(self.url_result( entries.append(self.url_result(
lecture_url, ie=LecturioIE.ie_key(), video_id=lecture_id)) lecture_url, ie=LecturioIE.ie_key(), video_id=lecture_id))
return self.playlist_result(
title = self._search_regex( entries, display_id, course.get('title'),
r'<span[^>]+class=["\']content-title[^>]+>([^<]+)', webpage, clean_html(course.get('description')))
'title', default=None)
return self.playlist_result(entries, display_id, title)
class LecturioDeCourseIE(LecturioBaseIE): class LecturioDeCourseIE(LecturioBaseIE):