Ejemplo n.º 1
1
    def iter_radios(self):
        document = self.infos.go().doc
        for channel in document.iter('channel'):
            id = channel.get('id')
            radio = Radio(id)
            radio.title = channel.findtext('title')
            radio.description = channel.findtext('description')

            current_data = channel.findtext('lastPlaying')
            current = StreamInfo(0)
            current.what, current.who = self._parse_current(current_data)
            radio.current = current

            radio.streams = []
            stream_id = 0
            for subtag in channel:
                if subtag.tag.endswith('pls'):
                    stream = BaseAudioStream(stream_id)
                    bitrate = subtag.text.replace('http://somafm.com/'+id, '').replace('.pls','')
                    if bitrate != '':
                        stream.bitrate = int(bitrate)
                        bitrate += 'Kbps'
                    else:
                        stream.bitrate = 0
                        bitrate = subtag.tag.replace('pls', '')
                    stream.format = subtag.get('format')
                    stream.title = '%s/%s' % (bitrate, stream.format)
                    stream.url = subtag.text
                    radio.streams.append(stream)
                    stream_id += 1

            yield radio
Ejemplo n.º 2
0
    def iter_radios(self):
        document = self.infos.go().doc
        for channel in document.iter('channel'):
            id = channel.get('id')
            radio = Radio(id)
            radio.title = channel.findtext('title')
            radio.description = channel.findtext('description')

            current_data = channel.findtext('lastPlaying')
            current = StreamInfo(0)
            current.what, current.who = self._parse_current(current_data)
            radio.current = current

            radio.streams = []
            stream_id = 0
            for subtag in channel:
                if subtag.tag.endswith('pls'):
                    stream = BaseAudioStream(stream_id)
                    bitrate = subtag.text.replace('http://somafm.com/' + id,
                                                  '').replace('.pls', '')
                    if bitrate != '':
                        stream.bitrate = int(bitrate)
                        bitrate += 'Kbps'
                    else:
                        stream.bitrate = 0
                        bitrate = subtag.tag.replace('pls', '')
                    stream.format = subtag.get('format')
                    stream.title = '%s/%s' % (bitrate, stream.format)
                    stream.url = subtag.text
                    radio.streams.append(stream)
                    stream_id += 1

            yield radio
Ejemplo n.º 3
0
    def get_radio(self, radio):
        if not isinstance(radio, Radio):
            radio = Radio(radio)

        if not radio.id in self._RADIOS:
            return None

        title, hd = self._RADIOS[radio.id]
        radio.title = title
        radio.description = title

        if hd:
            url = self._MP3_HD_URL % (radio.id, radio.id)
        else:
            url = self._MP3_URL % (radio.id, radio.id)

        # This should be asked demand, but is required for now as Radioob
        # does not require it.
        self.fillobj(radio, ('current', ))

        stream = BaseAudioStream(0)
        if hd:
            stream.bitrate=128
        else:
            stream.bitrate=32
        stream.format=u'mp3'
        stream.title = u'%s kbits/s' % (stream.bitrate)
        stream.url = url
        radio.streams = [stream]
        return radio
Ejemplo n.º 4
0
    def get_radio(self, radio):
        if not isinstance(radio, Radio):
            radio = Radio(radio)

        if radio.id not in self._RADIOS:
            return None

        title, hd = self._RADIOS[radio.id]
        radio.title = title
        radio.description = title

        if hd:
            url = self._MP3_HD_URL % (radio.id, radio.id)
        else:
            url = self._MP3_URL % (radio.id, radio.id)

        # This should be asked demand, but is required for now as Radioob
        # does not require it.
        self.fillobj(radio, ('current', ))

        stream = BaseAudioStream(0)
        if hd:
            stream.bitrate = 128
        else:
            stream.bitrate = 32
        stream.format = u'mp3'
        stream.title = u'%s kbits/s' % (stream.bitrate)
        stream.url = url
        radio.streams = [stream]
        return radio
Ejemplo n.º 5
0
        def create_stream(url, hd=True):
            stream = BaseAudioStream(0)
            if hd:
                stream.bitrate = 128
            else:
                stream.bitrate = 32
                url = url.replace('midfi', 'lofi')

            stream.format = u'mp3'
            stream.title = u'%s kbits/s' % (stream.bitrate)
            stream.url = url
            return stream
