Ejemplo n.º 1
0
    private void DoScrobbleLookups()
    {
      PlayList currentPlaylist = playlistPlayer.GetPlaylist(PlayListType.PLAYLIST_MUSIC);

      MusicDatabase dbs = MusicDatabase.Instance;
      Song current10SekSong = new Song();
      List<Song> scrobbledArtists = new List<Song>();

      ascrobbler.RemoveRequest(_lastRequest);
      switch (currentScrobbleMode)
      {
        case ScrobbleMode.Similar:
          if (_rememberStartTrack && _scrobbleStartTrack != null)
          {
            if (_totalScrobbledSongs > REINSERT_AFTER_THIS_MANY_SONGS)
            {
              _totalScrobbledSongs = 0;
              Song tmpArtist = new Song();
              tmpArtist = _scrobbleStartTrack;
              scrobbledArtists.Add(tmpArtist);
              break;
            }
          }
          string strFile = string.Empty;
          if (g_Player.Player.CurrentFile != null && g_Player.Player.CurrentFile != string.Empty && g_Player.IsMusic)
          {
            strFile = g_Player.Player.CurrentFile;

            bool songFound = dbs.GetSongByFileName(strFile, ref current10SekSong);
            if (songFound)
            {
              if (_scrobbleStartTrack == null || _scrobbleStartTrack.Artist == string.Empty)
              {
                _scrobbleStartTrack = current10SekSong.Clone();
              }

              try
              {
                UpdateSimilarArtists(current10SekSong.Artist);
                //scrobbledArtists = ascrobbler.getSimilarArtists(current10SekSong.ToURLArtistString(), _useSimilarRandom);
                return;
              }
              catch (Exception ex)
              {
                Log.Error("ScrobbleLookupThread: exception on lookup Similar - {0}", ex.Message);
              }
            }
          }
          break;

        case ScrobbleMode.Neighbours:
          //lock (ScrobbleLock)
          //{
          try
          {
            UpdateNeighboursArtists(true);
          }
          catch (Exception ex)
          {
            Log.Error("ScrobbleLookupThread: exception on lookup Neighbourhood - {0}", ex.Message);
          }
          //}
          break;

        case ScrobbleMode.Friends:
          //lock (ScrobbleLock)
          //{
          try
          {
            UpdateFriendsArtists(true);
          }
          catch (Exception ex)
          {
            Log.Error("ScrobbleLookupThread: exception on lookup - Friends {0}", ex.Message);
          }
          //}
          break;
        case ScrobbleMode.Random:
          try
          {
            switch (currentOfflineMode)
            {
              case offlineMode.random:
                UpdateRandomTracks();
                break;
              case offlineMode.timesplayed:
                UpdateUnheardTracks();
                break;
              case offlineMode.favorites:
                UpdateFavoriteTracks();
                break;
              default:
                UpdateRandomTracks();
                break;
            }
          }
          catch (Exception ex)
          {
            Log.Error("ScrobbleLookupThread: exception on lookup - Random {0}", ex.Message);
          }
          break;
      }

      OnScrobbleLookupsCompleted(scrobbledArtists);
    }
    private List<Song> fetchRandomTracks(offlineMode randomMode_)
    {
      int addedSongs = 0;
      MusicDatabase dbs = MusicDatabase.Instance;
      List<Song> randomSongList = new List<Song>(_limitRandomListCount);
      Song randomSong = new Song();
      Song lookupSong = new Song();
      int loops = 0;

      // fetch more than needed since there could be double entries
      while (addedSongs < _limitRandomListCount * 3)
      {
        loops++;
        lookupSong.Clear();

        dbs.GetRandomSong(ref lookupSong);
        randomSong = lookupSong.Clone();

        bool found = false;
        for (int i = 0; i < randomSongList.Count; i++)
        {
          if (randomSongList[i].Artist == randomSong.Artist)
          {
            found = true;
            break;
          }
        }

        if (!found)
        {
          switch (randomMode_)
          {
            case offlineMode.timesplayed:
              if (randomSong.TimesPlayed == 0)
              {
                randomSongList.Add(randomSong);
                addedSongs++;
              }
              break;
            case offlineMode.favorites:
              if (randomSong.Favorite)
              {
                randomSongList.Add(randomSong);
                addedSongs++;
              }
              break;
            case offlineMode.random:
              randomSongList.Add(randomSong);
              addedSongs++;
              break;
          }
        }
        // quick check; 3x rlimit times because every pass could try different artists in dbs.GetRandomSong(ref lookupSong);
        if (loops > 20)
        {
          if (randomMode_ == offlineMode.timesplayed)
          {
            Log.Debug("AudioScrobblerUtils: Not enough unique unheard tracks for random mode");
          }
          break;
        }
      }

      return randomSongList;
    }
