private void TryScrobble(string title, string artist, string album, int duration) { if (hasScrobbled) { return; } played += (int)DateTime.UtcNow.Subtract(started).TotalMilliseconds; if (played < Api.NowPlaying_GetDuration() / 2 && played < 240000) { return; } hasScrobbled = true; played = 0; LastFM.Scrobble(title, artist, album, (duration / 1000).ToString()); }
private async void ButtonSubmit_Click(object sender, EventArgs e) { if (shouldLogin) { LastFM.Response res = await LastFM.Login(TextBoxKey.Text, TextBoxSecret.Text, TextBoxUsername.Text, TextBoxPassword.Text); if (res.Code > 0) { string msg = ""; switch (res.Code) { case 4: msg = "Wrong username or password!"; break; case 6: msg = "Missing values!"; break; case 10: msg = "Invalid key!"; break; case 13: msg = "Invalid secret!"; break; } MessageBox.Show(msg, "ScrobbleBee", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } Settings.Session = res.Data; } Settings.Key = TextBoxKey.Text; Settings.Secret = TextBoxSecret.Text; Settings.Title = (MetaDataType)ComboBoxTitle.SelectedValue; Settings.Artist = (MetaDataType)ComboBoxArtist.SelectedValue; Settings.Album = (MetaDataType)ComboBoxAlbum.SelectedValue; Settings.Save(); Close(); }
public void ReceiveNotification(string src, NotificationType type) { if (type != NotificationType.TrackChanged && type != NotificationType.PlayStateChanged) { return; } string title = Api.NowPlaying_GetFileTag(Settings.Title); string artist = Api.NowPlaying_GetFileTag(Settings.Artist); string album = Api.NowPlaying_GetFileTag(Settings.Album); int duration = Api.NowPlaying_GetDuration(); switch (type) { case NotificationType.TrackChanged: TryScrobble(lastTitle, lastArtist, lastAlbum, lastDuration); LastFM.Update(title, artist, album, (duration / 1000).ToString()); hasScrobbled = duration < 30000; started = DateTime.UtcNow; played = 0; lastTitle = title; lastArtist = artist; lastAlbum = album; lastDuration = duration; break; case NotificationType.PlayStateChanged: switch (Api.Player_GetPlayState()) { case PlayState.Playing: started = DateTime.UtcNow; break; case PlayState.Paused: case PlayState.Stopped: TryScrobble(title, artist, album, duration); break; } break; } }
public static PluginInfo Initialise(IntPtr ApiPtr) { Api = new MusicBeeApiInterface(); Api.Initialise(ApiPtr); Settings.Load(Path.Combine(Api.Setting_GetPersistentStoragePath(), "ScrobbleBee.ini")); LastFM.Login(Settings.Key, Settings.Secret, Settings.Session); return(new PluginInfo { Type = PluginType.General, Name = "ScrobbleBee", Description = "Customizable scrobbling for MusicBee.", Author = "Karl Köörna", VersionMajor = 1, VersionMinor = 0, Revision = 1, PluginInfoVersion = PluginInfoVersion, MinInterfaceVersion = MinInterfaceVersion, MinApiRevision = MinApiRevision, ReceiveNotifications = ReceiveNotificationFlags.PlayerEvents, ConfigurationPanelHeight = 0 }); }