Esempio n. 1
0
 def f(id):
     """Load the album and show it."""
     try:
         album = application.api.get_album_info(id)
         wx.CallAfter(self.add_results, album.get('tracks', []), showing = '%s - %s' % (album.get('artist', 'Unknown Artist'), album.get('name', 'Unknown Album %s' % album.get('year'))))
     except NotLoggedIn:
         do_login(callback = f, args = [id])
Esempio n. 2
0
 def update_artists(self, event):
     """Re-download the biographies for artists on this track."""
     for a in self.track.artists:
         try:
             a.populate(application.api.get_artist_info(a.id))
         except NotLoggedIn:
             do_login(callback=self.update_artists, args=[event])
Esempio n. 3
0
 def on_done(self, event):
  """The done button was pressed."""
  name = self.name.GetValue()
  description = self.description.GetValue()
  public = self.public.GetValue()
  logger.debug('Attempting to create playlist with name "%s", description "%s" and public %s.', name, repr(description), public)
  if not name:
   do_error('Playlist names cannot be blank.')
   self.name.SetFocus()
  else:
   try:
    id = application.api.create_playlist(name, description, public)
    logger.debug('New playlist ID is %s.', id)
    p = Playlist(id = id, name = name, description = description)
    logger.debug('Created Playlist object %s.', p)
    session.add(p)
    application.frame.add_playlist(p)
    entry_ids = application.api.add_songs_to_playlist(p.id, [t.id for t in self.tracks])
    logger.debug('Entry IDs are: %s.', entry_ids)
    if len(entry_ids) == len(self.tracks):
     for pos, track in enumerate(self.tracks):
      p.tracks.append(track)
      e = PlaylistEntry(playlist = p, track = track, id = entry_ids[pos])
      logger.debug('Created playlist entry %s (%s).', e, e.track)
      session.add(e)
    else:
     do_error('Only %s %s out of %s were added to the playlist.' % (len(entry_ids), 'track' if len(entry_ids) == 1 else 'tracks', len(self.tracks)))
    session.commit()
    logger.debug('Done. Closing %s.', self)
    self.Close(True)
   except NotLoggedIn:
    do_login(callback = self.on_done, args = [event])
Esempio n. 4
0
 def update_artists(self, event):
  """Re-download the biographies for artists on this track."""
  for a in self.track.artists:
   try:
    a.populate(application.api.get_artist_info(a.id))
   except NotLoggedIn:
    do_login(callback = self.update_artists, args = [event])
Esempio n. 5
0
 def load_station(self, station):
     """Load a station's tracks."""
     try:
         wx.CallAfter(self.add_results,
                      application.api.get_station_tracks(station.id),
                      showing=station)
     except NotLoggedIn:
         do_login(callback=self.load_station, args=[station])
Esempio n. 6
0
 def save_track(self, event, path = None):
  """Save the track to disk."""
  if path is None:
   dlg = wx.FileDialog(None, message = 'Choose where to save the file', defaultFile = format_track(self.track) + '.mp3', style = wx.FD_SAVE | wx.FD_OVERWRITE_PROMPT)
   if dlg.ShowModal() == wx.ID_OK:
    path = dlg.GetPath()
   dlg.Destroy()
  if path:
   try:
    download_track(application.api.get_stream_url(self.track.id), path)
   except NotLoggedIn:
    do_login(callback = self.save_track, args = [event], kwargs = dict(path = path))
Esempio n. 7
0
 def load_album(self, event):
     """Load an album from the currently selected artist."""
     do_login()
     def f(id):
         """Get the album and load it from it's ID."""
         album = application.api.get_album_info(id)
         wx.CallAfter(self.add_results, album.get('tracks', []), showing = '%s - %s' % (album.get('artist', 'Unknown Artist'), album.get('name', 'Unknown Album %s' % album['year'])))
     res = self.get_result()
     if res is None:
         wx.Bell()
     else:
         artist_action(res.artists, lambda artist: album_action(artist, f))
