Exemple #1
0
 /// <summary>
 /// Marks all scrobbles as not "ToScrobble".
 /// </summary>
 public void SelectNone()
 {
     foreach (var vm in Scrobbles.Where(i => i.IsEnabled))
     {
         vm.ToScrobble = false;
     }
 }
Exemple #2
0
 /// <summary>
 /// Marks all scrobbles as "ToScrobble".
 /// </summary>
 public void SelectAll()
 {
     foreach (var vm in Scrobbles.Where(i => i.IsEnabled))
     {
         vm.ToScrobble = true;
     }
 }
Exemple #3
0
 /// <summary>
 /// Marks all selected scrobbles as not "ToScrobble".
 /// </summary>
 public virtual void UncheckSelected()
 {
     foreach (var s in Scrobbles.Where(s => s.IsSelected))
     {
         s.ToScrobble = false;
     }
 }
 /// <summary>
 /// Marks all selected scrobbles as not "ToScrobble".
 /// </summary>
 public override void UncheckSelected()
 {
     foreach (var s in Scrobbles.Where(s => s.IsEnabled && s.IsSelected))
     {
         s.ToScrobble = false;
     }
 }
Exemple #5
0
 /// <summary>
 /// Marks all fetched scrobbles as not "ToScrobble".
 /// </summary>
 public override void UncheckAll()
 {
     foreach (var vm in Scrobbles.Where(i => i.IsEnabled))
     {
         vm.ToScrobble = false;
     }
 }
Exemple #6
0
        /// <summary>
        /// Create a list with tracks that will be scrobbled.
        /// </summary>
        /// <returns>List with scrobbles.</returns>
        protected override IEnumerable <Scrobble> CreateScrobbles()
        {
            List <Scrobble> scrobbles = new List <Scrobble>();

            if (ScrobbleMode == CSVScrobbleMode.Normal)
            {
                foreach (var vm in Scrobbles.Where(i => i.ToScrobble))
                {
                    scrobbles.Add(new Scrobble(vm.ParsedScrobble.ArtistName, vm.ParsedScrobble.AlbumName, vm.ParsedScrobble.TrackName, vm.ParsedScrobble.Played)
                    {
                        AlbumArtist = vm.ParsedScrobble.AlbumArtist, Duration = vm.ParsedScrobble.Duration
                    });
                }
            }
            else if (ScrobbleMode == CSVScrobbleMode.ImportMode)
            {
                DateTime time = Time;
                foreach (var vm in Scrobbles.Where(i => i.ToScrobble))
                {
                    scrobbles.Add(new Scrobble(vm.ParsedScrobble.ArtistName, vm.ParsedScrobble.AlbumName, vm.ParsedScrobble.TrackName, time)
                    {
                        AlbumArtist = vm.ParsedScrobble.AlbumArtist,
                        Duration    = vm.ParsedScrobble.Duration
                    });

                    time = time.Subtract(TimeSpan.FromSeconds(Duration));
                }
            }

            return(scrobbles);
        }
 /// <summary>
 /// Marks all selected scrobbles as "ToScrobble".
 /// </summary>
 public override void CheckSelected()
 {
     foreach (var vm in Scrobbles.Where(i => i.IsEnabled && i.IsSelected))
     {
         vm.ToScrobble = false;
     }
 }
        /// <summary>
        /// Parses the metadata of the given <paramref name="files"/>.
        /// </summary>
        /// <param name="files">Files whose metadata to parse.</param>
        /// <returns>Task.</returns>
        private async Task ParseFiles(string[] files)
        {
            OnStatusUpdated("Trying to parse selected files...");
            List <string> errors = new List <string>();

            var newFiles = new List <LoadedFileViewModel>();
            await Task.Run(() =>
            {
                foreach (string file in files)
                {
                    try
                    {
                        if (SUPPORTEDFILES.Contains(Path.GetExtension(file).ToLower()))
                        {
                            ILocalFile audioFile = _localFileFactory.CreateFile(file);

                            if (string.IsNullOrEmpty(audioFile.Artist))
                            {
                                throw new Exception("No artist name found");
                            }
                            if (string.IsNullOrEmpty(audioFile.Track))
                            {
                                throw new Exception("No track name found");
                            }

                            var vm = new LoadedFileViewModel(audioFile);
                            vm.ToScrobbleChanged += Vm_ToScrobbleChanged;
                            newFiles.Add(vm);
                        }
                    }
                    catch (Exception ex)
                    {
                        errors.Add(string.Format("{0} {1}", file, ex.Message));
                    }
                }
            });

            Scrobbles = new ObservableCollection <LoadedFileViewModel>(Scrobbles.Concat(newFiles));

            if (errors.Count > 0)
            {
                OnStatusUpdated(string.Format("Finished parsing selected files. {0} files could not be parsed", errors.Count));
                if (_windowManager.MessageBoxService.ShowDialog("Some files could not be parsed. Do you want to save a text file with the files that could not be parsed?",
                                                                "Error parsing files", IMessageBoxServiceButtons.YesNo) == IMessageBoxServiceResult.Yes)
                {
                    IFileDialog sfd = _windowManager.CreateSaveFileDialog();
                    sfd.Filter = "Text Files|*.txt";
                    if (sfd.ShowDialog())
                    {
                        _fileOperator.WriteAllLines(sfd.FileName, errors.ToArray());
                    }
                }
            }
            else
            {
                OnStatusUpdated("Successfully parsed selected files");
            }
        }
