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

⌈⌋ ⎇ branch:  streamtuner2


Check-in [8c1da4e0f7]

Overview
Comment:Move status.progressbar init and cleanup into GenericChannel.load()
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: 8c1da4e0f7c75d6c834e5cedb4f5c52bceac2cda
User & Date: mario on 2014-05-26 15:32:28
Other Links: manifest | tags
Context
2014-05-26
16:32
Comment out dbg.DATA prints, add some statusbar updating calls. check-in: fd4a1b208c user: mario tags: trunk
15:32
Move status.progressbar init and cleanup into GenericChannel.load() check-in: 8c1da4e0f7 user: mario tags: trunk
14:06
New Freebase topic IDs, fix progressbar for multi-page collecting. check-in: 95166f7d96 user: mario tags: trunk
Changes

Modified channels/_generic.py from [6c89a69b5c] to [80b2da3d25].

182
183
184
185
186
187
188


189
190
191
192
193
194
195
        # load data,
        # update treeview content
        def load(self, category, force=False):
        
            # get data from cache or download
            if (force or not category in self.streams):
                __print__(dbg.PROC, "load", "update_streams")


                new_streams = self.update_streams(category)
      
                if new_streams:

                    # check and modify entry;
                    # assert that title and url are present
                    modified = []







>
>







182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
        # load data,
        # update treeview content
        def load(self, category, force=False):
        
            # get data from cache or download
            if (force or not category in self.streams):
                __print__(dbg.PROC, "load", "update_streams")
                self.parent.status("Updating streams...")
                self.parent.status(-0.1)
                new_streams = self.update_streams(category)
      
                if new_streams:

                    # check and modify entry;
                    # assert that title and url are present
                    modified = []
227
228
229
230
231
232
233


234
235
236
237
238
239
240
            #    self.gtk_list.set_model(self.liststore[category])
            #else:   # currently list is new, had not been converted to gtk array before
            #    self.liststore[category] = \
            mygtk.do(lambda:mygtk.columns(self.gtk_list, self.datamap, self.prepare(self.streams[category])))

            # set pointer
            self.current = category


            pass
            
        # store current streams data
        def save(self):
            conf.save("cache/" + self.module, self.streams, gz=1)









>
>







229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
            #    self.gtk_list.set_model(self.liststore[category])
            #else:   # currently list is new, had not been converted to gtk array before
            #    self.liststore[category] = \
            mygtk.do(lambda:mygtk.columns(self.gtk_list, self.datamap, self.prepare(self.streams[category])))

            # set pointer
            self.current = category
            self.parent.status("")
            self.parent.status(1.0)
            pass
            
        # store current streams data
        def save(self):
            conf.save("cache/" + self.module, self.streams, gz=1)


Modified channels/youtube.py from [2213612999] to [068cf22437].

177
178
179
180
181
182
183
184
185
186
187
188
189
190
191


    # retrieve and parse
    def update_streams(self, cat, force=0, search=None):

        entries = []
        channels = self.categories[self.categories.index("my channels") + 1]
        self.parent.status(-0.1)
        
        # Most Popular
        if cat == "mostPopular":
            #for row in self.api("feeds/api/standardfeeds/%s/most_popular"%conf.youtube_region, ver=2):
            #    entries.append(self.wrap2(row))
            for row in self.api("videos", chart="mostPopular", regionCode=conf.youtube_region):
                entries.append( self.wrap3(row, {"genre": "mostPopular"}) )







<







177
178
179
180
181
182
183

184
185
186
187
188
189
190


    # retrieve and parse
    def update_streams(self, cat, force=0, search=None):

        entries = []
        channels = self.categories[self.categories.index("my channels") + 1]

        
        # Most Popular
        if cat == "mostPopular":
            #for row in self.api("feeds/api/standardfeeds/%s/most_popular"%conf.youtube_region, ver=2):
            #    entries.append(self.wrap2(row))
            for row in self.api("videos", chart="mostPopular", regionCode=conf.youtube_region):
                entries.append( self.wrap3(row, {"genre": "mostPopular"}) )
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
                entries.append( self.wrap3(row, {"genre": ""}) )
        
        # empty entries
        else:
            entries = [dict(title="Placeholder for subcategories", genre="./.", playing="./.", url="http://youtube.com/")]
 
        # done    
        self.parent.status(1.0)
        return entries
        

    
    # Search for channel name:
    def channel_id(self, title):
        id = self.channel2id.get(title)