Ejemplo n.º 6
0
        def create_stream(url, hd=True):
            stream = BaseAudioStream(0)
            if hd:
                stream.bitrate = 128
            else:
                stream.bitrate = 32
                url = url.replace('midfi128', 'lofi32')

            stream.format = u'mp3'
            stream.title = u'%s kbits/s' % (stream.bitrate)
            stream.url = url
            return stream
Ejemplo n.º 7
0
    def get_stream_info(self, radio, url):
        stream = BaseAudioStream(0)
        current = StreamInfo(0)

        r = self.browser.open(url, stream=True, headers={'Icy-Metadata':'1'})

        stream.bitrate = int(r.headers['icy-br'].split(',')[0])

        r.raw.read(int(r.headers['icy-metaint']))
        size = ord(r.raw.read(1))
        content = r.raw.read(size*16)
        r.close()

        for s in content.split("\x00")[0].split(";"):
            a = s.split("=")
            if a[0] == "StreamTitle":
                stream.title = to_unicode(a[1].split("'")[1])
                res = stream.title.split(" - ")
                current.who = to_unicode(res[0])
                if(len(res) == 1):
                    current.what = ""
                else:
                    current.what = to_unicode(res[1])

        stream.format=u'mp3'
        stream.url = url
        return [stream], current
Ejemplo n.º 8
0
    def get_radio(self, radio):
        if not isinstance(radio, Radio):
            if radio == 'nova':  # old id
                radio = '19577'
            radio = Radio(radio)

        if radio.id not in self.RADIOS:
            return None

        json = self.browser.open('http://www.nova.fr/radio/%s/player' %
                                 radio.id).json()
        radio.title = radio.description = json['radio']['name']

        if 'currentTrack' in json:
            current = StreamInfo(0)
            current.who = json['currentTrack']['artist']
            current.what = json['currentTrack']['title']
            radio.current = current

        stream = BaseAudioStream(0)
        stream.bitrate = 128
        stream.format = 'mp3'
        stream.title = '128kbits/s'
        stream.url = json['radio']['high_def_stream_url']
        radio.streams = [stream]
        return radio
Ejemplo n.º 9
0
    def get_stream_info(self, radio, url):
        stream = BaseAudioStream(0)
        current = StreamInfo(0)

        r = self.browser.open(url, stream=True, headers={'Icy-Metadata': 1})

        stream.bitrate = int(r.headers['icy-br'].split(',')[0])

        r.raw.read(int(r.headers['icy-metaint']))
        size = ord(r.raw.read(1))
        content = r.raw.read(size * 16)
        r.close()

        for s in content.split("\x00")[0].split(";"):
            a = s.split("=")
            if a[0] == "StreamTitle":
                stream.title = to_unicode(a[1].split("'")[1])
                res = stream.title.split(" - ")
                current.who = to_unicode(res[0])
                if (len(res) == 1):
                    current.what = ""
                else:
                    current.what = to_unicode(res[1])

        stream.format = u'mp3'
        stream.url = url
        return [stream], current
Ejemplo n.º 10
0
    def get_radio(self, radio):
        if not isinstance(radio, Radio):
            if radio == 'nova': # old id
                radio = '19577'
            radio = Radio(radio)

        if radio.id not in self.RADIOS:
            return None

        json = self.browser.open('http://www.nova.fr/radio/%s/player' % radio.id).json()
        radio.title = radio.description = json['radio']['name']

        if 'currentTrack' in json:
            current = StreamInfo(0)
            current.who = json['currentTrack']['artist']
            current.what = json['currentTrack']['title']
            radio.current = current

        stream = BaseAudioStream(0)
        stream.bitrate = 128
        stream.format = 'mp3'
        stream.title = '128kbits/s'
        stream.url = json['radio']['high_def_stream_url']
        radio.streams = [stream]
        return radio
