Added try_get for multiple getters
This commit is contained in:
parent
cc7f194d7c
commit
4cc0397872
@ -1,8 +1,8 @@
|
||||
# coding: utf-8
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from ..compat import compat_urlparse
|
||||
from ..utils import urljoin, int_or_none
|
||||
from ..compat import compat_urlparse, compat_str
|
||||
from ..utils import urljoin, int_or_none, try_get
|
||||
from .common import InfoExtractor
|
||||
|
||||
|
||||
@ -25,7 +25,7 @@ class PeertubeIE(InfoExtractor):
|
||||
def _real_extract(self, url):
|
||||
video_id = self._match_id(url)
|
||||
url_data = compat_urlparse.urlparse(url)
|
||||
base_url = "%s://%s" % (url_data.scheme, url_data.hostname)
|
||||
base_url = "%s://%s" % (url_data.scheme or 'http', url_data.hostname)
|
||||
api_url = urljoin(base_url, "/api/v1/videos/%s" % video_id)
|
||||
details = self._download_json(api_url, video_id)
|
||||
formats = [{'url': file_data['fileUrl'], 'filesize': int_or_none(file_data.get('size')), 'format': file_data.get('resolution', {}).get('label')} for file_data in details['files']]
|
||||
@ -36,9 +36,9 @@ class PeertubeIE(InfoExtractor):
|
||||
'description': details.get('description'),
|
||||
'formats': formats,
|
||||
'thumbnail': urljoin(base_url, details['thumbnailPath']) if 'thumbnailPath' in details else None,
|
||||
'uploader': details.get('account', {}).get('name'),
|
||||
'uploader_id': details.get('account', {}).get('id'),
|
||||
'uploder_url': details.get('account', {}).get('url'),
|
||||
'uploader': try_get(details, lambda x: x['account']['displayName'], compat_str),
|
||||
'uploader_id': try_get(details, lambda x: x['account']['id'], int),
|
||||
'uploder_url': try_get(details, lambda x: x['account']['url'], compat_str),
|
||||
'duration': int_or_none(details.get('duration')),
|
||||
'view_count': int_or_none(details.get('views')),
|
||||
'like_count': int_or_none(details.get('likes')),
|
||||
|
Loading…
x
Reference in New Issue
Block a user