Пример #1
0
 def _update_src_info(self, src):
   """ Update a source's status and song metadata """
   stream_inst = self.get_stream(src)
   if stream_inst is not None:
     src.info = stream_inst.info()
   elif src.input == 'local' and src.id is not None:
     # RCA, name mimics the steam's formatting
     src.info = models.SourceInfo(img_url='static/imgs/rca_inputs.svg', name=f'{src.name} - rca', state='unknown')
   else:
     src.info = models.SourceInfo(img_url='static/imgs/disconnected.png', name='None', state='stopped')
Пример #2
0
    def info(self) -> models.SourceInfo:
        src_config_folder = f"{utils.get_folder('config')}/srcs/{self.src}"
        loc = f'{src_config_folder}/currentSong'
        if not self.logo:
            self.logo = "static/imgs/fmradio.png"
        source = models.SourceInfo(name=self.full_name(),
                                   state=self.state,
                                   img_url=self.logo)
        try:
            with open(loc, 'r') as file:
                data = json.loads(file.read())
                # Example JSON: "station": "Mixx96.1", "callsign": "KXXO", "prog_type": "Soft rock", "radiotext": "        x96.1"
                #print(json.dumps(data))
                if data['prog_type']:
                    source.artist = data['prog_type']
                else:
                    source.artist = self.freq + " FM"

                if data['radiotext']:
                    source.track = data['radiotext']
                else:
                    source.track = self.name

                if data['station']:
                    source.station = data['station']
                elif data['callsign']:
                    source.station = data['callsign']
                else:
                    source.station = ""

                return source
        except Exception:
            pass
            #print('Failed to get currentSong - it may not exist: {}'.format(e))
        return source
Пример #3
0
 def info(self) -> models.SourceInfo:
     src_config_folder = f'{utils.get_folder("config")}/srcs/{self.src}'
     loc = f'{src_config_folder}/.config/pianobar/currentSong'
     source = models.SourceInfo(name=self.full_name(),
                                state=self.state,
                                img_url='static/imgs/pandora.png')
     try:
         with open(loc, 'r') as file:
             for line in file.readlines():
                 line = line.strip()
                 if line:
                     data = line.split(',,,')
                     source.state = self.state
                     source.artist = data[0]
                     source.track = data[1]
                     source.album = data[2]
                     source.img_url = data[3]
                     source.station = data[5]
             return source
     except Exception:
         pass
         #print(error('Failed to get currentSong - it may not exist: {}'.format(e)))
     # TODO: report the status of pianobar with station name, playing/paused, song info
     # ie. Playing: "Cameras by Matt and Kim" on "Matt and Kim Radio"
     return source
Пример #4
0
 def info(self) -> models.SourceInfo:
     src_config_folder = f"{utils.get_folder('config')}/srcs/{self.src}"
     loc = f'{src_config_folder}/currentSong'
     source = models.SourceInfo(name=self.full_name(),
                                state=self.state,
                                img_url=self.logo)
     try:
         with open(loc, 'r') as file:
             data = json.loads(file.read())
             source.artist = data['artist']
             source.track = data['track']
             source.station = data['station']
             return source
     except Exception:
         pass
     return source
Пример #5
0
 def info(self) -> models.SourceInfo:
     src_config_folder = f'{utils.get_folder("config")}/srcs/{self.src}'
     loc = f'{src_config_folder}/currentSong'
     source = models.SourceInfo(name=self.full_name(),
                                state=self.state,
                                img_url='static/imgs/dlna.png')
     try:
         with open(loc, 'r') as file:
             for line in file.readlines():
                 line = line.strip()
                 if line:
                     d = eval(line)
             source.state = d['state']
             source.album = d['album']
             source.artist = d['artist']
             source.track = d['title']
             return source
     except Exception:
         pass
     return source
Пример #6
0
 def info(self) -> models.SourceInfo:
     src_config_folder = f'{utils.get_folder("config")}/srcs/{self.src}'
     loc = f'{src_config_folder}/currentSong'
     source = models.SourceInfo(name=self.full_name(),
                                state=self.state,
                                img_url='static/imgs/spotify.png')
     try:
         with open(loc, 'r') as file:
             d = {}
             for line in file.readlines():
                 try:
                     d = ast.literal_eval(line)
                 except Exception as exc:
                     print(f'Error parsing currentSong: {exc}')
             source.state = d['state']
             source.artist = ', '.join(d['artist'])
             source.track = d['track']
             source.album = d['album']
             source.img_url = d['img_url']
     except Exception:
         pass
     return source
Пример #7
0
 def info(self) -> models.SourceInfo:
     src_config_folder = f'{utils.get_folder("config")}/srcs/{self.src}'
     loc = f'{src_config_folder}/currentSong'
     source = models.SourceInfo(name=self.full_name(), state=self.state)
     source.img_url = 'static/imgs/shairport.png'
     try:
         with open(loc, 'r') as file:
             for line in file.readlines():
                 if line:
                     data = line.split(',,,')
                     for i in range(len(data)):
                         data[i] = data[i].strip('".')
                     source.artist = data[0]
                     source.track = data[1]
                     source.album = data[2]
                     if 'False' in data[3]:
                         source.state = 'playing'
                     else:
                         source.state = 'paused'
                     if int(data[4]):
                         source.img_url = f"/generated/shairport/srcs/{self.src}/{data[5]}"
     except Exception as exc:
         print(f'Failed to get currentSong - it may not exist: {exc}')
     return source
Пример #8
0
 def info(self) -> models.SourceInfo:
     source = models.SourceInfo(name=self.full_name(),
                                state=self.state,
                                img_url='static/imgs/plexamp.png')
     return source