Exemple #9
0
        /// <summary>
        /// Fetches the tracklist of the clicked release and displays it.
        /// </summary>
        /// <param name="sender">Clicked release as <see cref="LastAlbum"/>.</param>
        /// <param name="e">Ignored.</param>
        public async void ReleaseClicked(object sender, EventArgs e)
        {
            if (EnableControls)
            {
                EnableControls = false;

                try
                {
                    var release = sender as Release;
                    OnStatusUpdated(string.Format("Trying to fetch tracklist from release '{0}'", release.Name));

                    LastResponse <LastAlbum> response = null;
                    if (!string.IsNullOrEmpty(release.Mbid))
                    {
                        response = await _lastfmAlbumAPI.GetInfoByMbidAsync(release.Mbid);
                    }
                    else
                    {
                        response = await _lastfmAlbumAPI.GetInfoAsync(release.ArtistName, release.Name);
                    }

                    if (response.Success && response.Status == LastResponseStatus.Successful)
                    {
                        Scrobbles.Clear();
                        foreach (var t in response.Content.Tracks)
                        {
                            FetchedTrackViewModel vm = new FetchedTrackViewModel(new ScrobbleBase(t.Name, t.ArtistName, t.AlbumName, "", t.Duration), release.Image);
                            vm.ToScrobbleChanged += ToScrobbleChanged;
                            Scrobbles.Add(vm);
                        }

                        if (Scrobbles.Count != 0)
                        {
                            CurrentView = _trackResultView;
                            OnStatusUpdated(string.Format("Successfully fetched tracklist from release '{0}'", release.Name));
                        }
                        else
                        {
                            OnStatusUpdated(string.Format("Release '{0}' has no tracks", release.Name));
                        }
                    }
                    else
                    {
                        OnStatusUpdated(string.Format("Error while fetching tracklist from release '{0}': {1}", release.Name, response.Status));
                    }
                }
                catch (Exception ex)
                {
                    OnStatusUpdated(string.Format("Fatal error while fetching tracklist from release: {0}", ex.Message));
                }
                finally
                {
                    EnableControls = true;
                }
            }
        }
Exemple #10
0
        /// <summary>
        /// Creates a list with scrobbles that will be scrobbled.
        /// </summary>
        /// <returns>List with scrobbles.</returns>
        protected override IEnumerable <Scrobble> CreateScrobbles()
        {
            List <Scrobble> scrobbles = new List <Scrobble>();

            foreach (var vm in Scrobbles.Where(i => i.ToScrobble))
            {
                scrobbles.Add(new Scrobble(vm.ArtistName, vm.AlbumName, vm.TrackName, vm.TimePlayed.AddSeconds(1))
                {
                    Duration = vm.Duration
                });
            }

            return(scrobbles);
        }
        /// <summary>
        /// Creates the list of the tracks that will be scrobbled.
        /// </summary>
        /// <returns>List with scrobbles.</returns>
        protected override IEnumerable <Scrobble> CreateScrobbles()
        {
            DateTime        timePlayed = ScrobbleTimeVM.Time;
            List <Scrobble> scrobbles  = new List <Scrobble>();

            foreach (var vm in Scrobbles.Where(i => i.ToScrobble).Reverse())
            {
                scrobbles.Add(new Scrobble(vm.ArtistName, vm.AlbumName, vm.TrackName, timePlayed)
                {
                    AlbumArtist = vm.AlbumArtist,
                    Duration    = vm.Duration
                });
                timePlayed = timePlayed.Subtract(vm.Duration ?? TimeSpan.FromSeconds(1));
            }

            return(scrobbles);
        }
