Index: channels/jamendo.py
==================================================================
--- channels/jamendo.py
+++ channels/jamendo.py
@@ -10,14 +10,14 @@
#
import re
import ahttp as http
-from config import conf
+from config import conf, __print__, dbg
from channels import *
from xml.sax.saxutils import unescape
-
+import json
@@ -34,17 +34,20 @@
# description
title = "Jamendo"
module = "jamendo"
homepage = "http://www.jamendo.com/"
- version = 0.2
+ version = 0.3
+ has_search = True
base = "http://www.jamendo.com/en/"
listformat = "url/http"
+ api = "http://api.jamendo.com/v3.0/"
+ cid = "49daa4f5"
- categories = [] #"top 100", "reload category tree!", ["menu > channel > reload.."]]
- titles = dict( title="Artist", playing="Album/Song", bitrate=False, listeners=False )
+ categories = ["radios"]
+ titles = dict( title="Title", playing="Album/Artist/User", bitrate=False, listeners=False )
config = [
{"name":"jamendo_stream_format", "value":"ogg2", "type":"text", "description":"streaming format, 'ogg2' or 'mp31'"}
]
@@ -52,98 +55,94 @@
# refresh category list
def update_categories(self):
- html = http.get(self.base + "tags")
-
- rx_current = re.compile(r"""
- ]+rel="tag"[^>]+href="(http://www.jamendo.com/\w\w/tag/[\w\d]+)"[^>]*>([\w\d]+)
- """, re.S|re.X)
-
-
- #-- categories
- tags = []
- for uu in rx_current.findall(html):
- (href, title) = uu
- tags.append(title)
-
self.categories = [
"radios",
-# "tags", tags
+ "playlists",
+ "albums",
+ "tracks",
+ ["pop", "rock", "dance", "classical", "jazz", "instrumental"]
]
# download links from dmoz listing
- def update_streams(self, cat, force=0):
+ def update_streams(self, cat, search="", force=0):
entries = []
# return a static list for now
if cat == "radios":
entries = [
- {"title": "Pop", "url": "http://streaming.radionomy.com/JamPop", "playing": "", "format": "audio/mpeg", "homepage": "http://www.jamendo.com/en/radios"},
- {"title": "Rock", "url": "http://streaming.radionomy.com/JamRock", "playing": "", "format": "audio/mpeg", "homepage": "http://www.jamendo.com/en/radios"},
- {"title": "Lounge", "url": "http://streaming.radionomy.com/JamLounge", "playing": "", "format": "audio/mpeg", "homepage": "http://www.jamendo.com/en/radios"},
- {"title": "Electro", "url": "http://streaming.radionomy.com/JamElectro", "playing": "", "format": "audio/mpeg", "homepage": "http://www.jamendo.com/en/radios"},
- {"title": "HipHop", "url": "http://streaming.radionomy.com/JamHipHop", "playing": "", "format": "audio/mpeg", "homepage": "http://www.jamendo.com/en/radios"},
- {"title": "World", "url": "http://streaming.radionomy.com/JamWorld", "playing": "", "format": "audio/mpeg", "homepage": "http://www.jamendo.com/en/radios"},
- {"title": "Jazz", "url": "http://streaming.radionomy.com/JamJazz", "playing": "", "format": "audio/mpeg", "homepage": "http://www.jamendo.com/en/radios"},
- {"title": "Metal", "url": "http://streaming.radionomy.com/JamMetal", "playing": "", "format": "audio/mpeg", "homepage": "http://www.jamendo.com/en/radios"},
- {"title": "Soundtrack", "url": "http://streaming.radionomy.com/JamSoundtrack", "playing": "", "format": "audio/mpeg", "homepage": "http://www.jamendo.com/en/radios"},
- {"title": "Relaxation", "url": "http://streaming.radionomy.com/JamRelaxation", "playing": "", "format": "audio/mpeg", "homepage": "http://www.jamendo.com/en/radios"},
- {"title": "Classical", "url": "http://streaming.radionomy.com/JamClassical", "playing": "", "format": "audio/mpeg", "homepage": "http://www.jamendo.com/en/radios"},
- ]
-
- return entries
-
- # top list
- if cat == "top" or cat == "top 100":
- html = http.get(self.base + "top")
-
- rx_top = re.compile("""
- ]+src="(http://imgjam.com/albums/[\w\d]+/\d+/covers/1.\d+.jpg)"
- .*?
-
- \s*]+src="(http://imgjam.com/albums/[\w\d]+/\d+/covers/1.\d+.jpg)"
- .*? /tag/([\w\d]+)"
- """, re.X|re.S)
-
- for uu in rx_tag.findall(html):
- (artist, title, album, album_id, cover, tag) = uu
- entries.append({
- "title": artist,
- "playing": title,
- "homepage": album,
- "url": self.track_url(album_id, conf.jamendo_stream_format, "album"),
- "favicon": self.cover(cover),
- "genre": tag,
- "format": self.stream_mime(),
- })
+ data = http.get(self.api + "tracks", params={
+ "client_id": self.cid,
+ ("fuzzytags" if cat else "search"): (search if search else cat),
+ "format": "json",
+ "audioformat":"mp31",
+ "limit": "200",
+ "imagesize": "50",
+ "order": "popularity_week",
+ })
+ for e in json.loads(data)["results"]:
+ entries.append({
+ "title": e["name"],
+ "playing": e["album_name"] + " / " + e["artist_name"],
+ "favicon": e["album_image"],
+ "homepage": e["shareurl"],
+ "url": e["audio"]
+ })
# done
return entries
@@ -161,8 +160,8 @@
# audio/*
def stream_mime(self):
if conf.jamendo_stream_format.find("og") >= 0:
return "audio/ogg"
else:
- return "audio/mp3"
+ return "audio/mpeg"