1
0
Fork 0
mirror of https://github.com/ytdl-org/youtube-dl.git synced 2024-11-05 00:51:29 +00:00
youtube-dl/youtube_dl/extractor/playfm.py

76 lines
2.5 KiB
Python
Raw Normal View History

2014-08-22 15:34:50 +00:00
# coding: utf-8
from __future__ import unicode_literals
import re
from .common import InfoExtractor
2015-04-02 14:26:05 +00:00
from ..compat import compat_str
from ..utils import (
2014-08-22 15:34:50 +00:00
ExtractorError,
int_or_none,
2015-04-02 14:26:05 +00:00
parse_iso8601,
2014-08-22 15:34:50 +00:00
)
class PlayFMIE(InfoExtractor):
IE_NAME = 'play.fm'
2015-04-02 14:26:05 +00:00
_VALID_URL = r'https?://(?:www\.)?play\.fm/(?P<slug>(?:[^/]+/)+(?P<id>[^/]+))/?(?:$|[?#])'
2014-08-22 15:34:50 +00:00
_TEST = {
2015-04-02 14:26:05 +00:00
'url': 'https://www.play.fm/dan-drastic/sven-tasnadi-leipzig-electronic-music-batofar-paris-fr-2014-07-12',
2014-08-22 15:34:50 +00:00
'md5': 'c505f8307825a245d0c7ad1850001f22',
'info_dict': {
2015-04-02 14:26:05 +00:00
'id': '71276',
2014-08-22 15:34:50 +00:00
'ext': 'mp3',
2015-04-02 14:26:05 +00:00
'title': 'Sven Tasnadi - LEIPZIG ELECTRONIC MUSIC @ Batofar (Paris,FR) - 2014-07-12',
'description': '',
'duration': 5627,
'timestamp': 1406033781,
'upload_date': '20140722',
'uploader': 'Dan Drastic',
'uploader_id': '71170',
2014-08-22 15:34:50 +00:00
'view_count': int,
'comment_count': int,
2014-08-22 15:34:50 +00:00
},
}
def _real_extract(self, url):
mobj = re.match(self._VALID_URL, url)
video_id = mobj.group('id')
2015-04-02 14:26:05 +00:00
slug = mobj.group('slug')
2014-08-22 15:34:50 +00:00
2015-04-02 14:26:05 +00:00
recordings = self._download_json(
'http://v2api.play.fm/recordings/slug/%s' % slug, video_id)
2014-08-22 15:34:50 +00:00
2015-04-02 14:26:05 +00:00
error = recordings.get('error')
if isinstance(error, dict):
raise ExtractorError(
'%s returned error: %s' % (self.IE_NAME, error.get('message')),
expected=True)
2014-08-22 15:34:50 +00:00
2015-04-02 14:26:05 +00:00
audio_url = recordings['audio']
video_id = compat_str(recordings.get('id') or video_id)
title = recordings['title']
description = recordings.get('description')
duration = int_or_none(recordings.get('recordingDuration'))
timestamp = parse_iso8601(recordings.get('created_at'))
uploader = recordings.get('page', {}).get('title')
uploader_id = compat_str(recordings.get('page', {}).get('id'))
view_count = int_or_none(recordings.get('playCount'))
comment_count = int_or_none(recordings.get('commentCount'))
categories = [tag['name'] for tag in recordings.get('tags', []) if tag.get('name')]
2014-08-22 15:34:50 +00:00
return {
'id': video_id,
2015-04-02 14:26:05 +00:00
'url': audio_url,
2014-08-22 15:34:50 +00:00
'title': title,
2015-04-02 14:26:05 +00:00
'description': description,
2014-08-22 15:34:50 +00:00
'duration': duration,
2015-04-02 14:26:05 +00:00
'timestamp': timestamp,
2014-08-22 15:34:50 +00:00
'uploader': uploader,
'uploader_id': uploader_id,
2015-04-02 14:26:05 +00:00
'view_count': view_count,
'comment_count': comment_count,
'categories': categories,
2014-08-22 15:34:50 +00:00
}