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

⌈⌋ ⎇ branch:  streamtuner2


Check-in [23f4e4608e]

Overview
Comment:Removed dirble plugin for now (new API coming in April...?)
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: 23f4e4608e07b6f307d7c83872e0e2dc0b72769b
User & Date: mario on 2015-04-02 15:24:56
Other Links: manifest | tags
Context
2015-04-02
15:26
Updated punkcast to display again, also show banners now instead of empty columns, and embedded favicon/png. check-in: 8130cc2cdc user: mario tags: trunk
15:24
Removed dirble plugin for now (new API coming in April...?) check-in: 23f4e4608e user: mario tags: trunk
2015-04-01
20:31
Update documentation files (dependencies and manual installation paths). check-in: 186f91779d user: mario tags: trunk
Changes

Deleted channels/dirble.png version [599481fc0d].

cannot compute difference between binary files

Deleted channels/dirble.py version [8298579c5d].

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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
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
112
113
114
115
116
117
118
119
120
# encoding: UTF-8
# api: streamtuner2
# title: Dirble
# description: Open radio station directory.
# version: 0.2
# type: channel
# category: radio
# config:
#    { name: dirble_api_key,  value: "",  type: text,  description: Custom API access key. },
#    { name: dirble_fetch_homepage,  value: 0,  type: boolean,  description: Also fetch homepages when updating stations. (Rather slow.) }
# priority: optional
# url: http://dirble.com/
# documentation: http://dirble.com/developer/api
#
# Provides a nice JSON API, so is easy to support.
#
# However useful station information (homepage, etc.) only
# with extraneous requests. So just for testing as of now.
#
# ST2 users may have to get a custom Dirble.com key;
# last one got disabled.
#


import re
import json
from config import conf, dbg, __print__
from channels import *
import ahttp as http


# Surfmusik sharing site
class dirble (ChannelPlugin):

    # description
    title = "Dirble"
    module = "dirble"
    has_search = True
    listformat = "audio/x-scpls"
    titles = dict(listeners=False, playing="Location")

    categories = []
    catmap = {}
    
    base = "http://api.dirble.com/v1/%s/apikey/%s/"
    cid = "a0bdd7b8efc2f5d1ebdf1728b65a07ece4c73de5"


    # Retrieve cat list and map
    def update_categories(self):
        self.categories = []
        # Main categories
        for row in self.api("primaryCategories"):
            self.categories.append(row["name"])
            self.catmap[row["name"]] = row["id"]
            # Request subcats
            sub = []
            self.categories.append(sub)
            for subrow in self.api("childCategories", "primaryid", row["id"]):
                sub.append(subrow["name"])
                self.catmap[subrow["name"]] = subrow["id"]


    # Just copy over stream URLs and station titles
    def update_streams(self, cat, search=None):
    
        if cat:
            id = self.catmap.get(cat, 0);
            data = self.api("stations", "id", id)
        elif search:
            data = self.api("search", "search", search)
        else:
            pass

        r = []
        for e in data:
            # skip musicgoal (resolve to just a blocking teaser)
            if e["streamurl"].find("musicgoal") > 0:
                continue
            # append dict after renaming fields
            r.append(dict(
                id = e["id"],
                genre = str(cat),
                status = e["status"],
                title = e["name"],
                playing = e["country"],
                bitrate = self.to_int(e["bitrate"]),
                url = e["streamurl"],
                homepage = e.get("homepage") or self.get_homepage(e["id"], e["name"]),
                format = "audio/mpeg"
            ))
        return r


    # Request homepage for stations, else try to deduce Dirble page
    def get_homepage(self, id, name):
        if conf.dirble_fetch_homepage:
            try:
                return self.api("station", "id", id)["website"]
            except:
                None
        name = re.sub("[^\w\s]+", "", name)
        name = re.sub("\s", "-", name)
        return "http://dirble.com/station/" + name.lower();


    # Patch API url together, send request, decode JSON and whathaveyou
    def api(self, *params):
        method = params[0]
        try:
            j = http.get((self.base % (method, conf.dirble_api_key or self.cid)) + "/".join([str(e) for e in params[1:]]))
            r = json.loads(j);
        except:
            r = []
        if len(r) and "errormsg" in r[0]:
          __print__(dbg.ERR, r[0]["errormsg"]) 
          r = []
        return r


<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<