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

⌈⌋ ⎇ branch:  streamtuner2


Changes To write a plugin

Changes to "write a plugin" between 2015-04-05 22:25:57 and 2015-04-14 10:06:35

28
29
30
31
32
33
34


35
36
37
38
39
40
41
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43







+
+







            # ...        
            return entries

### Plugin meta block

The description block on top is used for the [plugin management](wiki/plugin+meta+data) (and documentative purposes). This is meant to cleanly separate in-application values (like .module or .has_search, .catmap) from attributes that just serve initialization.

All fields show up in `self.meta`, for instance the `meta["title"]` or `meta["url"]` are occasionally used. The `config[]` entry is a list/dict combination, and its defaults automatically thrown into `conf.*` variables. Therefore plugins can use their settings right away (e.g. `conf.myplugin_bitrate=128`)

### update_categories()

Each plugin needs a `update_categories()` method. This can be a stub, if the channel plugin has a static list of genres. If so, just set the `categories = [...]` declaration right away. The method is only used if the default categories list is empty, needs to be renewed from the service (e.g. whenever the menu entry Channel>Update_categories is used). There's also a `catmap={}` dict in case category/genre titles have to be associated with service ids.

### update_streams()

More importantly you need the `update_streams()` method to fetch station lists. It receives a `cat` parameter, for instance `"Pop"`. Then do whatever API query or website scraping (regex/pyquery) is necessary to populate a list.
77
78
79
80
81
82
83

84



85


86
87
88
89
90















91
92
93
94
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







+
-
+
+
+

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





### conf. options

You can access your <kbd>config:</kbd> options per the global `conf.*` dict. Take care to prefer unambigious names like `conf.myplugin_pagesize` etc.

### Attributes

There are a couple of other attributes.
The `has_search` class flag permits live server searches. If one is issued, the `update_streams()` method will be called with `cat=None` and `search="Find me maybe"` set instead.

 - **has_search** = False
   This flag documents if live server searches are available. If it's supported, then the `update_streams()` method will can called with `cat=None` and `search="Find me maybe"` set instead; and it's then responsible to do some searching.

 - **audioformat** = "audio/mpeg"  
   Sets the default audio stream type for this channel. (Note that each individual stream entry may carry its own `format` attribute, jsut in case.)
  * Other class options include `listformat="audio/x-scpls"` for declaring the station URL mime type (here `pls` for example).
  * And `audioformat="audio/mpeg"` for the default audio mime type.
  * While `default="Pop"` can specify which category is visible per default. (Will be retired in later versions. More a clutch for current Gtk handling.)
  * With `titles = dict(listeners=False)` you simply rename one of the default columns. You can also rename them with e.g. `titles = dict(playing="Current Song", genre="Group", title="Artist")` for example.
  * Other internal fields are listed in `channels/_generic.py`

 - **listformat** = "pls"  
   Declares the channel service playlist type. Can be either "pls" or "m3u" or "xspf" if the server is super modern. It's also possible to use "href" here, if 
you can't be sure of audio or playlist format types. And "srv" if the provider has a clean list of direct streaming URLs only.

 - **default** = "Pop"  
   Is obsolete. Used to specify the first shown category. (That was a workaround for initial crude Gtk handling.)

 - **titles =** `dict(listeners=False)`  
   This defines which station column titles to show. There are title=, genre= which you commonly have. And there is playing= or bitrate= and homepage= which you can omit by setting it to `=False`. Alternatively just rename them with `playing="Artist/Album name`.

 - **datamap** = `[...]`  
   If you want some complexity, column title renaming, and using custom row attributes can be accomplished with a Gtk TreeView datamap. No, you don't want to do that.

 - Other internal fields are listed in `channels/_generic.py`

### Installation

To have a new plugin picked up, you need to copy/symlink the file into `/usr/share/streamtuner2/channels/`. It's imported from the `channels` module group automatically. Which allows relocatability, and later even local plugins. (Which is commonly unneeded featuritis though. So not yet implemented.)