Exemple #12
0
        /// <summary>
        /// Creates a list with scrobbles.
        /// </summary>
        /// <returns>List with scrobbles that would be
        /// scrobbled with the current settings.</returns>
        protected override IEnumerable <Scrobble> CreateScrobbles()
        {
            DateTime        finishingTime = ScrobbleTimeVM.Time;
            List <Scrobble> scrobbles     = new List <Scrobble>();

            foreach (FetchedTrackViewModel vm in Scrobbles.Where(i => i.ToScrobble).Reverse())
            {
                scrobbles.Add(new Scrobble(vm.FetchedTrack.ArtistName, AlbumString, vm.FetchedTrack.TrackName, finishingTime));
                if (vm.FetchedTrack.Duration.HasValue)
                {
                    finishingTime = finishingTime.Subtract(vm.FetchedTrack.Duration.Value);
                }
                else
                {
                    finishingTime = finishingTime.Subtract(TimeSpan.FromMinutes(3.0));
                }
            }

            return(scrobbles);
        }
Exemple #13
0
        /// <summary>
        /// Creates a list with scrobbles that will be scrobbled.
        /// </summary>
        /// <returns>List with scrobbles.</returns>
        protected override IEnumerable <Scrobble> CreateScrobbles()
        {
            List <Scrobble> scrobbles = new List <Scrobble>();

            DateTime time = DateTime.Now;;

            foreach (var vm in Scrobbles.Where(i => i.ToScrobble))
            {
                for (int i = 0; i < vm.PlayCount; i++)
                {
                    scrobbles.Add(new Scrobble(vm.ArtistName, vm.AlbumName, vm.TrackName, time)
                    {
                        AlbumArtist = vm.AlbumArtist, Duration = vm.Duration
                    });
                    time = time.Subtract(TimeSpan.FromSeconds(1));
                }
            }

            return(scrobbles);
        }
Exemple #14
0
        /// <summary>
        /// Fetches the recent scrobbles of the user with the given <see cref="Username"/>.
        /// </summary>
        public async Task FetchScrobbles()
        {
            try
            {
                EnableControls = false;
                OnStatusUpdated(string.Format("Trying to fetch scrobbles of '{0}' ...", Username));
                Scrobbles.Clear();
                var response = await _userApi.GetRecentScrobbles(Username, null, 1, Amount);

                if (response.Success)
                {
                    foreach (var s in response)
                    {
                        if (!s.IsNowPlaying.HasValue || !s.IsNowPlaying.Value)
                        {
                            FetchedFriendTrackViewModel vm = new FetchedFriendTrackViewModel(s);
                            vm.ToScrobbleChanged += ToScrobbleChanged;
                            Scrobbles.Add(vm);
                        }
                    }

                    OnStatusUpdated(string.Format("Successfully fetched scrobbles of '{0}'", Username));
                }
                else
                {
                    OnStatusUpdated(string.Format("Failed to fetch scrobbles of '{0}': {1}", Username, response.Status));
                }
            }
            catch (Exception ex)
            {
                OnStatusUpdated(string.Format("Fatal error while fetching scrobbles of '{0}': {1}", Username, ex.Message));
            }
            finally
            {
                EnableControls = true;
            }
        }
 /// <summary>
 /// Marks all selected scrobbles as "ToScrobble".
 /// </summary>
 public virtual void CheckSelected()
 {
     SetToScrobbleState(Scrobbles.Where(s => s.IsSelected), true);
 }
 /// <summary>
 /// Marks all scrobbles as not "ToScrobble".
 /// </summary>
 public override void UncheckAll()
 {
     SetToScrobbleState(Scrobbles.Where(i => i.IsEnabled), false);
 }
 /// <summary>
 /// Marks all selected scrobbles as not "ToScrobble".
 /// </summary>
 public virtual void UncheckSelected()
 {
     SetToScrobbleState(Scrobbles.Where(s => s.IsSelected), false);
 }
 /// <summary>
 /// Marks all scrobbles as "ToScrobble".
 /// </summary>
 public override void CheckAll()
 {
     SetToScrobbleState(Scrobbles.Where(i => i.IsEnabled), true);
 }
 /// <summary>
 /// Removes the selected files.
 /// </summary>
 public void RemoveFiles()
 {
     Scrobbles = new ObservableCollection <LoadedFileViewModel>(Scrobbles.Where(i => !i.ToScrobble).ToList());
     NotifyOfPropertyChange(() => CanRemoveFiles);
 }
 /// <summary>
 /// Marks all selected scrobbles as not "ToScrobble".
 /// </summary>
 public override void UncheckSelected()
 {
     SetToScrobbleState(Scrobbles.Where(i => i.IsSelected && i.IsEnabled), false);
 }
