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

⌈⌋ ⎇ branch:  streamtuner2


Check-in [ca359689bf]

Overview
Comment:Reorganized Jamendo plugin to simplify API calls.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: ca359689bf6ba1f0b6ba6f35eb43629c74bdaa95
User & Date: mario on 2014-05-26 21:18:31
Other Links: manifest | tags
Context
2014-05-27
00:42
Jamendo stream format selection now uses dropdown too. check-in: 53b4c85039 user: mario tags: trunk
2014-05-26
21:18
Reorganized Jamendo plugin to simplify API calls. check-in: ca359689bf user: mario tags: trunk
20:21
Shoutcast: retry regex/dom really alternatively now (not just on exceptions, but also empty result sets) check-in: 61a51c29f9 user: mario tags: trunk
Changes

Modified channels/jamendo.py from [c602d9f7b7] to [2da2079266].

49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
    module = "jamendo"
    homepage = "http://www.jamendo.com/"
    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 = ["radios"]

    titles = dict( title="Title", playing="Album/Artist/User", bitrate=False, listeners=False )
 
    config = [







|







49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
    module = "jamendo"
    homepage = "http://www.jamendo.com/"
    version = 0.3
    has_search = True

    base = "http://www.jamendo.com/en/"
    listformat = "url/http"
    api_base = "http://api.jamendo.com/v3.0/"
    cid = "49daa4f5"

    categories = ["radios"]

    titles = dict( title="Title", playing="Album/Artist/User", bitrate=False, listeners=False )
 
    config = [
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
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168

169
170
171
172
173
174
175
176
177
178
179

180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198





199




200








201




202
203
204
205
206
207
208
209
210
211
212
213
214
215

    # retrieve category or search
    def update_streams(self, cat, search="", force=0):

        entries = []
        fmt = self.stream_mime(conf.jamendo_stream_format)
        
        # return a static list for now
        if cat == "radios":
        
            entries = []
            for radio in ["BestOf", "Pop", "Rock", "Lounge", "Electro", "HipHop", "World", "Jazz", "Metal", "Soundtrack", "Relaxation", "Classical"]:
                entries.append({
                    "genre": radio,
                    "title": radio,
                    "url": "http://streaming.radionomy.com/Jam" + radio,
                    "playing": "various artists",
                    "format": "audio/mpeg",
                    "homepage": "http://www.jamendo.com/en/radios",
                    "img": "http://imgjam1.jamendo.com/new_jamendo_radios/%s30.jpg" % radio.lower(),
                })
        
        # playlist
        elif cat == "playlists":
            for offset in self.retrieval_offsets():
                data = http.get(self.api + cat, params = {
                    "client_id": self.cid,
                    "format": "json",
                    "audioformat": conf.jamendo_stream_format,
                    "limit": "200",
                    "offset": offset,
                    "order": "creationdate_desc",
                })
                for e in json.loads(data)["results"]:
                    entries.append({
                        "title": e["name"],
                        "playing": e["user_name"],
                        "homepage": e["shareurl"],
                        #"url": "http://api.jamendo.com/v3.0/playlists/file?client_id=%s&id=%s" % (self.cid, e["id"]),
                        "url": "http://api.jamendo.com/get2/stream/track/xspf/?playlist_id=%s&n=all&order=random&from=app-%s" % (e["id"], self.cid),
                        "format": "application/xspf+xml",
                    })
                self.parent.status(float(offset)/float(1000))

        # albums
        elif cat in ["albums", "newest"]:
            for offset in self.retrieval_offsets():
                data = http.get(self.api + "albums/musicinfo", params = {
                    "client_id": self.cid,
                    "format": "json",
                    "audioformat": conf.jamendo_stream_format,
                    "limit": "200",
                    "offset": offset,
                    "imagesize": "50",
                    "order": ("popularity_week" if cat == "albums" else "releasedate_desc"),
                })
                for e in json.loads(data)["results"]:
                    entries.append({
                        "genre": " ".join(e["musicinfo"]["tags"]),
                        "title": e["name"],
                        "playing": e["artist_name"],
                        "img": e["image"],
                        "homepage": e["shareurl"],
                        #"url": "http://api.jamendo.com/v3.0/playlists/file?client_id=%s&id=%s" % (self.cid, e["id"]),
                        "url": "http://api.jamendo.com/get2/stream/track/xspf/?album_id=%s&streamencoding=ogg2&n=all&from=app-%s" % (e["id"], self.cid),
                        "format": "application/xspf+xml",
                    })
                self.parent.status(float(offset)/float(1000))
		
        # genre list
        else:
            for offset in self.retrieval_offsets():

                data = http.get(self.api + "tracks", params={
                    "client_id": self.cid,
                    ("fuzzytags" if cat else "search"): (search if search else cat),
                    "format": "json",
                    "audioformat": conf.jamendo_stream_format,
                    "limit": "200",
                    "offset": offset,
                    "imagesize": conf.jamendo_image_size,
                    "order": "popularity_week",
                    "include": "musicinfo",
                })

                for e in json.loads(data)["results"]:
                    entries.append({
                        "lang": e["musicinfo"]["lang"],
                        "genre": " ".join(e["musicinfo"]["tags"]["genres"]),
                        "extra": ", ".join(e["musicinfo"]["tags"]["vartags"]),
                        "title": e["name"],
                        "playing": e["album_name"] + " / " + e["artist_name"],
                        "img": e["album_image"],
                        "homepage": e["shareurl"],
                        #"url": e["audio"],
                        "url": "http://storage-new.newjamendo.com/?trackid=%s&format=ogg2&u=0&from=app-%s" % (e["id"], self.cid),
                        "format": fmt,
                    })
                self.parent.status(float(offset)/float(1000))
 
        # done    
        return entries

    





    # offset list [0, 200, 400, 600, ...] according to max retrieval count




    def retrieval_offsets(self):








        return [200*1 for i in range(0, int(conf.jamendo_count))]




        

    # audio/*
    def stream_mime(self, name):
        map = {
            "ogg": "audio/ogg", "ogg2": "audio/ogg",
            "mp3": "audio/mpeg", "mp31": "audio/mpeg", "mp33": "audio/mpeg",
            "flac": "audio/flac"
        }
        if name in map:
            return map[name]
        else:
            return map["mp3"]








|

<
<











|

<
<
<
<
<
<
<
|
<
<
|
|
|
|
|
|
|
|
<

|

<
|
<
|
<
<
|
<
|
<
|
|
|
|
|
|
|
|
|
|
|
<

|

<
>
|
<
|
<
|
<
|
<
<
<
<
>
|
|
|
|
|
|
|
|
|
|
|
|
|
<





>
>
>
>
>
|
>
>
>
>
|
>
>
>
>
>
>
>
>
|
>
>
>
>






|







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

152

153




154
155
156
157
158
159
160
161
162
163
164
165
166
167

168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210

    # retrieve category or search
    def update_streams(self, cat, search="", force=0):

        entries = []
        fmt = self.stream_mime(conf.jamendo_stream_format)
        
        # Static list of Radios
        if cat == "radios":


            for radio in ["BestOf", "Pop", "Rock", "Lounge", "Electro", "HipHop", "World", "Jazz", "Metal", "Soundtrack", "Relaxation", "Classical"]:
                entries.append({
                    "genre": radio,
                    "title": radio,
                    "url": "http://streaming.radionomy.com/Jam" + radio,
                    "playing": "various artists",
                    "format": "audio/mpeg",
                    "homepage": "http://www.jamendo.com/en/radios",
                    "img": "http://imgjam1.jamendo.com/new_jamendo_radios/%s30.jpg" % radio.lower(),
                })
        
        # Playlist
        elif cat == "playlists":







            for e in self.api(method = cat, order = "creationdate_desc"):


                entries.append({
                    "title": e["name"],
                    "playing": e["user_name"],
                    "homepage": e["shareurl"],
                    #"url": "http://api.jamendo.com/v3.0/playlists/file?client_id=%s&id=%s" % (self.cid, e["id"]),
                    "url": "http://api.jamendo.com/get2/stream/track/xspf/?playlist_id=%s&n=all&order=random&from=app-%s" % (e["id"], self.cid),
                    "format": "application/xspf+xml",
                })


        # Albums
        elif cat in ["albums", "newest"]:

            if cat == "albums":

                order = "popularity_week"


            else:

                order = "releasedate_desc"

            for e in self.api(method = "albums/musicinfo", order = order, include = "musicinfo"):
                entries.append({
                    "genre": " ".join(e["musicinfo"]["tags"]),
                    "title": e["name"],
                    "playing": e["artist_name"],
                    "img": e["image"],
                    "homepage": e["shareurl"],
                    #"url": "http://api.jamendo.com/v3.0/playlists/file?client_id=%s&id=%s" % (self.cid, e["id"]),
                    "url": "http://api.jamendo.com/get2/stream/track/xspf/?album_id=%s&streamencoding=ogg2&n=all&from=app-%s" % (e["id"], self.cid),
                    "format": "application/xspf+xml",
                })

		
        # Genre list, or Search
        else:

            if cat:
                data = self.api(method = "tracks", order = "popularity_week", include = "musicinfo", fuzzytags = cat, audioformat = conf.jamendo_stream_format)

            elif search:

                data = self.api(method = "tracks", order = "popularity_week", include = "musicinfo", search = search, audioformat = conf.jamendo_stream_format)

            else:




                data = []
            for e in data:
                entries.append({
                    "lang": e["musicinfo"]["lang"],
                    "genre": " ".join(e["musicinfo"]["tags"]["genres"]),
                    "extra": ", ".join(e["musicinfo"]["tags"]["vartags"]),
                    "title": e["name"],
                    "playing": e["album_name"] + " / " + e["artist_name"],
                    "img": e["album_image"],
                    "homepage": e["shareurl"],
                    #"url": e["audio"],
                    "url": "http://storage-new.newjamendo.com/?trackid=%s&format=ogg2&u=0&from=app-%s" % (e["id"], self.cid),
                    "format": fmt,
                })

 
        # done    
        return entries

    
    # Collect data from Jamenda API
    def api(self, method, **params):
        r = []
        max = 200 * int(conf.jamendo_count)
        params = dict(
            list({
                "client_id": self.cid,
                "format": "json",
                "audioformat": "mp32",
                "imagesize": conf.jamendo_image_size,
                "offset": 0,
                "limit": 200,
            }.items()) + list(params.items())
        )
        while (params["offset"] < max) and (len(r) % 200 == 0):
            data = json.loads(http.get(self.api_base + method, params))
            if data and "results" in data:
                r += data["results"]
            else:
                return r
            params["offset"] += 200;
            self.parent.status(float(params["offset"])/float(max+17))
            __print__(dbg.PROC, params["offset"], max, len(r))
        return r
        

    # audio/*
    def stream_mime(self, name):
        map = {
            "ogg": "audio/ogg", "ogg2": "audio/ogg",
            "mp3": "audio/mpeg", "mp31": "audio/mpeg", "mp32": "audio/mpeg",
            "flac": "audio/flac"
        }
        if name in map:
            return map[name]
        else:
            return map["mp3"]