Ejemplo n.º 3
0
    public void PlayPlayListStreams(Song aStreamSong)
    {
      bool playSuccess = false;
      try
      {
        GUIWaitCursor.Show();
        if (g_Player.Playing)
        {
          g_Player.Stop();
        }
        LastFMStation.CurrentStreamState = StreamPlaybackState.starting;

        _streamSong = aStreamSong;

        Song addSong = aStreamSong.Clone();
        AddStreamSongToPlaylist(ref addSong);

        PlaylistPlayer.CurrentPlaylistType = PlayListType.PLAYLIST_RADIO_STREAMS;
        PlayList Playlist = PlaylistPlayer.GetPlaylist(PlaylistPlayer.CurrentPlaylistType);

        if (Playlist == null)
        {
          return;
        }

        // Avoid an endless loop when a song cannot be played.
        PlaylistPlayer.RepeatPlaylist = false;

        // I found out, you have to send "Cookie: Session=[sessionID]" in the header of the request of the MP3 file. 
        PlaylistPlayer.Play(0);

        LastFMStation.CurrentStreamState = StreamPlaybackState.streaming;

        playSuccess = g_Player.Playing;
      }
      finally
      {
        GUIWaitCursor.Hide();
        if (!playSuccess)
        {
          PlayBackFailedHandler();
        }
      }
    }
    private List<Song> filterForLocalSongs(List<Song> unfilteredList_, bool onlyUniqueArtists, songFilterType filterType)
    {
      try
      {
        lock (LookupLock)
        {
          MusicDatabase mdb = MusicDatabase.Instance;
          List<Song> tmpSongs = new List<Song>();

          Song tmpSong = new Song();
          bool foundDoubleEntry = false;
          string tmpArtist = string.Empty;

          for (int s = 0; s < unfilteredList_.Count; s++)
          {
            tmpArtist = unfilteredList_[s].Artist.ToLowerInvariant();
            // only accept other artists than the current playing but include current "tag" since some people tag just using the artist's name..
            //if (tmpArtist != excludeArtist_.ToLowerInvariant() || tmpArtist == currentTag_)
            //{
            switch (filterType)
            {
              case songFilterType.Track:
                {
                  Song dbSong = new Song();
                  // The filename is unique so try if we get a 100% correct result first
                  if (!string.IsNullOrEmpty(unfilteredList_[s].FileName))
                  {
                    mdb.GetSongByFileName(unfilteredList_[s].FileName, ref dbSong);
                  }
                  else
                  {
                    mdb.GetSongByMusicTagInfo(AudioscrobblerBase.StripArtistPrefix(unfilteredList_[s].Artist),
                                              unfilteredList_[s].Album, unfilteredList_[s].Title, true, ref dbSong);
                  }

                  if (!string.IsNullOrEmpty(dbSong.Artist))
                  {
                    tmpSong = dbSong.Clone();
                    // Log.Debug("Audioscrobber: Track filter for {1} found db song - {0}", tmpSong.FileName, unfilteredList_[s].Title);
                    foundDoubleEntry = false;

                    if (onlyUniqueArtists)
                    {
                      // check and prevent entries from the same artist
                      for (int j = 0; j < tmpSongs.Count; j++)
                      {
                        if (tmpSong.Artist == tmpSongs[j].Artist)
                        {
                          foundDoubleEntry = true;
                          break;
                        }
                      }
                    }

                    // new item therefore add it
                    if (!foundDoubleEntry)
                    {
                      //if (currentTag_ != string.Empty)
                      //  tmpSong.Genre = currentTag_;
                      tmpSongs.Add(tmpSong);
                    }
                  }
                  break;
                }
              case songFilterType.Artist:
                {
                  String[] artistArray = null;
                  List<Song> dbArtists = new List<Song>();
                  ArrayList artistsInDB = new ArrayList();
                  if (mdb.GetArtists(4, unfilteredList_[s].Artist, ref artistsInDB))
                  {
                    artistArray = (String[])artistsInDB.ToArray(typeof (String));
                    foreach (String singleArtist in artistArray)
                    {
                      Song addSong = new Song();
                      addSong.Artist = singleArtist;
                      dbArtists.Add(addSong);
                    }
                    // only use the first hit for now..
                    if (dbArtists.Count > 0)
                    {
                      foundDoubleEntry = false;
                      // check and prevent double entries 
                      for (int j = 0; j < tmpSongs.Count; j++)
                      {
                        if (dbArtists[0].Artist == (tmpSongs[j].Artist))
                        {
                          foundDoubleEntry = true;
                          break;
                        }
                      }
                      // new item therefore add it
                      if (!foundDoubleEntry)
                      {
                        tmpSongs.Add(unfilteredList_[s]);
                      }
                    }
                  }
                  break;
                }
              case songFilterType.Album:
                {
                  AlbumInfo[] albumArray = null;
                  List<Song> dbAlbums = new List<Song>();
                  ArrayList albumsInDB = new ArrayList();
                  if (mdb.GetAlbums(2, unfilteredList_[s].Album, ref albumsInDB))
                  {
                    albumArray = (AlbumInfo[])albumsInDB.ToArray(typeof (AlbumInfo));
                    foreach (AlbumInfo singleAlbum in albumArray)
                    {
                      Song addSong = new Song();
                      addSong.Album = singleAlbum.Album;
                      dbAlbums.Add(addSong);
                    }
                    // only use the first hit for now..
                    if (dbAlbums.Count > 0)
                    {
                      foundDoubleEntry = false;
                      // check and prevent double entries 
                      for (int j = 0; j < tmpSongs.Count; j++)
                      {
                        if (dbAlbums[0].Album == (tmpSongs[j].Album))
                        {
                          foundDoubleEntry = true;
                          break;
                        }
                      }
                      // new item therefore add it
                      if (!foundDoubleEntry)
                      {
                        tmpSongs.Add(unfilteredList_[s]);
                      }
                    }
                  }
                  break;
                }
            }
            //}
            //else
            //  Log.Debug("AudioScrobblerUtils Artist {0} inadequate - skipping", tagTracks[s].Artist);
          }
          return tmpSongs;
        }
      }
      catch (Exception ex)
      {
        Log.Error("AudioScrobblerUtils: filtering for local songs failed - {0}", ex.Message);
        return unfilteredList_;
      }
    }