Esempio n. 8
0
 def f(id):
     """Load the album and show it."""
     try:
         album = application.api.get_album_info(id)
         wx.CallAfter(
             self.add_results,
             album.get('tracks', []),
             showing='%s - %s' %
             (album.get('artist', 'Unknown Artist'),
              album.get('name',
                        'Unknown Album %s' % album.get('year'))))
     except NotLoggedIn:
         do_login(callback=f, args=[id])
Esempio n. 9
0
 def load_remote_station(self, event):
     """Load a station from google."""
     try:
         data = application.api.get_all_stations()
         stations = []
         for d in data:
             stations.append(load_station(d))
         if not session.query(Station).filter(Station.id == 'IFL').count():
             stations.append(load_station(dict(name = 'I\'m Feeling Lucky', id = 'IFL')))
         dlg = wx.SingleChoiceDialog(self, 'Select a station to listen to', 'Radio Stations', [x.name for x in stations])
         if dlg.ShowModal() == wx.ID_OK:
             Thread(target = self.load_station, args = [stations[dlg.GetSelection()]]).start()
         dlg.Destroy()
     except NotLoggedIn:
         do_login(callback = self.load_remote_station, args = [event])
Esempio n. 10
0
 def __init__(self):
  super(GenreStation, self).__init__(None, title = 'Create A Genre Station')
  add_accelerator(self, 'ESCAPE', lambda event: self.Close(True))
  p = self.GetContentsPane()
  wx.StaticText(p, label = '&Name')
  self.name = wx.TextCtrl(p, style = wx.TE_RICH2)
  self.genres = [] # The ids for add_station.
  wx.StaticText(p, label = '&Genre')
  self.genre = wx.ListBox(p)
  self.genre.Bind(wx.EVT_LISTBOX, self.update_name)
  do_login(callback = self.update_genres)
  self.ok = wx.Button(p, label = '&OK')
  self.ok.SetDefault()
  self.ok.Bind(wx.EVT_BUTTON, self.on_ok)
  wx.Button(p, label = '&Cancel').Bind(wx.EVT_BUTTON, lambda event: self.Close(True))
Esempio n. 11
0
    def cast_result(self, event):
        """Cast the currently-focused result."""
        def f(device, result):
            """Cast result to the specified device."""
            if isinstance(result, URLStream):
                url = result.url
            else:
                url = application.api.get_stream_url(result.id)
            self.do_stop(None)
            device.wait()
            set_volume(device.status.volume_level * 100)
            device.play_media(url, 'audio/mp3')
            self.cast_device = device

        res = self.get_result()
        if res is None:
            return wx.Bell()
        devices = sorted(get_chromecasts(), key=lambda result: result.name)
        dlg = wx.SingleChoiceDialog(
            self, 'Choose a device to cast to', 'Cast', [
                '{} ({})'.format(x.name,
                                 (x.status.status_text or 'Not Playing')
                                 if x.status is not None else 'No Status')
                for x in devices
            ])
        if dlg.ShowModal() == wx.ID_OK:
            device = devices[dlg.GetSelection()]
        else:
            device = None
        dlg.Destroy()
        if device is not None:
            try:
                f(device, res)
            except NotLoggedIn:
                return do_login(callback=f, args=[device, res])
Esempio n. 12
0
 def __init__(self):
     super(GenreStation, self).__init__(None,
                                        title='Create A Genre Station')
     add_accelerator(self, 'ESCAPE', lambda event: self.Close(True))
     p = self.GetContentsPane()
     wx.StaticText(p, label='&Name')
     self.name = wx.TextCtrl(p, style=wx.TE_RICH2)
     self.genres = []  # The ids for add_station.
     wx.StaticText(p, label='&Genre')
     self.genre = wx.ListBox(p)
     self.genre.Bind(wx.EVT_LISTBOX, self.update_name)
     do_login(callback=self.update_genres)
     self.ok = wx.Button(p, label='&OK')
     self.ok.SetDefault()
     self.ok.Bind(wx.EVT_BUTTON, self.on_ok)
     wx.Button(p, label='&Cancel').Bind(wx.EVT_BUTTON,
                                        lambda event: self.Close(True))
