2020-03-03 12:27:13 -08:00
|
|
|
# coding: utf-8
|
|
|
|
from __future__ import unicode_literals
|
|
|
|
|
|
|
|
from .common import InfoExtractor
|
|
|
|
|
|
|
|
|
|
|
|
class PonyFMIE(InfoExtractor):
|
|
|
|
"""
|
|
|
|
InfoExtractor for PonyFM
|
|
|
|
|
|
|
|
This extractor is for tracks. Playlists and Albums may be defined at a later
|
|
|
|
point using a separate class that will be in this file.
|
|
|
|
"""
|
|
|
|
_VALID_URL = r'https?://pony\.fm/tracks/(?P<id>\d+)-.+'
|
2020-03-05 17:01:52 -08:00
|
|
|
_TESTS = [{
|
|
|
|
'url': 'https://pony.fm/tracks/43462-summer-wind-fallout-equestria-skybolt',
|
|
|
|
'info_dict': {
|
|
|
|
'id': '43462',
|
|
|
|
'ext': 'flac',
|
|
|
|
'title': 'Summer Wind (Fallout: Equestria) - SkyBolt',
|
|
|
|
'uploader': 'SkyBoltsMusic',
|
|
|
|
}
|
|
|
|
}, {
|
|
|
|
'url': 'https://pony.fm/tracks/43852-kirin-ts',
|
|
|
|
'info_dict': {
|
|
|
|
'id': '43852',
|
|
|
|
'ext': 'mp3',
|
|
|
|
'title': 'KIRIN TS',
|
|
|
|
'uploader': '7TAIL3DFOXX'
|
|
|
|
}
|
|
|
|
}]
|
2020-03-03 12:27:13 -08:00
|
|
|
|
|
|
|
def _real_extract(self, url):
|
|
|
|
track_id = self._match_id(url)
|
|
|
|
|
2020-03-04 23:37:29 -08:00
|
|
|
# Extract required fields from JSON API
|
|
|
|
apiurl = "https://pony.fm/api/web/tracks/%s" % track_id
|
|
|
|
json = self._download_json(apiurl, track_id)['track']
|
|
|
|
|
|
|
|
title = json['title']
|
2020-03-03 12:27:13 -08:00
|
|
|
formats = []
|
2020-03-04 23:37:29 -08:00
|
|
|
for f in json['formats']:
|
|
|
|
formats.append({
|
|
|
|
'format': f['name'],
|
|
|
|
'url': f['url'],
|
|
|
|
})
|
2020-03-03 12:27:13 -08:00
|
|
|
|
|
|
|
extracted = {
|
|
|
|
'id': track_id,
|
|
|
|
'title': title,
|
|
|
|
'formats': formats,
|
|
|
|
}
|
|
|
|
|
2020-03-04 23:37:29 -08:00
|
|
|
# Extract optional metadata (author, album art) from JSON API
|
|
|
|
author = json.get('user', {}).get('name')
|
|
|
|
artwork = json.get('covers', {}).get('original')
|
2020-03-03 12:27:13 -08:00
|
|
|
|
|
|
|
if artwork:
|
|
|
|
extracted['thumbnail'] = artwork
|
|
|
|
if author:
|
|
|
|
extracted['uploader'] = author
|
|
|
|
|
|
|
|
return extracted
|