Internet radio browser GUI for music/video streams from various directory services.

⌈⌋ branch:  streamtuner2


Diff

Differences From Artifact [e56bcf3be6]:

To Artifact [c6330abad1]:


8
9
10
11
12
13
14
15

16
17
18

19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39


40
41
42


43
44
45


46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71

72



73
74
75
76
77
78

79
80
81
82
83
84
85

86
87
88
89
90
91
92
93
94
95
96











97
98
99
100

101
102
103
104
105





106
107
108
109
110
111


112
113
114
115
116
117
118
119
120
121























122
123
124
125
126
127
128
129
130
131
132
133
134










135
136
137
138
139





140
141
142

143
144

145
146
147
148
149
150
151
8
9
10
11
12
13
14

15
16
17

18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38

39
40
41
42
43
44
45
46


47
48
49
50
51
52
53
54
55
56
57
58
59













60
61
62

63
64
65
66
67
68
69
70

71
72
73
74
75
76
77
78
79











80
81
82
83
84
85
86
87
88
89
90
91
92


93





94
95
96
97
98






99
100










101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126










127
128
129
130
131
132
133
134
135
136





137
138
139
140
141



142


143
144
145
146
147
148
149
150







-
+


-
+




















-
+
+



+
+

-
-
+
+











-
-
-
-
-
-
-
-
-
-
-
-
-


+
-
+
+
+





-
+







+
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+


-
-
+
-
-
-
-
-
+
+
+
+
+
-
-
-
-
-
-
+
+
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+



-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
-
-
-
-
-
+
+
+
+
+
-
-
-
+
-
-
+






# Recently required an API key as well. Thus probably will remain a stub.
#
#


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













