1
0
mirror of https://codeberg.org/polarisfm/youtube-dl synced 2025-01-10 07:07:55 +01:00
youtube-dl/youtube_dl/extractor/picta.py

134 lines
5.1 KiB
Python
Raw Normal View History

2019-02-02 01:07:44 +01:00
# coding: utf-8
from __future__ import unicode_literals
2019-02-02 06:30:27 +01:00
from ..compat import compat_str
2019-02-02 01:07:44 +01:00
from ..utils import (
int_or_none,
unified_timestamp,
2019-02-02 06:30:27 +01:00
try_get,
base_url,
2019-02-02 01:07:44 +01:00
ExtractorError
)
from .common import InfoExtractor
2019-02-02 06:30:27 +01:00
class PictaBaseIE(InfoExtractor):
2019-02-27 03:33:14 +01:00
API_BASE_URL = 'https://api.picta.cu/api/v1/'
2019-02-02 06:30:27 +01:00
def _extract_video(self, video, video_id=None, require_title=True):
title = video['results'][0]['nombre'] if require_title else video.get('results')[0].get('nombre')
description = try_get(video, lambda x: x['results'][0]['descripcion'], compat_str)
uploader = try_get(video, lambda x: x['results'][0]['usuario'], compat_str)
add_date = try_get(video, lambda x: x['results'][0]['fecha_creacion'])
timestamp = int_or_none(unified_timestamp(add_date))
thumbnail = try_get(video, lambda x: x['results'][0]['url_imagen'])
manifest_url = try_get(video, lambda x: x['results'][0]['url_manifiesto'])
category = try_get(video, lambda x: x['results'][0]['canal'], compat_str)
return {
'id': try_get(video, lambda x: x['results'][0]['id'], compat_str) or video_id,
'title': title,
'description': description,
'thumbnail': thumbnail,
'uploader': uploader,
'timestamp': timestamp,
'category': [category] if category else None,
'manifest_url': manifest_url,
}
class PictaIE(PictaBaseIE):
2019-02-08 00:38:41 +01:00
IE_NAME = 'picta'
IE_DESC = 'Picta videos'
_VALID_URL = r'https?://(?:www\.)?picta\.cu/(?:medias|embed)/(?:\?v=)?(?P<id>[\da-z-]+)'
2019-02-17 00:25:59 +01:00
_formats = {
# Dash webm
'0': {'ext': 'webm', 'height': 144, 'format_note': 'DASH video', 'container': 'webm', 'vcodec': 'vp9'},
'1': {'ext': 'webm', 'height': 240, 'format_note': 'DASH video', 'vcodec': 'vp9'},
'2': {'ext': 'webm', 'height': 360, 'format_note': 'DASH video', 'vcodec': 'vp9'},
'3': {'ext': 'webm', 'height': 480, 'format_note': 'DASH video', 'vcodec': 'vp9'},
'4': {'ext': 'webm', 'height': 720, 'format_note': 'DASH video', 'vcodec': 'vp9'},
# Dash webm audio with opus inside
'5': {'ext': 'webm', 'format_note': 'DASH audio', 'acodec': 'opus', 'abr': 128},
'6': {'ext': 'webm', 'format_note': 'DASH audio', 'acodec': 'opus', 'abr': 134},
}
2019-02-08 00:38:41 +01:00
_TESTS = [{
'url': 'https://www.picta.cu/medias/orishas-everyday-2019-01-16-16-36-42-443003',
'file': 'Orishas - Everyday-orishas-everyday-2019-01-16-16-36-42-443003.webm',
2019-02-17 04:36:31 +01:00
'md5': '7ffdeb0043500c4bb660c04e74e90f7a',
2019-02-02 01:07:44 +01:00
'info_dict': {
2019-02-17 04:36:31 +01:00
'id': 'orishas-everyday-2019-01-16-16-36-42-443003',
2019-02-02 01:07:44 +01:00
'ext': 'webm',
'title': 'Orishas - Everyday',
'thumbnail': r're:^https?://.*imagen/img.*\.png$',
2019-02-17 04:36:31 +01:00
'upload_date': '20190116',
'description': 'Orishas - Everyday (Video Oficial)',
'uploader': 'admin',
'timestamp': 1547656602,
},
'params': {
'format': '4',
2019-02-17 00:25:59 +01:00
},
2019-02-08 00:38:41 +01:00
}, {
'url': 'https://www.picta.cu/embed/?v=818',
'only_matching': True,
}]
2019-02-02 01:07:44 +01:00
def _real_extract(self, url):
video_id = self._match_id(url)
if base_url(url).find('medias') != -1:
json_url = self.API_BASE_URL + 'publicacion/?format=json&slug_url=%s&tipo=publicacion' % video_id
else:
json_url = self.API_BASE_URL + 'publicacion/?format=json&id_publicacion=%s&tipo=publicacion' % video_id
2019-02-02 06:30:27 +01:00
video = self._download_json(json_url, video_id, 'Downloading video JSON')
info = self._extract_video(video, video_id)
2019-02-02 01:07:44 +01:00
formats = []
# MPD manifest
2019-02-02 06:30:27 +01:00
if info.get('manifest_url'):
2019-02-17 00:25:59 +01:00
formats.extend(self._extract_mpd_formats(info.get('manifest_url'), video_id, formats_dict=self._formats))
# Fix some Picta DASH video vp09.00.[dd].08 for 'vcodec': 'vp9', 'acodec':'none'
for f in formats:
if f.get('acodec') is None and f.get('vcodec') == 'none':
f.update({'vcodec':'vp9'})
f.update({'acodec':'none'})
2019-02-02 01:07:44 +01:00
if not formats:
raise ExtractorError('Cannot find video formats')
self._sort_formats(formats)
2019-02-02 06:30:27 +01:00
info['formats'] = formats
return info
2019-02-08 00:38:41 +01:00
class PictaEmbedIE(InfoExtractor):
IE_NAME = 'picta:embed'
IE_DESC = 'Picta embedded videos'
_VALID_URL = r'https?://www\.picta\.cu/embed/\?v=(?P<id>[0-9]+)'
_TEST = {
'url': 'https://www.picta.cu/embed/?v=818',
'file': 'Orishas - Everyday-orishas-everyday-2019-01-16-16-36-42-443003.webm',
2019-02-17 04:36:31 +01:00
'md5': '7ffdeb0043500c4bb660c04e74e90f7a',
2019-02-08 00:38:41 +01:00
'info_dict': {
2019-02-17 04:36:31 +01:00
'id': 'orishas-everyday-2019-01-16-16-36-42-443003',
2019-02-08 00:38:41 +01:00
'ext': 'webm',
'title': 'Orishas - Everyday',
'thumbnail': r're:^https?://.*imagen/img.*\.png$',
2019-02-17 04:36:31 +01:00
'upload_date': '20190116',
'description': 'Orishas - Everyday (Video Oficial)',
'uploader': 'admin',
'timestamp': 1547656602,
},
'params': {
'format': '4',
},
2019-02-08 00:38:41 +01:00
}
def _real_extract(self, url):
return self.url_result(url, PictaIE.ie_key())