Esempio n. 13
0
 def load_id(self, id):
     """Play a track with a specific ID."""
     try:
         info = application.api.get_track_info(id)
     except CallFailure:
         return do_error('Invalid track ID: %s.' % id)
     except NotLoggedIn:
         return do_login(callback=self.load_id, args=[id])
     self.add_results([info], showing='ID: %s' % id)
Esempio n. 14
0
 def load_id(self, id):
     """Play a track with a specific ID."""
     try:
         info = application.api.get_track_info(id)
     except CallFailure:
         return do_error('Invalid track ID: %s.' % id)
     except NotLoggedIn:
         return do_login(callback=self.load_id, args=[id])
     self.add_results([info], showing='ID: %s' % id)
Esempio n. 15
0
 def download(self, track = None):
  """Download was clicked."""
  if track is None:
   track = self.track
  try:
   url = application.api.get_stream_url(track.id)
   download_track(url, track.path)
  except NotLoggedIn:
   return do_login(callback = self.download, kwargs = dict(track = track))
Esempio n. 16
0
 def download(self, track=None):
     """Download was clicked."""
     if track is None:
         track = self.track
     try:
         url = application.api.get_stream_url(track.id)
         download_track(url, track.path)
     except NotLoggedIn:
         return do_login(callback=self.download, kwargs=dict(track=track))
Esempio n. 17
0
 def save_track(self, event, path=None):
     """Save the track to disk."""
     if path is None:
         dlg = wx.FileDialog(None,
                             message='Choose where to save the file',
                             defaultFile=format_track(self.track) + '.mp3',
                             style=wx.FD_SAVE | wx.FD_OVERWRITE_PROMPT)
         if dlg.ShowModal() == wx.ID_OK:
             path = dlg.GetPath()
         dlg.Destroy()
     if path:
         try:
             download_track(application.api.get_stream_url(self.track.id),
                            path)
         except NotLoggedIn:
             do_login(callback=self.save_track,
                      args=[event],
                      kwargs=dict(path=path))
Esempio n. 18
0
    def load_album(self, event):
        """Load an album from the currently selected artist."""
        do_login()

        def f(id):
            """Get the album and load it from it's ID."""
            album = application.api.get_album_info(id)
            wx.CallAfter(
                self.add_results,
                album.get('tracks', []),
                showing='%s - %s' %
                (album.get('artist', 'Unknown Artist'),
                 album.get('name', 'Unknown Album %s' % album['year'])))

        res = self.get_result()
        if res is None:
            wx.Bell()
        else:
            artist_action(res.artists, lambda artist: album_action(artist, f))
Esempio n. 19
0
 def load_remote_station(self, event):
     """Load a station from google."""
     try:
         data = application.api.get_all_stations()
         stations = []
         for d in data:
             stations.append(load_station(d))
         if not session.query(Station).filter(Station.id == 'IFL').count():
             stations.append(
                 load_station(dict(name='I\'m Feeling Lucky', id='IFL')))
         dlg = wx.SingleChoiceDialog(self, 'Select a station to listen to',
                                     'Radio Stations',
                                     [x.name for x in stations])
         if dlg.ShowModal() == wx.ID_OK:
             Thread(target=self.load_station,
                    args=[stations[dlg.GetSelection()]]).start()
         dlg.Destroy()
     except NotLoggedIn:
         do_login(callback=self.load_remote_station, args=[event])
Esempio n. 20
0
 def on_done(self, event):
     """The done button was pressed."""
     name = self.name.GetValue()
     description = self.description.GetValue()
     public = self.public.GetValue()
     logger.debug(
         'Attempting to create playlist with name "%s", description "%s" and public %s.',
         name, repr(description), public)
     if not name:
         do_error('Playlist names cannot be blank.')
         self.name.SetFocus()
     else:
         try:
             id = application.api.create_playlist(name, description, public)
             logger.debug('New playlist ID is %s.', id)
             p = Playlist(id=id, name=name, description=description)
             logger.debug('Created Playlist object %s.', p)
             session.add(p)
             application.frame.add_playlist(p)
             entry_ids = application.api.add_songs_to_playlist(
                 p.id, [t.id for t in self.tracks])
             logger.debug('Entry IDs are: %s.', entry_ids)
             if len(entry_ids) == len(self.tracks):
                 for pos, track in enumerate(self.tracks):
                     p.tracks.append(track)
                     e = PlaylistEntry(playlist=p,
                                       track=track,
                                       id=entry_ids[pos])
                     logger.debug('Created playlist entry %s (%s).', e,
                                  e.track)
                     session.add(e)
             else:
                 do_error(
                     'Only %s %s out of %s were added to the playlist.' %
                     (len(entry_ids), 'track' if len(entry_ids) == 1 else
                      'tracks', len(self.tracks)))
             session.commit()
             logger.debug('Done. Closing %s.', self)
             self.Close(True)
         except NotLoggedIn:
             do_login(callback=self.on_done, args=[event])