Ejemplo n.º 11
0
    def get_radio(self, radio):
        if not isinstance(radio, Radio):
            radio = Radio(radio)

        radioName, network = radio.id.split('.', 1)

        self._fetch_radio_list(network)

        if radioName not in self.RADIOS[network]:
            return None

        radio_dict = self.RADIOS[network][radioName]
        radio.title = radio_dict['name']
        radio.description = radio_dict['name']

        artist, title = self.get_current(network, radioName)
        current = StreamInfo(0)
        current.who = artist
        current.what = title
        radio.current = current

        radio.streams = []
        defaultname = self._get_stream_name(network,
                                            self.config['quality'].get())
        stream = BaseAudioStream(0)
        stream.bitrate = self.NETWORKS[network]['streams'][defaultname]['rate']
        stream.format = self.NETWORKS[network]['streams'][defaultname]['fmt']
        stream.title = u'%s %skbps' % (stream.format, stream.bitrate)
        stream.url = 'http://%s/%s/%s.pls' %\
                     (self.NETWORKS[network]['domain'], defaultname, radioName)
        radio.streams.append(stream)
        i = 1
        for name in self.NETWORKS[network]['streams'].keys():
            if name == defaultname:
                continue
            stream = BaseAudioStream(i)
            stream.bitrate = self.NETWORKS[network]['streams'][name]['rate']
            stream.format = self.NETWORKS[network]['streams'][name]['fmt']
            stream.title = u'%s %skbps' % (stream.format, stream.bitrate)
            stream.url = 'http://%s/%s/%s.pls' % \
                         (self.NETWORKS[network]['domain'], name, radioName)

            radio.streams.append(stream)
            i = i + 1
        return radio
Ejemplo n.º 12
0
    def get_radio(self, radio):
        if not isinstance(radio, Radio):
            radio = Radio(radio)

        radioName, network = radio.id.split('.', 1)

        self._fetch_radio_list(network)

        if not radioName in self.RADIOS[network]:
            return None

        radio_dict = self.RADIOS[network][radioName]
        radio.title = radio_dict['name']
        radio.description = radio_dict['description']

        artist, title = self.get_current(network, radioName)
        current = StreamInfo(0)
        current.who = artist
        current.what = title
        radio.current = current

        radio.streams = []
        defaultname = self._get_stream_name(network, self.config['quality'].get())
        stream = BaseAudioStream(0)
        stream.bitrate = self.NETWORKS[network]['streams'][defaultname]['rate']
        stream.format = self.NETWORKS[network]['streams'][defaultname]['fmt']
        stream.title = u'%s %skbps' % (stream.format, stream.bitrate)
        stream.url = 'http://listen.%s/%s/%s.pls' %\
                     (self.NETWORKS[network]['domain'], defaultname, radioName)
        radio.streams.append(stream)
        i = 1
        for name in self.NETWORKS[network]['streams'].keys():
            if name == defaultname:
                continue
            stream = BaseAudioStream(i)
            stream.bitrate = self.NETWORKS[network]['streams'][name]['rate']
            stream.format = self.NETWORKS[network]['streams'][name]['fmt']
            stream.title = u'%s %skbps' % (stream.format, stream.bitrate)
            stream.url = 'http://listen.%s/%s/%s.pls'%\
                         (self.NETWORKS[network]['domain'], name, radioName)

            radio.streams.append(stream)
            i = i + 1
        return radio
Ejemplo n.º 13
0
    def iter_radios_list(self):
        radio = Radio('necta')
        radio.title = u'Nectarine'
        radio.description = u'Nectarine Demoscene Radio'
        radio.streams = []

        for index, el in enumerate(self.document.xpath('//stream')):
            stream_url = unicode(el.findtext('url'))
            bitrate = el.findtext('bitrate')
            encode = unicode(el.findtext('type'))
            country = unicode(el.findtext('country')).upper()
            stream = BaseAudioStream(index)
            stream.bitrate = int(bitrate)
            stream.format = encode
            stream.title = ' '.join(
                [radio.title, country, encode,
                 unicode(bitrate), 'kbps'])
            stream.url = stream_url
            radio.streams.append(stream)

        yield radio
Ejemplo n.º 14
0
    def iter_radios_list(self):
        radio = Radio('necta')
        radio.title = u'Nectarine'
        radio.description = u'Nectarine Demoscene Radio'
        radio.streams = []

        index = -1

        for el in self.doc.xpath('//stream'):
            index += 1
            stream_url = el.findtext('url')
            bitrate = el.findtext('bitrate')
            encode = el.findtext('type')
            country = el.findtext('country').upper()
            stream = BaseAudioStream(index)
            stream.bitrate = int(bitrate)
            stream.format = encode
            stream.title = ' '.join([radio.title, country, encode, str(bitrate), 'kbps'])
            stream.url = stream_url
            radio.streams.append(stream)

        yield radio