# jamendo CC music sharing site
class jamendo (ChannelPlugin):

    # 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'"}
    ]    
    



    # refresh category list
    def update_categories(self):

        html = http.get(self.base + "tags")

        rx_current = re.compile(r"""
             <a\s[^>]+rel="tag"[^>]+href="(http://www.jamendo.com/\w\w/tag/[\w\d]+)"[^>]*>([\w\d]+)</a>
        """, re.S|re.X)


        #-- categories
        tags = []
        for uu in rx_current.findall(html):
            (href, title) = uu
            tags.append(title)
            
        self.categories = [
           "radios",
           "playlists",
#           "tags", tags
           "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": "Best Of", "url": "http://streaming.radionomy.com/BestOf", "playing": "", "format": "audio/mpeg", "homepage": "http://www.jamendo.com/en/radios", "favicon": "http://imgjam1.jamendo.com/new_jamendo_radios/bestof30.jpg"},
                {"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"},
                {"title": "Pop", "url": "http://streaming.radionomy.com/JamPop", "playing": "", "format": "audio/mpeg", "homepage": "http://www.jamendo.com/en/radios", "favicon": "http://imgjam1.jamendo.com/new_jamendo_radios/pop30.jpg"},
                {"title": "Rock", "url": "http://streaming.radionomy.com/JamRock", "playing": "", "format": "audio/mpeg", "homepage": "http://www.jamendo.com/en/radios", "favicon": "http://imgjam1.jamendo.com/new_jamendo_radios/rock30.jpg"},
                {"title": "Lounge", "url": "http://streaming.radionomy.com/JamLounge", "playing": "", "format": "audio/mpeg", "homepage": "http://www.jamendo.com/en/radios", "favicon": "http://imgjam1.jamendo.com/new_jamendo_radios/lounge30.jpg"},
                {"title": "Electro", "url": "http://streaming.radionomy.com/JamElectro", "playing": "", "format": "audio/mpeg", "homepage": "http://www.jamendo.com/en/radios", "favicon": "http://imgjam1.jamendo.com/new_jamendo_radios/electro30.jpg"},
                {"title": "HipHop", "url": "http://streaming.radionomy.com/JamHipHop", "playing": "", "format": "audio/mpeg", "homepage": "http://www.jamendo.com/en/radios", "favicon": "http://imgjam1.jamendo.com/new_jamendo_radios/hiphop30.jpg"},
                {"title": "World", "url": "http://streaming.radionomy.com/JamWorld", "playing": "", "format": "audio/mpeg", "homepage": "http://www.jamendo.com/en/radios", "favicon": "http://imgjam1.jamendo.com/new_jamendo_radios/world30.jpg"},
                {"title": "Jazz", "url": "http://streaming.radionomy.com/JamJazz", "playing": "", "format": "audio/mpeg", "homepage": "http://www.jamendo.com/en/radios", "favicon": "http://imgjam1.jamendo.com/new_jamendo_radios/jazz30.jpg"},
                {"title": "Metal", "url": "http://streaming.radionomy.com/JamMetal", "playing": "", "format": "audio/mpeg", "homepage": "http://www.jamendo.com/en/radios", "favicon": "http://imgjam1.jamendo.com/new_jamendo_radios/metal30.jpg"},
                {"title": "Soundtrack", "url": "http://streaming.radionomy.com/JamSoundtrack", "playing": "", "format": "audio/mpeg", "homepage": "http://www.jamendo.com/en/radios", "favicon": "http://imgjam1.jamendo.com/new_jamendo_radios/soundtrack30.jpg"},
                {"title": "Relaxation", "url": "http://streaming.radionomy.com/JamRelaxation", "playing": "", "format": "audio/mpeg", "homepage": "http://www.jamendo.com/en/radios", "favicon": "http://imgjam1.jamendo.com/new_jamendo_radios/relaxation30.jpg"},
                {"title": "Classical", "url": "http://streaming.radionomy.com/JamClassical", "playing": "", "format": "audio/mpeg", "homepage": "http://www.jamendo.com/en/radios", "favicon": "http://imgjam1.jamendo.com/new_jamendo_radios/classical30.jpg"},
            ]
        
        return entries
    
        # playlist
        # top list
        if cat == "top" or cat == "top 100":
            html = http.get(self.base + "top")

	    rx_top = re.compile("""
        if cat == "playlists":
            data = http.get(self.api + cat, params = {
                "client_id": self.cid,
                "format": "json",
                "limit": "200"
		<img[^>]+src="(http://imgjam.com/albums/[\w\d]+/\d+/covers/1.\d+.jpg)"
		.*?
		<a\stitle="([^"]+)\s*-\s*([^"]+)"\s+class="track_name"\s+href="(http://www.jamendo.com/\w+/track/(\d+))"
	    """, re.X|re.S)

	    for uu in rx_top.findall(html):
            })
            for e in json.loads(data)["results"]:
		(cover, title, artist, track, track_id) = uu
		entries.append({
		    "title": artist,
		    "playing": title,
		    "homepage": track,
		    "url": self.track_url(track_id, conf.jamendo_stream_format),
		    "favicon": self.cover(cover),
		    "format": self.stream_mime(),
		})
		
                entries.append({
                    "title": e["name"],
                    "playing": e["user_name"],
                    "homepage": e["shareurl"],
                    "url": "http://api.jamendo.com/v3.0/playlists/file?client_id="+self.cid+"&id="+e["id"]
                })

        # albums
        if cat == "albums":
            data = http.get(self.api + cat, params = {
                "client_id": self.cid,
                "format": "json",
                "limit": "200",
                "imagesize": "50"
            })
            for e in json.loads(data)["results"]:
                entries.append({
                    "title": e["name"],
                    "playing": e["artist_name"],
                    "favicon": e["image"],
                    "homepage": e["shareurl"],
                    "url": "http://api.jamendo.com/v3.0/playlists/file?client_id="+self.cid+"&id="+e["id"]
                })
		
        # genre list            
        else:
            html = http.get(self.base + "tag/" + cat)
            
            rx_tag = re.compile("""
		<a\s+title="([^"]+)\s*-\s*([^"]+)"
		\s+href="(http://www.jamendo.com/\w+/album/(\d+))"\s*>
		\s*<img[^>]+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):
            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"]:
		(artist, title, album, album_id, cover, tag) = uu
		entries.append({
		    "title": artist,
		    "playing": title,
		    "homepage": album,
                entries.append({
                    "title": e["name"],
                    "playing": e["album_name"] + " / " + e["artist_name"],
                    "favicon": e["album_image"],
                    "homepage": e["shareurl"],
		    "url": self.track_url(album_id, conf.jamendo_stream_format, "album"),
		    "favicon": self.cover(cover),
		    "genre": tag,
                    "url": e["audio"]
		    "format": self.stream_mime(),
		})
                })
 
        # done    
        return entries
        
        
    # smaller album link
    def cover(self, url):
159
160
161
162
163
164
165
166

167
168
158
159
160
161
162
163
164

165
166
167







-
+

	return "http://api.jamendo.com/get2/stream/"+track+"/"+urltype+"/?id="+track_id+"&streamencoding="+fmt

    # audio/*
    def stream_mime(self):
        if conf.jamendo_stream_format.find("og") >= 0:
            return "audio/ogg"
        else:
            return "audio/mp3"
            return "audio/mpeg"