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

⌈⌋ branch:  streamtuner2

Artifact [10c266c14e]

Artifact 10c266c14eea2413852a3dba302d12ac9019ff0f:

# encoding: UTF-8
# api: streamtuner2
# title: SomaFM
# description: Alternative radio, entirely community sponsored and non-advertisey.
# version: 1.0
# type: channel
# category: radio
# url:
# config:
#   { name: somafm_bitrate, value: 64, type: select, select: "130=AAC → 128 kbit/s|64=AAC → 64 kbit/s|32=AAC → 32 kbit/s|0=MP3 → 128 kbit/s|56=MP3 → 56 kbit/s|24=MP3 → 24 kbit/s", description: "Most streams are accessible in different bitrates." }
# priority: extra
# extraction-method: static
# png:
#    50IAxuIkFe9/+NXDP+9JVr++tX3jk2/I29lkV0fd0DY741+z7PC9dz7Ki9XZ8kSrDudKSIBExx3ulVJJL5UcvVkoob0zm8Nzoc0uXnq1Mcuko9NewnkkgvNaMQVCQWirugz4w88/nUyPPrh+M9a9SGAIbVXWPlSmEkIxUeanArnkrLbNepX9vffw2x+/Z2Rni7PP3n0rjuLkxf7R8b+tMVYwaKzIJvuc
#    WkRE1j7dvX/77u0QcKOz8eDxnjk+2L6QDtLfpARXGssKEcVYtQwYcsCuiP74a7zzaB8Yy03DibXWjg+nv/9yz9fsP+NO182ybIRrV5aIA5ONOTw65oJrJQhCX8sYsSH+ZDopns8coyZU3Em8NNrUinMZT56vD+azWAkF1AUAS8vWrwKtnTuYZ97Zui7XdYkXh30GUqDczcPl0ebLg0HlnQZERkikOGFX
#    GuCmbvOynq8KzMoakaNKFMY3r11LtbKOeQYKMCZ4+3xyNWbzower9Vyx0JOI+4/GRWvLgq4Mo1Haq6pcCXBAAtl5bj9+I7313ddfvHkuNpkpKxaskI1Z1rp4NqWtV2ZPT04sAeeFBy4Di8W4rLaeHe+sxJ395aqcXhiN4LXtq6fZGSAQV0gEzMed/mJxmiYi1mIyMz1WV6itZ8G1/TTlqHRZFGVpgrcI
# SomaFM is a non-commercial radio station project.
# Uses a static internal station list. Stream URLs are
# only rewritten depending on bitrate configuration.
# Note that only 64bit AAC and 128bit MP3 are guaranteed
# to be available. Most stations offer different bitrates,
# but not all of them!

from config import *
from channels import *
import re
import ahttp

