Beispiel #1
0
        public IEnumerable <Track> GetTracksByName(string name)
        {
            List <Track> tracks = new List <Track>();

            try
            {
                var response = GroovesharkModule.GetClient().SearchArtist(name);
                var results  = response.result.result as List <SearchArtist.SearchArtistResult>;
                tracks.AddRange(Convert(results));
            }
            catch (Exception e)
            {
                _logger.Log("Grooveshark: " + e, Category.Info, Priority.Medium);
            }

            return(tracks);
        }
Beispiel #2
0
        public IEnumerable <TrackContainer> GetAlbumsByArtist(string artist)
        {
            List <TrackContainer> containers = new List <TrackContainer>();

            try
            {
                var response = GroovesharkModule.GetClient().SearchArtist(artist);
                var results  = response.result.result as List <SearchArtist.SearchArtistResult>;
                var byAlbum  = results
                               .Where(s => artist.Equals(s.ArtistName, StringComparison.InvariantCultureIgnoreCase))
                               .GroupBy(s => new { Album = s.AlbumName, Year = s.Year });

                foreach (var albumGroup in byAlbum)
                {
                    int year;
                    if (!int.TryParse(albumGroup.Key.Year, out year))
                    {
                        year = DateTime.Now.Year;
                    }

                    TrackContainer container = new TrackContainer
                    {
                        Name   = albumGroup.Key.Album,
                        Year   = year,
                        Owner  = new TrackContainerOwner(artist),
                        Tracks = Convert(albumGroup).OrderBy(t => t.Index).ToArray(),
                    };

                    var firstTrack = container.Tracks.FirstOrDefault();

                    if (firstTrack != null)
                    {
                        container.Image = firstTrack.AlbumArt;
                    }

                    containers.Add(container);
                }
            }
            catch (Exception e)
            {
                _logger.Log("Grooveshark: " + e, Category.Exception, Priority.Medium);
            }

            return(containers);
        }
        public void Load(Track track)
        {
            var currentTrack = track as GroovesharkTrack;

            if (currentTrack != null)
            {
                lock (_trackPlayerLock)
                {
                    try
                    {
                        if (_trackPlayer != null)
                        {
                            _trackPlayer.Stop();
                        }
                    }
                    catch (Exception e)
                    {
                        _log.Log("While disposing old trackplayer: " + e.Message, Category.Warn, Priority.Medium);
                    }

                    var client = GroovesharkModule.GetClient();
                    var stream = client.GetMusicStream(currentTrack.SongID, currentTrack.ArtistID);

                    Action <Track>          trackComplete = OnTrackComplete;
                    Action <bool>           isPlaying     = parameter => IsPlaying = parameter;
                    Action <bool>           isBuffering   = parameter => IsBuffering = parameter;
                    Action <double, double> trackProgress = OnTrackProgress;
                    _trackPlayer = new GrooveSharkTrackPlayerHandler(
                        _log,
                        currentTrack,
                        trackComplete,
                        isPlaying,
                        isBuffering,
                        trackProgress);

                    _trackPlayer.Initialize(stream.Stream);
                }
            }
        }