Skip to content

Commit

Permalink
add beatport backend
Browse files Browse the repository at this point in the history
  • Loading branch information
Changaco committed Jan 29, 2013
1 parent 16eccd9 commit cd8f09f
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 9 deletions.
44 changes: 44 additions & 0 deletions media_info/backends/beatport.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
from __future__ import division, print_function, unicode_literals

import json

from ..imports import *


track_id_re = re.compile(r'/track/[^/]*/([0-9]+)')

class beatport_backend(MediaInfoBackend):

DOMAINS = ('beatport.com',)
NAME = 'Beatport'

def get_id(self, url):
track_id = track_id_re.search(url.path)
if not track_id:
raise MediaInfoException(self._('Unrecognized url: %s') % url.geturl())
return track_id.group(1)

def get_info(self, track_id, raw):
r = iNS(type='audio')
info_url = 'http://api.beatport.com/catalog/3/beatport/track?id='
info = iNS(json.loads(urlopen(info_url+track_id).read()))
if raw:
return info
t = iNS(info.results.get('track', None))
if not t:
raise MediaInfoException(self._('Failed to retrieve information for track %s' % (track_id)))
make_author = safe(lambda a: {'name':a['name'], 'urlname':a['slug']})
r.authors = list(filter(None, map(make_author, t.artists)))
waveform = t.images.pop('waveform', identity)
r.artworks = list(t.images.values())
r.beats_per_minute = t.bpm or identity
minutes, seconds = t.length.split(':')
r.duration = int(minutes)*60 + int(seconds)
r.genres = list(filter(None, (g.get('name', None) for g in t.genres)))
r.published = call(parse_date, t.publishDate or identity)
r.thumbnails = call(lambda a: [a], waveform)
r.title = t.title
return r

def normalize(self, track_id):
return 'http://www.beatport.com/track//'+track_id
12 changes: 6 additions & 6 deletions media_info/backends/soundcloud.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,15 @@ def get_info(self, track_id, raw):
if info.kind != 'track':
raise MediaInfoException(self._('%s is a %s, not a track' % (track_id,info.kind)))
r.alternates = call(lambda url: [{'type':'video','url':url}], info.video_url or identity)
r.authors = call(lambda a: [a], info.user['username'])
r.artwork_url = info.artwork_url
make_author = safe(lambda u: {'name':u['username'], 'urlname':u['permalink']})
r.authors = call(lambda a: [a], make_author(info.user or {}))
r.artworks = call(lambda url: [{'url':url}], info.artwork_url)
r.beats_per_minute = info.bpm or identity
r.comment_count = info.comment_count
r.description = info.description
r.duration = info.duration / 1000
r.favorite_count = info.favoritings_count
r.genre = info.genre or identity
r.genres = call(lambda a: [a], info.genre or identity)
r.license = info.license
r.published = call(parse_date, info.created_at)
r.purchase_url = info.purchase_url or identity
Expand All @@ -51,6 +52,5 @@ def get_info(self, track_id, raw):
r.downloads = list(filter(None, [info.download_url, info.stream_url]))
return r

def normalize(self, url):
p = url.path
return ('http://soundcloud.com'+p, p)
def normalize(self, track_id):
return 'http://soundcloud.com/'+track_id
9 changes: 6 additions & 3 deletions media_info/backends/youtube.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from __future__ import print_function, unicode_literals
from __future__ import division, print_function, unicode_literals

from ..imports import *

Expand Down Expand Up @@ -70,8 +70,11 @@ def get_info(self, video_id, raw):
if raw:
return iNS(get_video_info=info, gdata=entry)
elif entry:
authors = (text(author, 'uri').split('/')[-1] for author in getattr(entry, 'author', []))
r.authors = list(filter(None, authors)) or r.authors
make_author = safe(lambda a:
{'name': author.name.text,
'urlname': author.uri.text.split('/')[-1]}
)
r.authors = list(filter(None, map(make_author, getattr(entry, 'author', [])))) or r.authors
r.description = text(entry, 'content')
r.duration = call(int, getattrsi(entry, 'media', 'duration', 'seconds'), r.duration)
r.favorite_count = call(int, getattrsi(entry, 'statistics', 'favorite_count'))
Expand Down

0 comments on commit cd8f09f

Please sign in to comment.