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-03-25 16:34:16 and 2015-04-03 18:39:25

1
2
3
4
5
6
7
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
1
2
3
4
5
6
7
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








+
+






-
+




-











-
+

-
+







Wrting a new plugin is often trivial.
Just create a new `channels/name.py` following this structure:

    # title: MyPlugin
    # description: my radio list
    # version: 0.1
    # type: channel
    # category: radio
    # url: http://www.mymusicstation.com/
    # config: -

    from channels import *

    class myplugin (ChannelPlugin):
        title = "MyNewChannel"
        module = "myplugin"
        homepage = "http://www.mymusicstation.com/"

        has_search = False
        titles = dict(listeners=False)
        categories = []
        catmap = {}
        config = []

        def update_categories(self):
            self.categories = ["Pop", "Rock", "etc"]

        def update_streams(self, cat, search=None):
            entries = []
            # ...
            # get it from somewhere
            # ...        
            return entries

The description block on top is used for the plugin management, and decorative purposes. Some fields like `title` and and `module` are repeated in the class declaration though.
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.

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.
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.

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.

Most plugins will return a list of dicts like:

     {title: Radio123, url: http://pls, genre: Pop, playing: Song123}

72
73
74
75
76
77
78
79

73
74
75
76
77
78
79

80







-
+
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.

  * 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 audio mime type.
  * While `current=""` and `default="Pop"` can specify which category is visible per default, or currently active. (Both will be retired in later versions. More a clutch for current Gtk handling.)
  * Other internal fields are listed in `channels/_generic.py`

To have a new plugin picked up, you need to copy/symlink the file into `/usr/share/streamtuner2/channels/`. It's imported from a local `./channels/` dir though, but the plugin finder currently just looks for the global directory.
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.)