0
0
Fork 0
mirror of https://github.com/yt-dlp/yt-dlp.git synced 2024-12-05 04:17:27 +00:00
yt-dlp/yt_dlp/extractor/viidea.py

197 lines
7.1 KiB
Python
Raw Normal View History

import re
import urllib.parse
2014-03-21 13:38:37 +00:00
from .common import InfoExtractor
from ..networking.exceptions import HTTPError
from ..utils import (
ExtractorError,
js_to_json,
parse_duration,
parse_iso8601,
)
2014-03-21 13:38:37 +00:00
class ViideaIE(InfoExtractor):
_VALID_URL = r'''(?x)https?://(?:www\.)?(?:
videolectures\.net|
flexilearn\.viidea\.net|
presentations\.ocwconsortium\.org|
video\.travel-zoom\.si|
video\.pomp-forum\.si|
tv\.nil\.si|
video\.hekovnik.com|
video\.szko\.si|
kpk\.viidea\.com|
inside\.viidea\.net|
video\.kiberpipa\.org|
bvvideo\.si|
kongres\.viidea\.net|
edemokracija\.viidea\.com
)(?:/lecture)?/(?P<id>[^/]+)(?:/video/(?P<part>\d+))?/*(?:[#?].*)?$'''
2014-03-21 13:38:37 +00:00
2015-10-01 16:45:10 +00:00
_TESTS = [{
2014-03-21 13:38:37 +00:00
'url': 'http://videolectures.net/promogram_igor_mekjavic_eng/',
'info_dict': {
'id': '20171',
'display_id': 'promogram_igor_mekjavic_eng',
2014-03-21 13:38:37 +00:00
'ext': 'mp4',
'title': 'Automatics, robotics and biocybernetics',
'description': 'md5:815fc1deb6b3a2bff99de2d5325be482',
'thumbnail': r're:http://.*\.jpg',
'timestamp': 1372349289,
2014-03-21 13:38:37 +00:00
'upload_date': '20130627',
'duration': 565,
},
'params': {
# m3u8 download
'skip_download': True,
},
}, {
# video with invalid direct format links (HTTP 403)
'url': 'http://videolectures.net/russir2010_filippova_nlp/',
'info_dict': {
'id': '14891',
'display_id': 'russir2010_filippova_nlp',
'ext': 'flv',
'title': 'NLP at Google',
'description': 'md5:fc7a6d9bf0302d7cc0e53f7ca23747b3',
'thumbnail': r're:http://.*\.jpg',
'timestamp': 1284375600,
'upload_date': '20100913',
'duration': 5352,
},
'params': {
# rtmp download
'skip_download': True,
},
2015-10-01 16:45:10 +00:00
}, {
# event playlist
2015-10-01 16:45:10 +00:00
'url': 'http://videolectures.net/deeplearning2015_montreal/',
'info_dict': {
'id': '23181',
2015-10-01 16:45:10 +00:00
'title': 'Deep Learning Summer School, Montreal 2015',
'description': 'md5:0533a85e4bd918df52a01f0e1ebe87b7',
'thumbnail': r're:http://.*\.jpg',
'timestamp': 1438560000,
2015-10-01 16:45:10 +00:00
},
'playlist_count': 30,
}, {
# multi part lecture
'url': 'http://videolectures.net/mlss09uk_bishop_ibi/',
'info_dict': {
'id': '9737',
'display_id': 'mlss09uk_bishop_ibi',
'title': 'Introduction To Bayesian Inference',
'thumbnail': r're:http://.*\.jpg',
'timestamp': 1251622800,
},
'playlist': [{
'info_dict': {
'id': '9737_part1',
'display_id': 'mlss09uk_bishop_ibi_part1',
'ext': 'wmv',
'title': 'Introduction To Bayesian Inference (Part 1)',
'thumbnail': r're:http://.*\.jpg',
'duration': 4622,
'timestamp': 1251622800,
'upload_date': '20090830',
},
}, {
'info_dict': {
'id': '9737_part2',
'display_id': 'mlss09uk_bishop_ibi_part2',
'ext': 'wmv',
'title': 'Introduction To Bayesian Inference (Part 2)',
'thumbnail': r're:http://.*\.jpg',
'duration': 5641,
'timestamp': 1251622800,
'upload_date': '20090830',
},
}],
'playlist_count': 2,
2015-10-01 16:45:10 +00:00
}]
2014-03-21 13:38:37 +00:00
def _real_extract(self, url):
lecture_slug, explicit_part_id = self._match_valid_url(url).groups()
webpage = self._download_webpage(url, lecture_slug)
2014-03-21 13:38:37 +00:00
cfg = self._parse_json(self._search_regex(
[r'cfg\s*:\s*({.+?})\s*,\s*[\da-zA-Z_]+\s*:\s*\(?\s*function',
r'cfg\s*:\s*({[^}]+})'],
webpage, 'cfg'), lecture_slug, js_to_json)
lecture_id = str(cfg['obj_id'])
2014-03-21 13:38:37 +00:00
base_url = self._proto_relative_url(cfg['livepipe'], 'http:')
try:
lecture_data = self._download_json(
f'{base_url}/site/api/lecture/{lecture_id}?format=json',
lecture_id)['lecture'][0]
except ExtractorError as e:
if isinstance(e.cause, HTTPError) and e.cause.status == 403:
msg = self._parse_json(
e.cause.response.read().decode('utf-8'), lecture_id)
raise ExtractorError(msg['detail'], expected=True)
raise
2014-03-21 13:38:37 +00:00
lecture_info = {
'id': lecture_id,
'display_id': lecture_slug,
'title': lecture_data['title'],
'timestamp': parse_iso8601(lecture_data.get('time')),
'description': lecture_data.get('description_wiki'),
'thumbnail': lecture_data.get('thumb'),
}
2014-03-21 13:38:37 +00:00
playlist_entries = []
lecture_type = lecture_data.get('type')
parts = [str(video) for video in cfg.get('videos', [])]
if parts:
multipart = len(parts) > 1
def extract_part(part_id):
smil_url = f'{base_url}/{lecture_slug}/video/{part_id}/smil.xml'
smil = self._download_smil(smil_url, lecture_id)
info = self._parse_smil(smil, smil_url, lecture_id)
info['id'] = lecture_id if not multipart else f'{lecture_id}_part{part_id}'
info['display_id'] = lecture_slug if not multipart else f'{lecture_slug}_part{part_id}'
if multipart:
info['title'] += f' (Part {part_id})'
switch = smil.find('.//switch')
if switch is not None:
info['duration'] = parse_duration(switch.attrib.get('dur'))
item_info = lecture_info.copy()
item_info.update(info)
return item_info
if explicit_part_id or not multipart:
result = extract_part(explicit_part_id or parts[0])
else:
result = {
'_type': 'multi_video',
'entries': [extract_part(part) for part in parts],
}
result.update(lecture_info)
# Immediately return explicitly requested part or non event item
if explicit_part_id or lecture_type != 'evt':
return result
playlist_entries.append(result)
# It's probably a playlist
if not parts or lecture_type == 'evt':
playlist_webpage = self._download_webpage(
f'{base_url}/site/ajax/drilldown/?id={lecture_id}', lecture_id)
entries = [
self.url_result(urllib.parse.urljoin(url, video_url), 'Viidea')
for _, video_url in re.findall(
r'<a[^>]+href=(["\'])(.+?)\1[^>]+id=["\']lec=\d+', playlist_webpage)]
playlist_entries.extend(entries)
2014-03-21 13:38:37 +00:00
playlist = self.playlist_result(playlist_entries, lecture_id)
playlist.update(lecture_info)
return playlist