Example #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
Example #2
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
Example #3
0
 def get_current_emission(self):
     current = StreamInfo(0)
     current.who = unicode(
         self.document.xpath('//playlist/now/entry/artist')[0].text)
     current.what = unicode(
         self.document.xpath('//playlist/now/entry/song')[0].text)
     return current
Example #4
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
Example #5
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
Example #6
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
Example #7
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
Example #8
0
 def get_current_emission(self):
     current = StreamInfo(0)
     two_or_more = unicode(self.document.xpath('//p')[0].text).split('/////')[0].split(' - ')
     # Consider that if String(' - ') appears it'll be in title rather in the artist name
     if len(two_or_more) > 2:
         current.who = two_or_more.pop(0)
         current.what = ' - '.join(two_or_more)
     else:
         current.who, current.what = two_or_more
     return current
Example #9
0
 def get_current_emission(self):
     current = StreamInfo(0)
     two_or_more = unicode(
         self.document.xpath('//p')[0].text).split('/////')[0].split(' - ')
     # Consider that if String(' - ') appears it'll be in title rather in the artist name
     if len(two_or_more) > 2:
         current.who = two_or_more.pop(0)
         current.what = ' - '.join(two_or_more)
     else:
         current.who, current.what = two_or_more
     return current
Example #10
0
 def fill_radio(self, radio, fields):
     if 'current' in fields:
         radioName, network = radio.id.split('.', 1)
         radio.current = StreamInfo(0)
         radio.current.who, radio.current.what = self.get_current(
             network, radioName)
         return radio
Example #11
0
 def fill_radio(self, radio, fields):
     if 'current' in fields:
         artist = title = None
         if radio.id in self._PLAYERJS_RADIOS:
             artist, title = self.browser.get_current_playerjs(radio.id)
             if title.endswith(u'par %s' % artist):
                 artist = None
         if radio.id in self._DIRECTJSON_RADIOS:
             dartist, dtitle = self.browser.get_current_direct(radio.id)
             if dartist:
                 artist = dartist
             if dtitle:
                 if title:
                     title = u"%s [%s]" % (dtitle, title)
                 else:
                     title = dtitle
         elif radio.id in self._LARGEDIRECTJSON_RADIOS:
             dartist, dtitle = self.browser.get_current_direct_large(
                 radio.id)
             if dartist:
                 artist = dartist
             if dtitle:
                 title = dtitle
         if radio.id in self._RSS_RADIOS:
             title = self.browser.get_current_rss(radio.id)
         if title:
             if not radio.current or radio.current is NotLoaded:
                 radio.current = StreamInfo(0)
             radio.current.what = title
             radio.current.who = artist
     return radio
Example #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 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
Example #13
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
Example #14
0
 def fill_radio(self, radio, fields):
     if 'current' in fields:
         title = self._RADIOS[radio.id]['title']
         live_url = self._RADIOS[radio.id]['live']
         radio_name = radio.id if not radio.id.startswith('fb') else 'francebleu'
         artist, title = self.browser.get_current(radio_name, live_url)
         if not radio.current or radio.current is NotLoaded:
             radio.current = StreamInfo(0)
         radio.current.what = title
         radio.current.who = artist
     return radio
Example #15
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
Example #16
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
Example #17
0
 def get_current_emission(self):
     current = StreamInfo(0)
     current.who = unicode(self.document.xpath('//playlist/now/entry/artist')[0].text)
     current.what = unicode(self.document.xpath('//playlist/now/entry/song')[0].text)
     return current
Example #18
0
 def fill_radio(self, radio, fields):
     if 'current' in fields:
         if not radio.current:
             radio.current = StreamInfo(0)
         radio.current.who, radio.current.what = self.get_current(radio.id)
     return radio