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

βŒˆβŒ‹ βŽ‡ branch:  streamtuner2


Check-in [c5e06b031a]

Overview
Comment:Reuse mime_guess+list_guess functions from action.heuristic_funcs
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: c5e06b031a36f2dc495ac040fa236f97934b175a
User & Date: mario on 2017-02-26 21:45:10
Other Links: manifest | tags
Context
2017-02-26
21:45
... and also bump version check-in: b068c34740 user: mario tags: trunk
21:45
Reuse mime_guess+list_guess functions from action.heuristic_funcs check-in: c5e06b031a user: mario tags: trunk
21:44
Collect audio format form URL guessing into new class heuristic_funcs check-in: 7a1577bf74 user: mario tags: trunk
Changes

Modified contrib/radiolist.py from [4692e7b068] to [22b5dbfc08].

42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#   extraction afterwards (instead of a block match).
#
# Β· Entries may contain more than one streaming url. Each accompanied by a
#   bitrate. β†’ Therefore the .best_url() sorting method.
#
# Β· Later versions might of course use multi-urls again…
#
class radiolist (ChannelPlugin):

    # module attributes
    listformat = "pls"
    has_search = False
    categories = ["Europe", "America", "Canada", "Oceania", "Asia"]
    catmap = {"Europe":"", "America":"world", "Canada":"world/canada", "Oceania":"world/oceania", "Asia":"world/asia"}
    titles = dict( genre="Genre", title="Station", playing="Location", bitrate="Bitrate", listeners=False )







|







42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#   extraction afterwards (instead of a block match).
#
# Β· Entries may contain more than one streaming url. Each accompanied by a
#   bitrate. β†’ Therefore the .best_url() sorting method.
#
# Β· Later versions might of course use multi-urls again…
#
class radiolist (ChannelPlugin, action.heuristic_funcs):

    # module attributes
    listformat = "pls"
    has_search = False
    categories = ["Europe", "America", "Canada", "Oceania", "Asia"]
    catmap = {"Europe":"", "America":"world", "Canada":"world/canada", "Oceania":"world/oceania", "Asia":"world/asia"}
    titles = dict( genre="Genre", title="Station", playing="Location", bitrate="Bitrate", listeners=False )
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
121
122
123
124
125
126
            if ut and uu and lg:
                url, br = self.best_url(uu)
                entries.append(dict(
                    homepage = ut[0][0],
                    title = unhtml(ut[0][1]),
                    url = url,
                    bitrate = br,
                    format = self.guess_fmt(url),
                    listformat = self.guess_pls(url),
                    playing = lg[0],
                    genre = lg[1]
                ))
        # done    
        [log.DATA(e) for e in entries]
        return entries

    # pick highest rated URL from [(url,bitrate),…] tuples
    def best_url(self, urls):
        r = dict([(u, to_int(b)) for u,b in urls])  # {url: bitrate, …}
        best = sorted(r, key=r.get, reverse=True)
        return best[0], r[best[0]]

    # see if audio type can be guessed
    def guess_fmt(self, url):
        ext = re.findall("mp3|ogg|wma|aac|mp4", url)
        if ext:
            return mime_fmt(ext[0])
        else:
            return "audio/mpeg"

    # guess PLS/M3U from url
    def guess_pls(self, url):
        ext = re.findall("|".join(action.playlist_fmt_prio), url)
        if ext:
            return ext[0]
        else:
            return "srv"
    







|
|













<
<
<
<
<
<
<
|
<
<
<
<
<
<
<
<
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110







111








            if ut and uu and lg:
                url, br = self.best_url(uu)
                entries.append(dict(
                    homepage = ut[0][0],
                    title = unhtml(ut[0][1]),
                    url = url,
                    bitrate = br,
                    format = self.mime_guess(url, "audio/mpeg"),
                    listformat = self.list_guess(url),
                    playing = lg[0],
                    genre = lg[1]
                ))
        # done    
        [log.DATA(e) for e in entries]
        return entries

    # pick highest rated URL from [(url,bitrate),…] tuples
    def best_url(self, urls):
        r = dict([(u, to_int(b)) for u,b in urls])  # {url: bitrate, …}
        best = sorted(r, key=r.get, reverse=True)
        return best[0], r[best[0]]