1
0
mirror of https://codeberg.org/polarisfm/youtube-dl synced 2024-11-22 16:44:32 +01:00

[Pivotshare] Add playlist extractor

This commit is contained in:
jgilf 2020-06-08 15:20:52 +10:00
parent b892c5fbb7
commit 0d1a78fea8
2 changed files with 99 additions and 49 deletions

View File

@ -842,7 +842,10 @@ from .picarto import (
) )
from .piksel import PikselIE from .piksel import PikselIE
from .pinkbike import PinkbikeIE from .pinkbike import PinkbikeIE
from .pivotshare import PivotshareIE from .pivotshare import (
PivotshareIE,
PivotsharePlaylistIE,
)
from .pladform import PladformIE from .pladform import PladformIE
from .platzi import ( from .platzi import (
PlatziIE, PlatziIE,

View File

@ -17,47 +17,46 @@ from ..utils import (
) )
class PivotshareIE(InfoExtractor): class PivotshareBaseIE(InfoExtractor):
_VALID_URL = r"""(?x) _VALID_URL_BASE = r"""(?x)
https?:// https?://
(?:www\.)? (?:www\.)?
(?P<domain> (?P<domain>
(?: (?:
thunderboltpoweryogatv| thunderboltpoweryogatv|
hungrymonkyoga| hungrymonkyoga|
soccer\.sklz| soccer\.sklz|
womenstennisnetwork| womenstennisnetwork|
pigskinkids| pigskinkids|
czwstudios| czwstudios|
highspotswrestlingnetwork| highspotswrestlingnetwork|
titlematchwrestlingnetwork| titlematchwrestlingnetwork|
womenswrestlingnetwork| womenswrestlingnetwork|
rockstarpronetwork| rockstarpronetwork|
mcwragetv| mcwragetv|
aawondemand| aawondemand|
pwnnetwork| pwnnetwork|
ondemand\.DiscoveryWrestling| ondemand\.DiscoveryWrestling|
adsrcourses| adsrcourses|
reaktortutorials| reaktortutorials|
crosscounter| crosscounter|
cultorama| cultorama|
bongflix| bongflix|
everyonecansalsa| everyonecansalsa|
academy\.tedgibson| academy\.tedgibson|
video\.jasyoga| video\.jasyoga|
(?P<subdomain> (?P<subdomain>[^.]+)\.pivotshare
[^.]+ )
)\.pivotshare \.(?:com|tv)
)\. )?"""
(?:com|tv) _API_BASE = 'https://api.pivotshare.com/v1/'
)?/media/ _CLIENT_ID = 'c0da629bb49ceff00327ac7c1f128bca'
(?: _TOKEN = None
[^/]+ _NETRC_MACHINE = 'pivotshare'
)/
(?P<id>
[0-9]+ class PivotshareIE(PivotshareBaseIE):
) _VALID_URL = r"%s/media/(?:[^/]+)/(?P<id>[0-9]+)" % PivotshareBaseIE._VALID_URL_BASE
"""
_TESTS = [{ _TESTS = [{
'url': 'https://ted.pivotshare.com/media/rob-forbes-on-ways-of-seeing/61/feature', 'url': 'https://ted.pivotshare.com/media/rob-forbes-on-ways-of-seeing/61/feature',
'md5': '30a2ba2b97d0a1ccd2efb5d534d922ae', 'md5': '30a2ba2b97d0a1ccd2efb5d534d922ae',
@ -106,11 +105,6 @@ class PivotshareIE(InfoExtractor):
'only_matching': True, 'only_matching': True,
}] }]
_API_BASE = 'https://api.pivotshare.com/v1/'
_CLIENT_ID = 'c0da629bb49ceff00327ac7c1f128bca'
_TOKEN = None
_NETRC_MACHINE = 'pivotshare'
def _real_initialize(self): def _real_initialize(self):
self._login() self._login()
@ -149,8 +143,8 @@ class PivotshareIE(InfoExtractor):
query['access_token'] = self._TOKEN query['access_token'] = self._TOKEN
channel_meta = self._download_json( channel_meta = self._download_json(
'%schannels/%s' % (self._API_BASE, subdomain if subdomain else domain), '%schannels/%s' % (self._API_BASE, subdomain or domain),
subdomain, "Downloading channel JSON metadata", subdomain or domain, "Downloading channel JSON metadata",
query=query) query=query)
query.pop('search_method') query.pop('search_method')
@ -204,3 +198,56 @@ class PivotshareIE(InfoExtractor):
'duration': try_get(meta, lambda x: x['channel']['media']['duration'], int), 'duration': try_get(meta, lambda x: x['channel']['media']['duration'], int),
'categories': [try_get(meta, lambda x: x['channel']['media']['category'], compat_str)], 'categories': [try_get(meta, lambda x: x['channel']['media']['category'], compat_str)],
} }
class PivotsharePlaylistIE(PivotshareBaseIE):
_VALID_URL = r'%s/categories/(?:[^/]+)/(?P<id>[0-9]+)' % PivotshareBaseIE._VALID_URL_BASE
_TESTS = [{
'url': 'https://ted.pivotshare.com/categories/science/43/media',
'info_dict': {
'id': '43',
'title': 'Science',
},
}]
def _real_extract(self, url):
domain, subdomain, playlist_id = re.match(self._VALID_URL, url).groups()
query = {
'client_id': self._CLIENT_ID,
'search_method': 'subdomain' if subdomain else 'domain'
}
channel_meta = self._download_json(
'%schannels/%s' % (self._API_BASE, subdomain or domain),
subdomain or domain, "Downloading channel JSON metadata",
query=query)
query.pop('search_method')
channel_id = try_get(channel_meta, lambda x: x['channel']['id'], int)
if channel_id:
category_meta = self._download_json(
'%schannels/%s/categories/%s' % (
self._API_BASE, channel_id, playlist_id),
playlist_id, "Downloading playlist JSON metadata",
query=query)
title = try_get(category_meta, lambda x: x['channel']['category']['name'], compat_str)
category_items_meta = self._download_json(
'%schannels/%s/categories/%s/media' % (
self._API_BASE, channel_id, playlist_id),
playlist_id, "Downloading playlist items JSON metadata",
query=query)
entries = []
for item in category_items_meta['categories']['media']:
entries.append(self.url_result(
'https://%s/media/item/%s' % (
'%s.pivotshare.com' % subdomain if subdomain else domain,
item.get('id')), ie=PivotshareIE.ie_key()))
return self.playlist_result(entries, playlist_id, title)