<







223
224
225
226
227
228
229

230
231
232
233
234
235
236
                entries.append( self.wrap3(row, {"genre": ""}) )
        
        # empty entries
        else:
            entries = [dict(title="Placeholder for subcategories", genre="./.", playing="./.", url="http://youtube.com/")]
 
        # done    

        return entries
        

    
    # Search for channel name:
    def channel_id(self, title):
        id = self.channel2id.get(title)
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
    #-- Retrieve Youtube API query results
    #
    def api(self, method, ver=3, pages=5, **params):
        items = []

        # URL and default parameters
        (base_url, defaults) = self.service[ver]
        #params = dict(  defaults.items() | params.items()  )
        params = dict( defaults, **params )

        # Retrieve data set
        while pages > 0:
            j = ahttp.get(base_url + method, params=params)
            #__print__(dbg.DATA, j)
            if j:
                # json decode







<
|







247
248
249
250
251
252
253

254
255
256
257
258
259
260
261
    #-- Retrieve Youtube API query results
    #
    def api(self, method, ver=3, pages=5, **params):
        items = []

        # URL and default parameters
        (base_url, defaults) = self.service[ver]

        params = dict( list(defaults.items()) + list(params.items())  )

        # Retrieve data set
        while pages > 0:
            j = ahttp.get(base_url + method, params=params)
            #__print__(dbg.DATA, j)
            if j:
                # json decode
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
            elif "pageInfo" in data and data["pageInfo"]["totalResults"] < 50:
                pages = 0
            elif "nextPageToken" in data:
                params["pageToken"] = data["nextPageToken"]
                pages -= 1
            else:
                pages = 0
            self.parent.status( (11 - 1.852 * pages) / 10.0 )

        return items



    # Wrap API 3.0 result into streams row
    def wrap3(self, row, data):







|







275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
            elif "pageInfo" in data and data["pageInfo"]["totalResults"] < 50:
                pages = 0
            elif "nextPageToken" in data:
                params["pageToken"] = data["nextPageToken"]
                pages -= 1
            else:
                pages = 0
            self.parent.status( (10 - 1.852 * pages) / 10.5 )

        return items



    # Wrap API 3.0 result into streams row
    def wrap3(self, row, data):

Modified st2.py from [9efbd2b2e3] to [131924495a].

418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
            sbar_cid = self.get_widget("statusbar").get_context_id("messages")
            # remove text
            while ((not text) and (type(text)==str) and len(sbar_msg)):
                sbar_msg.pop()
                mygtk.do(lambda:self.statusbar.pop(sbar_cid))
            # progressbar
            if (type(text)==float):
                __print__(dbg.PROC, "status.progressbar", float, text)
                if (text >= 999.0/1000):  # completed
                    mygtk.do(lambda:self.progress.hide())
                else:  # show percentage
                    __print__(dbg.PROC, "status.progressbar", dbg.ERR, "fraction")
                    mygtk.do(lambda:self.progress.show() or self.progress.set_fraction(text))
                    if (text <= 0):  # unknown state
                        __print__(dbg.PROC, "status.progressbar", dbg.STAT, "PULSE")
                        mygtk.do(lambda:self.progress.pulse())
            # add text
            elif (type(text)==str):
                sbar_msg.append(1)
                mygtk.do(lambda:self.statusbar.push(sbar_cid, text))
            pass








<



<


<







418
419
420
421
422
423
424

425
426
427

428
429

430
431
432
433
434
435
436
            sbar_cid = self.get_widget("statusbar").get_context_id("messages")
            # remove text
            while ((not text) and (type(text)==str) and len(sbar_msg)):
                sbar_msg.pop()
                mygtk.do(lambda:self.statusbar.pop(sbar_cid))
            # progressbar
            if (type(text)==float):

                if (text >= 999.0/1000):  # completed
                    mygtk.do(lambda:self.progress.hide())
                else:  # show percentage

                    mygtk.do(lambda:self.progress.show() or self.progress.set_fraction(text))
                    if (text <= 0):  # unknown state

                        mygtk.do(lambda:self.progress.pulse())
            # add text
            elif (type(text)==str):
                sbar_msg.append(1)
                mygtk.do(lambda:self.statusbar.push(sbar_cid, text))
            pass