Integrated peertube api for peertube

This commit is contained in:
Parth Verma 2018-04-30 22:30:34 +05:30
parent 034026359e
commit 2d8fc9c537

View File

@ -1,35 +1,35 @@
# coding: utf-8 # coding: utf-8
from __future__ import unicode_literals from __future__ import unicode_literals
from ..compat import compat_urlparse
from .common import InfoExtractor from .common import InfoExtractor
class PeertubeIE(InfoExtractor): class PeertubeIE(InfoExtractor):
_BASE_VIDEO_URL = 'https://peertube.touhoppai.moe/static/webseed/%s-1080.mp4'
_BASE_THUMBNAIL_URL = 'https://peertube.touhoppai.moe/static/previews/%s.jpg'
IE_DESC = 'Peertube Videos' IE_DESC = 'Peertube Videos'
IE_NAME = 'Peertube' IE_NAME = 'Peertube'
_VALID_URL = r'https?:\/\/peertube\.touhoppai\.moe\/videos\/watch\/(?P<id>[0-9|\-|a-z]+)' _VALID_URL = r'https?:\/\/peertube\.touhoppai\.moe\/videos\/watch\/(?P<id>[0-9|\-|a-z]+)'
_TEST = { _TEST = {
'url': 'https://peertube.touhoppai.moe/videos/watch/7f3421ae-6161-4a4a-ae38-d167aec51683', 'url': 'https://peertube.touhoppai.moe/videos/watch/7f3421ae-6161-4a4a-ae38-d167aec51683',
'md5': 'a5e1e4a978e6b789553198d1739f5643', 'md5': '051ef9823d237416d5a6fc0bd8d67812',
'info_dict': { 'info_dict': {
'id': '7f3421ae-6161-4a4a-ae38-d167aec51683', 'id': '7f3421ae-6161-4a4a-ae38-d167aec51683',
'ext': 'mp4', 'ext': 'mp4',
'title': 'David Revoy Live Stream: Speedpainting', 'title': 'David Revoy Live Stream: Speedpainting',
'description': 'md5:5c09a6e3fdb5f56edce289d69fbe7567', 'description': 'md5:4e67c2fec55739a2ccb86052505a741e',
'thumbnail': 'https://peertube.touhoppai.moe/static/previews/7f3421ae-6161-4a4a-ae38-d167aec51683.jpg', 'thumbnail': 'https://peertube.touhoppai.moe/static/thumbnails/7f3421ae-6161-4a4a-ae38-d167aec51683.jpg',
} }
} }
def _real_extract(self, url): def _real_extract(self, url):
video_id = self._match_id(url) video_id = self._match_id(url)
webpage = self._download_webpage(url, video_id) url_data = compat_urlparse.urlparse(url)
title = self._og_search_title(webpage) api_url = "%s://%s/api/v1/videos/%s" % (url_data.scheme, url_data.hostname, video_id)
details = self._download_json(api_url, video_id)
return { return {
'id': video_id, 'id': video_id,
'title': title, 'title': details['name'],
'description': self._og_search_description(webpage), 'description': details['description'],
'url': self._BASE_VIDEO_URL % video_id, 'url': details['files'][-1]['fileUrl'],
'thumbnail': self._BASE_THUMBNAIL_URL % video_id 'thumbnail': url_data.scheme + '://' + url_data.hostname + details['thumbnailPath']
} }