<reponame>leigh123linux/streamtuner2
# encoding: UTF-8
# api: streamtuner2
# title: iTunes Radio
# description: iTunes unsorted station list via RoliSoft Radio Playlist caching webservice.
# version: 0.1
# type: channel
# category: radio
# url: http://www.itunes.com?
# status: broken
# priority: obsolete
# status: broken
# config: -
# png:
#   <KEY>
#   <KEY>
#   <KEY>EE<KEY>
#   <KEY>
#   <KEY>
#   <KEY>
# documentation: http://lab.rolisoft.net/playlists.html
#
# API provides pre-parsed radio station playlists for various services
#
#  → Shoutcast
#  → Xiph/ICEcast
#  → Tunein
#  → iTunes
#  → FilterMusic
#  → SomaFM
#  → AccuRadio
#  → BBC
#
# In this module only iTunes will be queried for now.
#

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


# Surfmusik sharing site
class itunes (ChannelPlugin):

    # control attribues
    has_search = False
    listformat = "pls"
    titles = dict(listeners=False, bitrate=False, playing=False)
    #base = "http://lab.rolisoft.net/playlists/itunes.php"
    base = "http://aws-eu.rolisoft.net/playlists/itunes.php"
    #base = "http://aws-us.rolisoft.net/playlists/itunes.php"

    categories = [
        "Adult Contemporary",
        "Alternative Rock",
        "Ambient",
        "Blues",
        "Classic Rock",
        "Classical",
        "College",
        "Comedy",
        "Country",
        "Eclectic",
        "Electronica",
        "Golden Oldies",
        "Hard Rock",
        "Hip Hop",
        "International",
        "Jazz",
        "News",
        "Raggae",
        "Religious",
        "RnB",
        "Sports Radio",
        "Top 40",
        "'70s Retro",
        "'80s Flashback",
        "'90s Hits",
    ]
    

    # static list for iTunes
    def update_categories(self):
        pass

    # Just copy over stream URLs and station titles
    def update_streams(self, cat):
    
        m3u = ahttp.get(self.base, {"category": cat.lower()})
        if len(m3u) < 256:
            log.ERR(m3u)
        
        rx_m3u = re.compile(r"""
            ^File(\d+)\s*=\s*(http://[^\s]+)\s*$\s*
            ^Title\1\s*=\s*([^\r\n]+)\s*$\s*
        """, re.M|re.I|re.X)

        r = []
        for e in rx_m3u.findall(m3u):
            r.append(dict(
                genre = cat,
                url = e[1],
                title = e[2],
                format = "audio/mpeg",
                playing = "",
            ))

        return r


# encoding: UTF-8
# api: streamtuner2
# title: iTunes Radio
# description: iTunes unsorted station list via RoliSoft Radio Playlist caching webservice.
# version: 0.1
# type: channel
# category: radio
# url: http://www.itunes.com?
# status: broken
# priority: obsolete
# status: broken
# config: -
# png:
#   <KEY>
#   <KEY>
#   <KEY>EE<KEY>
#   <KEY>
#   <KEY>
#   <KEY>
# documentation: http://lab.rolisoft.net/playlists.html
#
# API provides pre-parsed radio station playlists for various services
#
#  → Shoutcast
#  → Xiph/ICEcast
#  → Tunein
#  → iTunes
#  → FilterMusic
#  → SomaFM
#  → AccuRadio
#  → BBC
#
# In this module only iTunes will be queried for now.
#

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


# Surfmusik sharing site
class itunes (ChannelPlugin):

    # control attribues
    has_search = False
    listformat = "pls"
    titles = dict(listeners=False, bitrate=False, playing=False)
    #base = "http://lab.rolisoft.net/playlists/itunes.php"
    base = "http://aws-eu.rolisoft.net/playlists/itunes.php"
    #base = "http://aws-us.rolisoft.net/playlists/itunes.php"

    categories = [
        "Adult Contemporary",
        "Alternative Rock",
        "Ambient",
        "Blues",
        "Classic Rock",
        "Classical",
        "College",
        "Comedy",
        "Country",
        "Eclectic",
        "Electronica",
        "Golden Oldies",
        "Hard Rock",
        "Hip Hop",
        "International",
        "Jazz",
        "News",
        "Raggae",
        "Religious",
        "RnB",
        "Sports Radio",
        "Top 40",
        "'70s Retro",
        "'80s Flashback",
        "'90s Hits",
    ]
    

    # static list for iTunes
    def update_categories(self):
        pass

    # Just copy over stream URLs and station titles
    def update_streams(self, cat):
    
        m3u = ahttp.get(self.base, {"category": cat.lower()})
        if len(m3u) < 256:
            log.ERR(m3u)
        
        rx_m3u = re.compile(r"""
            ^File(\d+)\s*=\s*(http://[^\s]+)\s*$\s*
            ^Title\1\s*=\s*([^\r\n]+)\s*$\s*
        """, re.M|re.I|re.X)

        r = []
        for e in rx_m3u.findall(m3u):
            r.append(dict(
                genre = cat,
                url = e[1],
                title = e[2],
                format = "audio/mpeg",
                playing = "",
            ))

        return r
# encoding: UTF-8 # api: streamtuner2 # title: iTunes Radio # description: iTunes unsorted station list via RoliSoft Radio Playlist caching webservice. # version: 0.1 # type: channel # category: radio # url: http://www.itunes.com? # status: broken # priority: obsolete # status: broken # config: - # png: #   <KEY> #   <KEY> #   <KEY>EE<KEY> #   <KEY> #   <KEY> #   <KEY> # documentation: http://lab.rolisoft.net/playlists.html # # API provides pre-parsed radio station playlists for various services # #  → Shoutcast #  → Xiph/ICEcast #  → Tunein #  → iTunes #  → FilterMusic #  → SomaFM #  → AccuRadio #  → BBC # # In this module only iTunes will be queried for now. # # Surfmusik sharing site # control attribues #base = "http://lab.rolisoft.net/playlists/itunes.php" #base = "http://aws-us.rolisoft.net/playlists/itunes.php" # static list for iTunes # Just copy over stream URLs and station titles ^File(\d+)\s*=\s*(http://[^\s]+)\s*$\s*             ^Title\1\s*=\s*([^\r\n]+)\s*$\s*