# SomaFM radio stations
class somafm (ChannelPlugin):

    # description
    has_search = False
    listformat = "pls"
    audioformat = "audio/aac"
    titles = dict(listeners=False, playing="Description")

    categories = ["listen", "support"]
    builtin = [
        {'genre': 'ambient/electronica', 'listeners': 3210, 'title': 'Groove Salad', 'url': '', 'bitrate': 128, 'homepage': '', 'playing': 'A nicely chilled plate of ambient/downtempo beats and grooves.'},
        {'genre': 'ambient', 'listeners': 962, 'title': 'Drone Zone', 'url': '', 'bitrate': 128, 'homepage': '', 'playing': 'Served best chilled, safe with most medications. Atmospheric textures with minimal beats.'},
        {'genre': 'electronica', 'listeners': 571, 'title': 'Space Station Soma', 'url': '', 'bitrate': 128, 'homepage': '', 'playing': 'Tune in, turn on, space out. Spaced-out ambient and mid-tempo electronica.'},
        {'genre': 'alternative/rock', 'listeners': 548, 'title': 'Indie Pop Rocks!', 'url': '', 'bitrate': 128, 'homepage': '', 'playing': 'New and classic favorite indie pop tracks.'},
        {'genre': 'ambient', 'listeners': 459, 'title': 'Deep Space One', 'url': '', 'bitrate': 128, 'homepage': '', 'playing': 'Deep ambient electronic, experimental and space music. For inner and outer space exploration.'},
        {'genre': 'lounge', 'listeners': 445, 'title': 'Secret Agent', 'url': '', 'bitrate': 128, 'homepage': '', 'playing': 'The soundtrack for your stylish, mysterious, dangerous life. For Spies and PIs too!'},
        {'genre': 'ambient/electronica', 'listeners': 415, 'title': 'Groove Salad Classic', 'url': '', 'bitrate': 128, 'homepage': '', 'playing': 'The classic (early 2000s) version of a nicely chilled plate of ambient/downtempo beats and grooves.'},
        {'genre': 'alternative/electronica', 'listeners': 387, 'title': 'Underground 80s', 'url': '', 'bitrate': 128, 'homepage': '', 'playing': 'Early 80s UK Synthpop and a bit of New Wave.'},
        {'genre': 'electronica', 'listeners': 366, 'title': 'Lush', 'url': '', 'bitrate': 128, 'homepage': '', 'playing': 'Sensuous and mellow vocals, mostly female, with an electronic influence.'},
        {'genre': '70s/rock', 'listeners': 355, 'title': 'Left Coast 70s', 'url': '', 'bitrate': 128, 'homepage': '', 'playing': 'Mellow album rock from the Seventies. Yacht not required.'},
        {'genre': 'electronica/specials', 'listeners': 246, 'title': 'DEF CON Radio', 'url': '', 'bitrate': 128, 'homepage': '', 'playing': 'Music for Hacking. The DEF CON Year-Round Channel.'},
        {'genre': 'alternative/rock', 'listeners': 225, 'title': 'BAGeL Radio', 'url': '', 'bitrate': 128, 'homepage': '', 'playing': 'What alternative rock radio should sound like. [explicit]'},
        {'genre': 'folk/alternative', 'listeners': 217, 'title': 'Folk Forward', 'url': '', 'bitrate': 128, 'homepage': '', 'playing': 'Indie Folk, Alt-folk and the occasional folk classics.'},
        {'genre': 'electronica', 'listeners': 190, 'title': 'Beat Blender', 'url': '', 'bitrate': 128, 'homepage': '', 'playing': 'A late night blend of deep-house and downtempo chill.'},
        {'genre': 'world', 'listeners': 156, 'title': 'Suburbs of Goa', 'url': '', 'bitrate': 128, 'homepage': '', 'playing': 'Desi-influenced Asian world beats and beyond.'},
        {'genre': 'americana', 'listeners': 155, 'title': 'Boot Liquor', 'url': '', 'bitrate': 128, 'homepage': '', 'playing': 'Americana Roots music for Cowhands, Cowpokes and Cowtippers'},
        {'genre': 'celtic/world', 'listeners': 155, 'title': 'ThistleRadio', 'url': '', 'bitrate': 128, 'homepage': '', 'playing': 'Exploring music from Celtic roots and branches'},
        {'genre': 'electronica', 'listeners': 145, 'title': 'The Trip', 'url': '', 'bitrate': 128, 'homepage': '', 'playing': 'Progressive house / trance. Tip top tunes.'},
        {'genre': 'alternative', 'listeners': 142, 'title': 'PopTron', 'url': '', 'bitrate': 128, 'homepage': '', 'playing': 'Electropop and indie dance rock with sparkle and pop.'},
        {'genre': 'jazz', 'listeners': 130, 'title': 'Sonic Universe', 'url': '', 'bitrate': 128, 'homepage': '', 'playing': 'Transcending the world of jazz with eclectic, avant-garde takes on tradition.'},
        {'genre': 'electronica/hiphop', 'listeners': 124, 'title': 'Fluid', 'url': '', 'bitrate': 128, 'homepage': '', 'playing': 'Drown in the electronic sound of instrumental hiphop, future soul and liquid trap.'},
        {'genre': 'lounge', 'listeners': 108, 'title': 'Illinois Street Lounge', 'url': '', 'bitrate': 128, 'homepage': '', 'playing': 'Classic bachelor pad, playful exotica and vintage music of tomorrow.'},
        {'genre': 'reggae', 'listeners': 84, 'title': 'Heavyweight Reggae', 'url': '', 'bitrate': 128, 'homepage': '', 'playing': 'NEW! Reggae, Ska, Rocksteady classic and deep tracks.'},
        {'genre': 'electronica', 'listeners': 66, 'title': 'cliqhop idm', 'url': '', 'bitrate': 128, 'homepage': '', 'playing': u"Blips'n'beeps backed mostly w/beats. Intelligent Dance Music."},
        {'genre': 'electronica/alternative', 'listeners': 64, 'title': 'Digitalis', 'url': '', 'bitrate': 128, 'homepage': '', 'playing': 'Digitally affected analog rock to calm the agitated heart.'},
        {'genre': 'electronica', 'listeners': 64, 'title': 'Dub Step Beyond', 'url': '', 'bitrate': 128, 'homepage': '', 'playing': 'Dubstep, Dub and Deep Bass. May damage speakers at high volume.'},
        {'genre': 'oldies', 'listeners': 58, 'title': 'Seven Inch Soul', 'url': '', 'bitrate': 128, 'homepage': '', 'playing': 'Vintage soul tracks from the original 45 RPM vinyl.'},
        {'genre': 'eclectic', 'listeners': 47, 'title': 'Black Rock FM', 'url': '', 'bitrate': 128, 'homepage': '', 'playing': 'From the Playa to the world, for the annual Burning Man festival.'},
        {'genre': 'eclectic', 'listeners': 42, 'title': 'Covers', 'url': '', 'bitrate': 128, 'homepage': '', 'playing': u"Just covers. Songs you know by artists you don't. We've got you covered."},
        {'genre': 'ambient/electronica', 'listeners': 42, 'title': 'Mission Control', 'url': '', 'bitrate': 128, 'homepage': '', 'playing': 'Celebrating NASA and Space Explorers everywhere.'},
        {'genre': 'metal', 'listeners': 32, 'title': 'Metal Detector', 'url': '', 'bitrate': 128, 'homepage': '', 'playing': 'From black to doom, prog to sludge, thrash to post, stoner to crossover, punk to industrial.'},
        {'genre': 'ambient/news', 'listeners': 25, 'title': 'SF 10-33', 'url': '', 'bitrate': 128, 'homepage': '', 'playing': 'Ambient music mixed with the sounds of San Francisco public safety radio traffic.'},
        {'genre': 'specials', 'listeners': 16, 'title': 'SomaFM Specials', 'url': '', 'bitrate': 128, 'homepage': '', 'playing': 'Special, seasonal and experimental broadcasts'},
        {'genre': 'holiday', 'listeners': 10, 'title': 'Christmas Lounge', 'url': '', 'bitrate': 128, 'homepage': '', 'playing': 'Chilled holiday grooves and classic winter lounge tracks. (Kid and Parent safe!)'},
        {'genre': 'holiday', 'listeners': 9, 'title': 'Christmas Rocks!', 'url': '', 'bitrate': 128, 'homepage': '', 'playing': 'Have your self an indie/alternative holiday season!'},
        {'genre': 'specials', 'listeners': 9, 'title': 'SomaFM Live', 'url': '', 'bitrate': 128, 'homepage': '', 'playing': 'Special Live Events and rebroadcasts of past live events'},
        {'genre': 'holiday', 'listeners': 7, 'title': u"Jolly Ol' Soul", 'url': '', 'bitrate': 128, 'homepage': '', 'playing': 'Where we cut right to the soul of the season.'},
        {'genre': 'holiday', 'listeners': 4, 'title': 'Xmas in Frisko', 'url': '', 'bitrate': 128, 'homepage': '', 'playing': u"SomaFM's wacky and eclectic holiday mix. Not for the easily offended."},
        {'genre': 'live/news', 'listeners': 3, 'title': 'SF Police Scanner', 'url': '', 'bitrate': 128, 'homepage': '', 'playing': 'San Francisco Public Safety Scanner Feed'}
    streams = {
    "support": [
        {'genre': 'faq', 'listeners': 6398, 'title': 'Commercial-free, listener supported radio station.', 'url': '', 'format': 'video/youtube', 'bitrate': 256, 'homepage': '', 'playing': 'Unique among music stations, SomaFM depends on community donations to operate. PS: SomaFM Loves You!!'}

    # All static
    def update_categories(self):

    # Just update entries with bitrate setting
    def update_streams(self, cat, search=None):
        if not cat in self.categories:
        elif cat == "listen":
            rows = self.builtin
           # or self._real_parse()
            rows = self.streams[cat]
        # Overwrite bitrate
        bitreal = int(conf.somafm_bitrate) or 128
        biturl = int(conf.somafm_bitrate) or ""
        for i,row in enumerate(rows):
            rows[i]["format"] = "audio/mp3" if bitreal in (128,56,24) else "audio/aac"
            rows[i]["bitrate"] = int(bitreal)
            rows[i]["url"] = re.sub("\d*\.pls$", "%s.pls" % biturl, row["url"])
        # Resend stream list
        return rows

    # Disabled at runtime.
    def _real_parse(self):
        html = ahttp.get("")
        ls = re.findall(r"""
            Listeners: \s* (\d+) \s*--> \s*
            <!-- .*? \(([\w/]+)\) \s* --> .*?
            <h3>  (.+?)  </h3> \s+
            <p[^>]*> (.+?) </p> .*?
        """, html, re.X|re.S)
        rows = [
           dict(genre=g, title=t, playing=p, url=""+u, listeners=int(l), bitrate=128, homepage=""+re.sub("\d*\.pls$", "/", u))
            for l,g,t,p,u in ls
        return rows