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

⌈⌋ ⎇ branch:  streamtuner2


Artifact [6c7e3b19fe]

Artifact 6c7e3b19fef7f14f2d0519bb920a4bd63e2b775e:

  • File channels/global_key.py — part of check-in [ea628d6426] at 2015-04-08 17:59:53 on branch trunk — Remove extraneous class wrapper action.action. Start to regroup listformat mapping (pls-url → m3u-fn rewrites). Will need some heuristics, as depending just on the channel.listformat assumption won't work in practice (some .pls servers actually host direct server links, or occasionally .m3u references even). Currently does nothing, just returns the pls/etc URL. (user: mario, size: 2371) [annotate] [blame] [check-ins using] [more...]

# api: streamtuner2
# title: Global keyboard shortcut
# description: Allows switching between bookmarked radios via key press.
# type: feature
# category: ui
# version: 0.3
# config:
#    { name="switch_key", type="text", value="XF86Forward", description="Global key shortcut for switching radio." },
#    { name="switch_channel", type="text", value="bookmarks:favourite", description="Station list and channels to alternate in." },
#    { name="switch_random", type="boolean", value=0, description="Pick random channel, instead of next." },
# priority: extra
# depends: python-keybinder
#
#
# Binds a key to global desktop (F13 = left windows key).
# On keypress switches the currently playing radio station
# to another one from the bookmarks list.
#
# Valid key names are `F9`, `<Ctrl>G`, `<Alt>R` for example.


import keybinder
from config import *
import action
import random



# register a key
class global_key(object):

    module = "global_key"
    title = "keyboard shortcut"
    meta = plugin_meta()
    last = 0


    # register
    def __init__(self, parent):
        self.parent = parent
        conf.add_plugin_defaults(self.meta, self.module)
        try:
            for i,keyname in enumerate(conf.switch_key.split(",")):    # allow multiple keys
                keybinder.bind(keyname, self.switch, ((-1 if i else +1)))   # forward +1 or backward -1
        except:
            __print__(dbg.ERR, "plugin global_key: Key `%s` could not be registered" % conf.switch_key)
    
        
    # key event
    def switch(self, num, *any):
        
        # bookmarks, favourite
        channel, cat = conf.switch_channel.split(":")

        # get list
        streams = self.parent.channels[channel].streams[cat]

        # pickrandom
        if conf.switch_random:
            self.last = random.randint(0, len(streams)-1)

        # or iterate over list
        else:
            self.last = self.last + num
            if self.last >= len(streams):
                self.last = 0
            elif self.last < 0:
                self.last = len(streams)-1
            
        # play
        i = self.last
        action.play(streams[i]["url"], streams[i]["format"])

        # set pointer in gtk.TreeView
        if self.parent.channels[channel].current == cat:
            self.parent.channels[channel].gtk_list.get_selection().select_path(i)