public Entry(string artist, string title, DateTime timeStarted, PlaybackSource source, TimeSpan duration, ScrobbleMode mode) { Artist = artist; Title = title; TimeStarted = timeStarted; Source = source; Duration = duration; Mode = mode; }
public Entry(string artist, string title, DateTime timeStarted, PlaybackSource source, TimeSpan duration, ScrobbleMode mode, string album, int trackNumber, string mbid) { Artist = artist; Title = title; TimeStarted = timeStarted; Source = source; Duration = duration; Mode = mode; Album = album; Number = trackNumber; MBID = mbid; }
public Entry(string artist, string title, string album, DateTime timeStarted, PlaybackSource source, TimeSpan duration, ScrobbleMode mode) { //if (string.IsNullOrWhiteSpace (artist)) { // artist = gMusic.Song.GetArtistFromFileName (title); // title = gMusic.Song.GetTitleFromFileName (title); //} Artist = artist; Title = title; TimeStarted = timeStarted; Source = source; Duration = duration; Mode = mode; Album = album; }
public FileParseResult Parse(string file, TimeSpan defaultDuration, ScrobbleMode scrobbleMode) { if (string.IsNullOrEmpty(file)) { throw new ArgumentNullException(nameof(file)); } var errors = new List <string>(); var settings = new JsonSerializerSettings() { ContractResolver = new CustomContractResolver(), Error = delegate(object sender, Newtonsoft.Json.Serialization.ErrorEventArgs args) { errors.Add($"Object Number: {args.ErrorContext.Member} | Error: {args.ErrorContext.Error.Message}"); args.ErrorContext.Handled = true; } }; var parsedscrobbles = JsonConvert.DeserializeObject <DatedScrobble[]>(File.ReadAllText(file), settings); return(new FileParseResult(parsedscrobbles, errors)); }
public FileParseResult Parse(string file, TimeSpan defaultDuration, ScrobbleMode scrobbleMode) { return(_parser.Parse(file, defaultDuration, scrobbleMode)); }
protected override void OnClicked(int controlId, GUIControl control, Action.ActionType actionType) { base.OnClicked(controlId, control, actionType); if (control == btnScrobbleUser) { // no users in database if (_scrobbleUsers.Count == 0) { return; } //for (int i = 0; i < scrobbleusers.Count; i++) GUIDialogMenu dlg = (GUIDialogMenu)GUIWindowManager.GetWindow((int)Window.WINDOW_DIALOG_MENU); if (dlg != null) { dlg.Reset(); dlg.SetHeading(GUILocalizeStrings.Get(497)); //Menu int selected = 0; int count = 0; foreach (string scrobbler in _scrobbleUsers) { dlg.Add(scrobbler); if (scrobbler == _currentScrobbleUser) { selected = count; } count++; } dlg.SelectedLabel = selected; } dlg.DoModal(GetID); if (dlg.SelectedLabel < 0) { return; } if (_currentScrobbleUser != dlg.SelectedLabelText) { _currentScrobbleUser = dlg.SelectedLabelText; btnScrobbleUser.Label = GUILocalizeStrings.Get(33005) + _currentScrobbleUser; AudioscrobblerBase.DoChangeUser(_currentScrobbleUser, m_database.AddScrobbleUserPassword( Convert.ToString(m_database.AddScrobbleUser(_currentScrobbleUser)), "")); LoadScrobbleUserSettings(); UpdateButtonStates(); } GUIControl.FocusControl(GetID, controlId); return; } //if (control == btnScrobbleUser) if (control == btnScrobbleMode) { bool shouldContinue = false; do { shouldContinue = false; GUIDialogMenu dlg = (GUIDialogMenu)GUIWindowManager.GetWindow((int)Window.WINDOW_DIALOG_MENU); if (dlg != null) { dlg.Reset(); dlg.SetHeading(GUILocalizeStrings.Get(33010)); // Automatically fill playlist with dlg.Add(GUILocalizeStrings.Get(33011)); // similar tracks dlg.Add(GUILocalizeStrings.Get(33017)); // random tracks if (_enableScrobbling) { dlg.Add(GUILocalizeStrings.Get(33012)); // tracks your neighbours like dlg.Add(GUILocalizeStrings.Get(33016)); // tracks your friends like //dlg.Add(GUILocalizeStrings.Get(33014)); // tracks played recently //dlg.Add(GUILocalizeStrings.Get(33013)); // tracks suiting configured tag {0} } dlg.DoModal(GetID); if (dlg.SelectedLabel < 0) { return; } switch (dlg.SelectedId) { case 1: currentScrobbleMode = ScrobbleMode.Similar; btnScrobbleMode.Label = GUILocalizeStrings.Get(33001); break; case 2: currentScrobbleMode = ScrobbleMode.Random; btnScrobbleMode.Label = GUILocalizeStrings.Get(33007); break; case 3: currentScrobbleMode = ScrobbleMode.Neighbours; btnScrobbleMode.Label = GUILocalizeStrings.Get(33002); break; case 4: currentScrobbleMode = ScrobbleMode.Friends; btnScrobbleMode.Label = GUILocalizeStrings.Get(33006); break; case 5: currentScrobbleMode = ScrobbleMode.Recent; btnScrobbleMode.Label = GUILocalizeStrings.Get(33004); break; case 6: currentScrobbleMode = ScrobbleMode.Tags; btnScrobbleMode.Label = GUILocalizeStrings.Get(33003); break; default: currentScrobbleMode = ScrobbleMode.Random; btnScrobbleMode.Label = GUILocalizeStrings.Get(33007); break; } if (currentScrobbleMode == ScrobbleMode.Random) { if (currentOfflineMode == offlineMode.favorites) { MusicDatabase checkdb = MusicDatabase.Instance; if (checkdb.GetTotalFavorites() <= _maxScrobbledArtistsForSongs * 2) { shouldContinue = true; Log.Warn( "Audioscrobbler playlist: Cannot activate offline mode: favorites because there are not enough tracks"); } } } } } while (shouldContinue); CheckScrobbleInstantStart(); GUIControl.FocusControl(GetID, controlId); return; } //if (control == btnScrobbleMode) if (control == btnShuffle) { ShufflePlayList(); } else if (control == btnSave) { SavePlayList(); } else if (control == btnClear) { ClearPlayList(); } else if (control == btnScrobble) { //get state of button if (btnScrobble.Selected) { ScrobblerOn = true; CheckScrobbleInstantStart(); } else { ScrobblerOn = false; } if (facadeLayout.PlayListLayout != null) { UpdateButtonStates(); } } else if ((btnRepeatPlaylist != null) && (control == btnRepeatPlaylist)) { playlistPlayer.RepeatPlaylist = btnRepeatPlaylist.Selected; } }
/// <summary> /// Parses the given <paramref name="file"/>. /// </summary> /// <param name="file">File to parse.</param> /// <param name="defaultDuration">Default duration for tracks.</param> /// <param name="scrobbleMode">Scrobble mode to use.</param> /// <returns>Parse result.</returns> public abstract FileParseResult Parse(string file, TimeSpan defaultDuration, ScrobbleMode scrobbleMode);
/// <summary> /// Parses the given <paramref name="file"/>. /// </summary> /// <param name="file">File to parse.</param> /// <param name="defaultDuration">Default duration for tracks.</param> /// <param name="scrobbleMode"></param> /// <returns>Parse result.</returns> public FileParseResult Parse(string file, TimeSpan defaultDuration, ScrobbleMode scrobbleMode) { if (string.IsNullOrEmpty(file)) { throw new ArgumentNullException(nameof(file)); } var scrobbles = new List <DatedScrobble>(); var errors = new List <string>(); string[] fields = null; using (var parser = new TextFieldParser(file, Encoding.GetEncoding(Settings.Default.CSVEncoding))) { parser.SetDelimiters(Settings.Default.CSVDelimiters.Select(x => new string(x, 1)).ToArray()); parser.HasFieldsEnclosedInQuotes = Settings.Default.CSVHasFieldsInQuotes; while (!parser.EndOfData) { try { fields = parser.ReadFields(); string dateString = fields.ElementAtOrDefault(Settings.Default.TimestampFieldIndex); // check for 'now playing' if (string.IsNullOrEmpty(dateString) && scrobbleMode == ScrobbleMode.Normal) { continue; } DateTime date = DateTime.Now; if (!FileParserBase.TryParseDateString(dateString, out date) && scrobbleMode == ScrobbleMode.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); if (!TimeSpan.TryParse(duration, out TimeSpan time)) { time = TimeSpan.FromSeconds(3); // todo: use user provided duration } scrobbles.Add(new DatedScrobble(date.AddSeconds(1), fields[Settings.Default.TrackFieldIndex], fields[Settings.Default.ArtistFieldIndex], album, albumArtist, time)); } catch (Exception ex) { string errorString = $"CSV line number: {parser.LineNumber - 1},"; // fields is old in this case if (!(ex is MalformedLineException)) { foreach (string s in fields) { errorString += $"{s},"; } } errorString += ex.Message; errors.Add(errorString); } } } return(new FileParseResult(scrobbles, errors)); }
protected override void OnClicked(int controlId, GUIControl control, MediaPortal.GUI.Library.Action.ActionType actionType) { OnClickedBase(controlId, control, actionType); if (control == btnSavedPlaylists) { OnShowSavedPlaylists(); } if (control == btnScrobbleUser) { // no users in database if (_scrobbleUsers.Count == 0) return; //for (int i = 0; i < scrobbleusers.Count; i++) GUIDialogMenu dlg = (GUIDialogMenu)GUIWindowManager.GetWindow((int)GUIWindow.Window.WINDOW_DIALOG_MENU); if (dlg != null) { dlg.Reset(); dlg.SetHeading(GUILocalizeStrings.Get(497));//Menu int selected = 0; int count = 0; foreach (string scrobbler in _scrobbleUsers) { dlg.Add(scrobbler); if (scrobbler == _currentScrobbleUser) selected = count; count++; } dlg.SelectedLabel = selected; } dlg.DoModal(GetID); if (dlg.SelectedLabel < 0) return; if (_currentScrobbleUser != dlg.SelectedLabelText) { _currentScrobbleUser = dlg.SelectedLabelText; btnScrobbleUser.Label = GUILocalizeStrings.Get(33005) + _currentScrobbleUser; AudioscrobblerBase.DoChangeUser(_currentScrobbleUser, mdb.AddScrobbleUserPassword(Convert.ToString(mdb.AddScrobbleUser(_currentScrobbleUser)), "")); LoadScrobbleUserSettings(); UpdateButtonStates(); } GUIControl.FocusControl(GetID, controlId); return; }//if (control == btnScrobbleUser) if (control == btnScrobbleMode) { bool shouldContinue = false; do { shouldContinue = false; GUIDialogMenu dlg = (GUIDialogMenu)GUIWindowManager.GetWindow((int)GUIWindow.Window.WINDOW_DIALOG_MENU); if (dlg != null) { dlg.Reset(); dlg.SetHeading(GUILocalizeStrings.Get(33010)); // Automatically fill playlist with dlg.Add(GUILocalizeStrings.Get(33011)); // similar tracks dlg.Add(GUILocalizeStrings.Get(33017)); // random tracks if (_enableScrobbling) { dlg.Add(GUILocalizeStrings.Get(33012)); // tracks your neighbours like dlg.Add(GUILocalizeStrings.Get(33016)); // tracks your friends like //dlg.Add(GUILocalizeStrings.Get(33014)); // tracks played recently //dlg.Add(GUILocalizeStrings.Get(33013)); // tracks suiting configured tag {0} } dlg.DoModal(GetID); if (dlg.SelectedLabel < 0) return; switch (dlg.SelectedId) { case 1: currentScrobbleMode = ScrobbleMode.Similar; btnScrobbleMode.Label = GUILocalizeStrings.Get(33001); break; case 2: currentScrobbleMode = ScrobbleMode.Random; btnScrobbleMode.Label = GUILocalizeStrings.Get(33007); break; case 3: currentScrobbleMode = ScrobbleMode.Neighbours; btnScrobbleMode.Label = GUILocalizeStrings.Get(33002); break; case 4: currentScrobbleMode = ScrobbleMode.Friends; btnScrobbleMode.Label = GUILocalizeStrings.Get(33006); break; case 5: currentScrobbleMode = ScrobbleMode.Recent; btnScrobbleMode.Label = GUILocalizeStrings.Get(33004); break; case 6: currentScrobbleMode = ScrobbleMode.Tags; btnScrobbleMode.Label = GUILocalizeStrings.Get(33003); break; default: currentScrobbleMode = ScrobbleMode.Random; btnScrobbleMode.Label = GUILocalizeStrings.Get(33007); break; } if (currentScrobbleMode == ScrobbleMode.Random) if (currentOfflineMode == offlineMode.favorites) { MusicDatabase checkdb = MusicDatabase.Instance; if (checkdb.GetTotalFavorites() <= _maxScrobbledArtistsForSongs * 2) { shouldContinue = true; Log.Warn("Audioscrobbler playlist: Cannot activate offline mode: favorites because there are not enough tracks"); } } } } while (shouldContinue); CheckScrobbleInstantStart(); GUIControl.FocusControl(GetID, controlId); return; }//if (control == btnScrobbleMode) if (control == btnShuffle) { ShufflePlayList(); } else if (control == btnSave) { SavePlayList(); } else if (control == btnClear) { ClearPlayList(); } else if (control == btnNowPlaying) { GUIWindowManager.ActivateWindow(29052); } //else if (control == btnPlay) //{ // playlistPlayer.CurrentPlaylistType = PlayListType.PLAYLIST_MUSIC; // playlistPlayer.Reset(); // playlistPlayer.Play(facadeView.SelectedListItemIndex); // UpdateButtonStates(); //} else if (control == btnScrobble) { //if (_enableScrobbling) //{ //get state of button if (btnScrobble.Selected) { ScrobblerOn = true; CheckScrobbleInstantStart(); } else ScrobblerOn = false; if (facadeView.PlayListView != null) //{ // // Prevent the currently playing track from being scrolled off the top // // or bottom of the screen when other items are re-ordered // facadeView.PlayListView.AllowLastVisibleListItemDown = !ScrobblerOn; // facadeView.PlayListView.AllowMoveFirstVisibleListItemUp = !ScrobblerOn; //} UpdateButtonStates(); } else if ((btnRepeatPlaylist != null) && (control == btnRepeatPlaylist)) { playlistPlayer.RepeatPlaylist = btnRepeatPlaylist.Selected; } }
protected override void OnPageLoad() { base.OnPageLoad(); if (string.IsNullOrEmpty(playlistname)) { GUIPropertyManager.SetProperty("#currentmodule", "Playlist"); } else { GUIPropertyManager.SetProperty("#currentmodule", "Playlist/" + playlistname); } _playlistType = PlayListType.PLAYLIST_MUSIC_VIDEO; currentView = View.PlayList; facadeView.CurrentLayout = GUIFacadeControl.Layout.Playlist; LoadDirectory(string.Empty); if (m_iItemSelected >= 0) { GUIControl.SelectItemControl(GetID, facadeView.GetID, m_iItemSelected); } if ((m_iLastControl == facadeView.GetID) && facadeView.Count <= 0) { m_iLastControl = btnNowPlaying.GetID; GUIControl.FocusControl(GetID, m_iLastControl); } if (facadeView.Count <= 0) { GUIControl.FocusControl(GetID, btnViewAs.GetID); } using (MediaPortal.Profile.Settings settings = new MediaPortal.Profile.Settings(Config.GetFile(Config.Dir.Config, "MediaPortal.xml"))) { playlistPlayer.RepeatPlaylist = settings.GetValueAsBool("youtubeplaylist", "repeat", true); ScrobblerOn = settings.GetValueAsBool("youtubeplaylist", "ScrobblerOn", true); currentScrobbleMode =(ScrobbleMode) settings.GetValueAsInt("youtubeplaylist", "ScrobblerMode", 0); } if (btnRepeatPlaylist != null) { btnRepeatPlaylist.Selected = playlistPlayer.RepeatPlaylist; } if (ScrobblerOn) btnScrobble.Selected = true; SetScrobbleButonLabel(); SelectCurrentPlayingSong(); }
protected override void OnClicked(int controlId, GUIControl control, MediaPortal.GUI.Library.Action.ActionType actionType) { OnClickedBase(controlId, control, actionType); if (control == btnSavedPlaylists) { OnShowSavedPlaylists(); } if (control == btnScrobbleMode) { GUIDialogMenu dlg = (GUIDialogMenu)GUIWindowManager.GetWindow((int)GUIWindow.Window.WINDOW_DIALOG_MENU); if (dlg != null) { dlg.Reset(); dlg.SetHeading(Translation.AutomaticallyFillPlaylist); // Automatically fill playlist with dlg.Add(Translation.ScrobbleSimilarVideos); // similar tracks //dlg.Add(GUILocalizeStrings.Get(33017)); // random tracks if (Youtube2MP.LastFmProfile.IsLoged) { dlg.Add(Translation.ScrobbleNeighboursLike); // tracks your neighbours like //dlg.Add(GUILocalizeStrings.Get(33016)); // tracks your friends like dlg.Add(Translation.ScrobbleRecentlyPlayed); // tracks played recently //dlg.Add(GUILocalizeStrings.Get(33013)); // tracks suiting configured tag {0} } dlg.SelectedId = (int) currentScrobbleMode; dlg.DoModal(GetID); if (dlg.SelectedId < 0) return; if (dlg.SelectedLabelText == Translation.ScrobbleSimilarVideos) { currentScrobbleMode = ScrobbleMode.Youtube; } else if (dlg.SelectedLabelText == Translation.ScrobbleNeighboursLike) { currentScrobbleMode = ScrobbleMode.Neighbours; } else if (dlg.SelectedLabelText == Translation.ScrobbleRecentlyPlayed) { currentScrobbleMode = ScrobbleMode.Recent; } SetScrobbleButonLabel(); } GUIControl.FocusControl(GetID, controlId); return; } //if (control == btnScrobbleMode) if (control == btnShuffle) { ShufflePlayList(); } else if (control == btnSave) { SavePlayList(); } else if (control == btnClear) { ClearPlayList(); } else if (control == btnNowPlaying) { GUIWindowManager.ActivateWindow(29052); } else if (control == btnScrobble) { //if (_enableScrobbling) //{ //get state of button if (btnScrobble.Selected) { ScrobblerOn = true; } else ScrobblerOn = false; if (facadeView.PlayListLayout != null) UpdateButtonStates(); } else if ((btnRepeatPlaylist != null) && (control == btnRepeatPlaylist)) { playlistPlayer.RepeatPlaylist = btnRepeatPlaylist.Selected; } }