Exemple #21
0
        /// <summary>
        /// Loads and parses a csv file.
        /// </summary>
        /// <returns>Task.</returns>
        public async Task ParseCSVFile()
        {
            try
            {
                EnableControls = false;
                OnStatusUpdated("Reading CSV file...");
                Scrobbles.Clear();

                using (ITextFieldParser parser = _parserFactory.CreateParser(CSVFilePath))
                {
                    parser.SetDelimiters(Settings.Default.CSVDelimiters.Select(x => new string(x, 1)).ToArray());

                    string[]      fields = null;
                    List <string> errors = new List <string>();
                    ObservableCollection <ParsedCSVScrobbleViewModel> parsedScrobbles = new ObservableCollection <ParsedCSVScrobbleViewModel>();

                    await Task.Run(() =>
                    {
                        while (!parser.EndOfData)
                        {
                            try
                            {
                                fields = parser.ReadFields();

                                string dateString = fields[Settings.Default.TimestampFieldIndex];

                                // check for 'now playing'
                                if (dateString == "" && ScrobbleMode == CSVScrobbleMode.Normal)
                                {
                                    continue;
                                }

                                DateTime date = DateTime.Now;
                                if (!DateTime.TryParse(dateString, out date))
                                {
                                    bool parsed = false;
                                    // try different formats until succeeded
                                    foreach (string format in _formats)
                                    {
                                        parsed = DateTime.TryParseExact(dateString, format, CultureInfo.CurrentCulture, DateTimeStyles.None, out date);
                                        if (parsed)
                                        {
                                            break;
                                        }
                                    }

                                    if (!parsed && ScrobbleMode == CSVScrobbleMode.Normal)
                                    {
                                        throw new Exception("Timestamp could not be parsed!");
                                    }
                                }

                                // try to get optional parameters first
                                string album       = fields.ElementAtOrDefault(Settings.Default.AlbumFieldIndex);
                                string albumArtist = fields.ElementAtOrDefault(Settings.Default.AlbumArtistFieldIndex);
                                string duration    = fields.ElementAtOrDefault(Settings.Default.DurationFieldIndex);
                                TimeSpan time      = TimeSpan.FromSeconds(Duration);
                                TimeSpan.TryParse(duration, out time);

                                DatedScrobble parsedScrobble = new DatedScrobble(date.AddSeconds(1), fields[Settings.Default.TrackFieldIndex],
                                                                                 fields[Settings.Default.ArtistFieldIndex], album,
                                                                                 albumArtist, time);
                                ParsedCSVScrobbleViewModel vm = new ParsedCSVScrobbleViewModel(parsedScrobble, ScrobbleMode);
                                vm.ToScrobbleChanged         += ToScrobbleChanged;
                                parsedScrobbles.Add(vm);
                            }
                            catch (Exception ex)
                            {
                                string errorString = "CSV line number: " + parser.LineNumber + ",";
                                foreach (string s in fields)
                                {
                                    errorString += s + ",";
                                }

                                errorString += ex.Message;
                                errors.Add(errorString);
                            }
                        }
                    });

                    if (errors.Count == 0)
                    {
                        OnStatusUpdated("Successfully parsed CSV file. Parsed " + parsedScrobbles.Count + " rows");
                    }
                    else
                    {
                        OnStatusUpdated("Partially parsed CSV file. " + errors.Count + " rows could not be parsed");
                        if (MessageBox.Show("Some rows could not be parsed. Do you want to save a text file with the rows that could not be parsed?", "Error parsing rows", MessageBoxButtons.YesNo) == DialogResult.Yes)
                        {
                            SaveFileDialog sfd = new SaveFileDialog()
                            {
                                Filter = "Text Files|*.txt"
                            };
                            if (sfd.ShowDialog() == DialogResult.OK)
                            {
                                File.WriteAllLines(sfd.FileName, errors.ToArray());
                            }
                        }
                    }

                    Scrobbles = parsedScrobbles;
                }
            }
            catch (Exception ex)
            {
                Scrobbles.Clear();
                OnStatusUpdated("Error parsing CSV file: " + ex.Message);
            }
            finally
            {
                EnableControls = true;
            }
        }