Ejemplo n.º 15
0
    def iter_radios_list(self):
        radio = Radio('necta')
        radio.title = u'Nectarine'
        radio.description = u'Nectarine Demoscene Radio'
        radio.streams = []

        index = -1

        for el in self.document.xpath('//stream'):
            index += 1
            stream_url = unicode(el.findtext('url'))
            bitrate = el.findtext('bitrate')
            encode = unicode(el.findtext('type'))
            country = unicode(el.findtext('country')).upper()
            stream = BaseAudioStream(index)
            stream.bitrate = int(bitrate)
            stream.format = encode
            stream.title = ' '.join([radio.title, country, encode, unicode(bitrate), 'kbps'])
            stream.url = stream_url
            radio.streams.append(stream)

        yield radio
Ejemplo n.º 16
0
    def iter_radios_list(self):
        radio = Radio('nihon')
        radio.title = u'Nihon no Oto'
        radio.description = u'Nihon no Oto: le son du Japon'
        radio.streams = []

        index = -1

        for el in self.document.xpath('//source'):
            index += 1
            mime_type = unicode(el.attrib['type'])
            stream_url = unicode(el.attrib['src'])
            stream = BaseAudioStream(index)
            stream.bitrate = 128
            if (mime_type == u'audio/mpeg'):
                stream.format = u'mp3'
            elif (mime_type == u'audio/ogg'):
                stream.format = u'vorbis'
            stream.title = radio.title + ' ' + mime_type
            stream.url = stream_url
            radio.streams.append(stream)

        yield radio
Ejemplo n.º 17
0
    def iter_radios_list(self):
        radio = Radio('nihon')
        radio.title = u'Nihon no Oto'
        radio.description = u'Nihon no Oto: le son du Japon'
        radio.streams = []

        index = -1

        for el in self.document.xpath('//source'):
            index += 1
            mime_type = unicode(el.attrib['type'])
            stream_url = unicode(el.attrib['src'])
            stream = BaseAudioStream(index)
            stream.bitrate = 128
            if (mime_type == u'audio/mpeg'):
                stream.format = u'mp3'
            elif (mime_type == u'audio/ogg'):
                stream.format = u'vorbis'
            stream.title = radio.title + ' ' + mime_type
            stream.url = stream_url
            radio.streams.append(stream)

        yield radio
Ejemplo n.º 18
0
    def iter_radios_list(self):
        radio = Radio("nihon")
        radio.title = u"Nihon no Oto"
        radio.description = u"Nihon no Oto: le son du Japon"
        radio.streams = []

        index = -1

        for el in self.document.xpath("//source"):
            index += 1
            mime_type = unicode(el.attrib["type"])
            stream_url = unicode(el.attrib["src"])
            stream = BaseAudioStream(index)
            stream.bitrate = 128
            if mime_type == u"audio/mpeg":
                stream.format = u"mp3"
            elif mime_type == u"audio/ogg":
                stream.format = u"vorbis"
            stream.title = radio.title + " " + mime_type
            stream.url = stream_url
            radio.streams.append(stream)

        yield radio
Ejemplo n.º 19
0
    def get_radio(self, radio):
        if not isinstance(radio, Radio):
            radio = Radio(radio)

        if radio.id not in self._RADIOS:
            return None

        title, description, url, bitrate = self._RADIOS[radio.id]
        radio.title = title
        radio.description = description

        artist, title = self.get_current(radio.id)
        current = StreamInfo(0)
        current.who = artist
        current.what = title
        radio.current = current

        stream = BaseAudioStream(0)
        stream.bitrate = bitrate
        stream.format = u"mp3"
        stream.title = u"%skbits/s" % (stream.bitrate)
        stream.url = url
        radio.streams = [stream]
        return radio
Ejemplo n.º 20
0
    def get_radio(self, radio):
        if not isinstance(radio, Radio):
            radio = Radio(radio)

        if radio.id not in self._RADIOS:
            return None

        title, description, url, bitrate = self._RADIOS[radio.id]
        radio.title = title
        radio.description = description

        artist, title = self.get_current(radio.id)
        current = StreamInfo(0)
        current.who = artist
        current.what = title
        radio.current = current

        stream = BaseAudioStream(0)
        stream.bitrate = bitrate
        stream.format = u'mp3'
        stream.title = u'%skbits/s' % (stream.bitrate)
        stream.url = url
        radio.streams = [stream]
        return radio