mirror of
https://codeberg.org/polarisfm/youtube-dl
synced 2024-11-16 14:34:31 +01:00
[voicerepublic] Make more robust and extract more metadata
This commit is contained in:
parent
98c2c0febc
commit
a6762c4a22
@ -1,52 +1,99 @@
|
|||||||
# coding: utf-8
|
|
||||||
from __future__ import unicode_literals
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
import re
|
import re
|
||||||
|
|
||||||
from .common import InfoExtractor
|
from .common import InfoExtractor
|
||||||
from ..compat import compat_urllib_request
|
from ..compat import (
|
||||||
from ..utils import ExtractorError
|
compat_urllib_request,
|
||||||
|
compat_urlparse,
|
||||||
|
)
|
||||||
|
from ..utils import (
|
||||||
|
ExtractorError,
|
||||||
|
determine_ext,
|
||||||
|
int_or_none,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
class VoiceRepublicIE(InfoExtractor):
|
class VoiceRepublicIE(InfoExtractor):
|
||||||
_VALID_URL = r'https?://voicerepublic\.com/talks/(?P<id>[0-9a-z-]+)'
|
_VALID_URL = r'https?://voicerepublic\.com/(?:talks|embed)/(?P<id>[0-9a-z-]+)'
|
||||||
_TEST = {
|
_TESTS = [{
|
||||||
'url': 'https://voicerepublic.com/talks/watching-the-watchers-building-a-sousveillance-state',
|
'url': 'http://voicerepublic.com/talks/watching-the-watchers-building-a-sousveillance-state',
|
||||||
'md5': '0554a24d1657915aa8e8f84e15dc9353',
|
'md5': '0554a24d1657915aa8e8f84e15dc9353',
|
||||||
'info_dict': {
|
'info_dict': {
|
||||||
'id': '2296',
|
'id': '2296',
|
||||||
|
'display_id': 'watching-the-watchers-building-a-sousveillance-state',
|
||||||
'ext': 'm4a',
|
'ext': 'm4a',
|
||||||
'title': 'Watching the Watchers: Building a Sousveillance State',
|
'title': 'Watching the Watchers: Building a Sousveillance State',
|
||||||
'thumbnail': 'https://voicerepublic.com/system/flyer/2296.png',
|
|
||||||
'description': 'md5:715ba964958afa2398df615809cfecb1',
|
'description': 'md5:715ba964958afa2398df615809cfecb1',
|
||||||
|
'thumbnail': 're:^https?://.*\.(?:png|jpg)$',
|
||||||
|
'duration': 1800,
|
||||||
|
'view_count': int,
|
||||||
}
|
}
|
||||||
}
|
}, {
|
||||||
|
'url': 'http://voicerepublic.com/embed/watching-the-watchers-building-a-sousveillance-state',
|
||||||
|
'only_matching': True,
|
||||||
|
}]
|
||||||
|
|
||||||
def _real_extract(self, url):
|
def _real_extract(self, url):
|
||||||
display_id = self._match_id(url)
|
display_id = self._match_id(url)
|
||||||
req = compat_urllib_request.Request(url)
|
|
||||||
|
req = compat_urllib_request.Request(
|
||||||
|
compat_urlparse.urljoin(url, '/talks/%s' % display_id))
|
||||||
# Older versions of Firefox get redirected to an "upgrade browser" page
|
# Older versions of Firefox get redirected to an "upgrade browser" page
|
||||||
req.add_header('User-Agent', 'youtube-dl')
|
req.add_header('User-Agent', 'youtube-dl')
|
||||||
webpage = self._download_webpage(req, display_id)
|
webpage = self._download_webpage(req, display_id)
|
||||||
thumbnail = self._og_search_thumbnail(webpage)
|
|
||||||
video_id = self._search_regex(r'/(\d+)\.png', thumbnail, 'id')
|
|
||||||
|
|
||||||
if '<a>Queued for processing, please stand by...</a>' in webpage:
|
if '>Queued for processing, please stand by...<' in webpage:
|
||||||
raise ExtractorError('Audio is still queued for processing')
|
raise ExtractorError(
|
||||||
|
'Audio is still queued for processing', expected=True)
|
||||||
|
|
||||||
|
data = self._parse_json(
|
||||||
|
self._search_regex(
|
||||||
|
r'(?s)return ({.+?});\s*\n', webpage,
|
||||||
|
'data', default=None),
|
||||||
|
display_id, fatal=False)
|
||||||
|
|
||||||
|
if data:
|
||||||
|
title = data['title']
|
||||||
|
description = data.get('teaser')
|
||||||
|
talk_id = data.get('talk_id') or display_id
|
||||||
|
talk = data['talk']
|
||||||
|
duration = int_or_none(talk.get('duration'))
|
||||||
formats = [{
|
formats = [{
|
||||||
'url': 'https://voicerepublic.com' + path,
|
'url': compat_urlparse.urljoin(url, talk_url),
|
||||||
'ext': ext,
|
'format_id': format_id,
|
||||||
'format_id': ext,
|
'ext': determine_ext(talk_url) or format_id,
|
||||||
'vcodec': 'none',
|
'vcodec': 'none',
|
||||||
} for ext, path in re.findall(r"data-([^=]+)='(/[^']+\.\1)'", webpage)]
|
} for format_id, talk_url in talk['links'].items()]
|
||||||
|
else:
|
||||||
|
title = self._og_search_title(webpage)
|
||||||
|
description = self._html_search_regex(
|
||||||
|
r"(?s)<div class='talk-teaser'[^>]*>(.+?)</div>",
|
||||||
|
webpage, 'description', fatal=False)
|
||||||
|
talk_id = self._search_regex(
|
||||||
|
[r"id='jc-(\d+)'", r"data-shareable-id='(\d+)'"],
|
||||||
|
webpage, 'talk id', default=None) or display_id
|
||||||
|
duration = None
|
||||||
|
formats = [{
|
||||||
|
'url': compat_urlparse.urljoin(url, talk_url),
|
||||||
|
'format_id': format_id,
|
||||||
|
'ext': determine_ext(talk_url) or format_id,
|
||||||
|
'vcodec': 'none',
|
||||||
|
} for format_id, talk_url in re.findall(r"data-([^=]+)='([^']+)'", webpage)]
|
||||||
self._sort_formats(formats)
|
self._sort_formats(formats)
|
||||||
|
|
||||||
|
thumbnail = self._og_search_thumbnail(webpage)
|
||||||
|
view_count = int_or_none(self._search_regex(
|
||||||
|
r"class='play-count[^']*'>\s*(\d+) plays",
|
||||||
|
webpage, 'play count', fatal=False))
|
||||||
|
|
||||||
return {
|
return {
|
||||||
'id': video_id,
|
'id': talk_id,
|
||||||
'title': self._og_search_title(webpage),
|
'display_id': display_id,
|
||||||
'formats': formats,
|
'title': title,
|
||||||
'url': self._og_search_url(webpage),
|
'description': description,
|
||||||
'thumbnail': thumbnail,
|
'thumbnail': thumbnail,
|
||||||
'description': self._og_search_description(webpage),
|
'duration': duration,
|
||||||
|
'view_count': view_count,
|
||||||
|
'formats': formats,
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user