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

⌈⌋ ⎇ branch:  streamtuner2


Check-in [7965619312]

Overview
Comment:Initial support for Dirble.com, provides grouped categories and search feature.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: 7965619312b1705e5d4677b45b9447df85e67796
User & Date: mario on 2014-08-01 01:35:02
Other Links: manifest | tags
Context
2014-08-05
02:39
Ah, Shoutcast, switching again. → HTML extraction is now JS lexing → {genreid:} is now {genrename:} check-in: 4836962bd4 user: mario tags: trunk
2014-08-01
01:35
Initial support for Dirble.com, provides grouped categories and search feature. check-in: 7965619312 user: mario tags: trunk
01:34
catmap{} cache handling now by _generic module check-in: cda3504633 user: mario tags: trunk
Changes

Added channels/dirble.png version [059e34c558].

cannot compute difference between binary files

Added channels/dirble.py version [0d33a5ff54].



















































































































































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
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
# encoding: UTF-8
# api: streamtuner2
# title: Dirble
# description: New open radio station directory.
# version: 0.1
# type: channel
# category: radio
# priority: optional
# 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.
#
#


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"
    homepage = "http://dirble.com/"
    has_search = True
    listformat = "audio/x-scpls"
    titles = dict(listeners=False, playing="Location")

    categories = []
    config = [
        {"name": "dirble_fetch_homepage",
         "value": 0,
         "type": "boolean",
         "description": "Also fetch homepages when updating stations. (This is slow, as it requires one extra request for each.)"
        }
    ]    
    catmap = {}
    
    base = "http://api.dirble.com/v1/%s/apikey/%s/"
    cid = "84be582567ff418c9ba94d90d075d7fee178ad60"

    # 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", str(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", str(id)])
        elif search:
            data = self.api("search", ["search", search])
        else:
            pass

        r = []
        for e in data:
            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:
            return self.api("station", ["id", str(id)])["website"]
        else:
            name = re.sub("[^\w\s]+", "", name)
            name = re.sub("\s", "-", name)
            return "http://dirble.com/station/" + name.lower();

    # Patch together
    def api(self, method, params=[]):
        j = http.get((self.base % (method, self.cid)) + "/".join([str(e) for e in params]))
        r = json.loads(j);
        return r