Esempio n. 21
0
 def on_ok(self, event):
  """The OK button was pressed."""
  name, description = self.name.GetValue(), self.description.GetValue()
  if not name:
   return do_error('Playlist names cannot be blank.')
  elif not description:
   return do_error('Playlist descriptions cannot be blank.')
  else:
   self.playlist.name = name
   self.playlist.description = description
   try:
    self.playlist.id = application.api.edit_playlist(self.playlist.id, new_name = name, new_description = description)
   except NotLoggedIn:
    return do_login(callback = self.on_ok, args = [event])
   session.add(self.playlist)
   session.commit()
   self.Close(True)
Esempio n. 22
0
 def on_ok(self, event):
     """The OK button was pressed."""
     name, description = self.name.GetValue(), self.description.GetValue()
     if not name:
         return do_error('Playlist names cannot be blank.')
     elif not description:
         return do_error('Playlist descriptions cannot be blank.')
     else:
         self.playlist.name = name
         self.playlist.description = description
         try:
             self.playlist.id = application.api.edit_playlist(
                 self.playlist.id,
                 new_name=name,
                 new_description=description)
         except NotLoggedIn:
             return do_login(callback=self.on_ok, args=[event])
         session.add(self.playlist)
         session.commit()
         self.Close(True)
Esempio n. 23
0
 def cast_result(self, event):
     """Cast the currently-focused result."""
     def f(device, result):
         """Cast result to the specified device."""
         if isinstance(result, URLStream):
             url = result.url
         else:
             url = application.api.get_stream_url(result.id)
         self.do_stop(None)
         device.wait()
         set_volume(device.status.volume_level * 100)
         device.play_media(url, 'audio/mp3')
         self.cast_device = device
     res = self.get_result()
     if res is None:
         return wx.Bell()
     devices = sorted(get_chromecasts(), key=lambda result: result.name)
     dlg = wx.SingleChoiceDialog(
         self,
         'Choose a device to cast to',
         'Cast',
         ['{} ({})'.format(
                         x.name,
                         (x.status.status_text or 'Not Playing') if x.status is not None else 'No Status'
         ) for x in devices]
     )
     if dlg.ShowModal() == wx.ID_OK:
         device = devices[dlg.GetSelection()]
     else:
         device = None
     dlg.Destroy()
     if device is not None:
         try:
             f(device, res)
         except NotLoggedIn:
             return do_login(callback=f, args=[device, res])
Esempio n. 24
0
 def f2(results):
     """Get the user to login."""
     self.search_label.SetLabel(SEARCH_LABEL)
     do_login(callback = f, args = [what])
Esempio n. 25
0
 def load_station(self, station):
     """Load a station's tracks."""
     try:
         wx.CallAfter(self.add_results, application.api.get_station_tracks(station.id), showing = station)
     except NotLoggedIn:
         do_login(callback = self.load_station, args = [station])
Esempio n. 26
0
 def reload(self, event):
     """Reload the track from google."""
     try:
         self.track.populate(application.api.get_track_info(self.track.id))
     except NotLoggedIn:
         do_login(callback=self.reload, args=[event])
Esempio n. 27
0
 def reload(self, event):
  """Reload the track from google."""
  try:
   self.track.populate(application.api.get_track_info(self.track.id))
  except NotLoggedIn:
   do_login(callback = self.reload, args = [event])
Esempio n. 28
0
 def f2(results):
     """Get the user to login."""
     self.search_label.SetLabel(SEARCH_LABEL)
     do_login(callback=f, args=[what])