public static void Scrobble(TrackInfo t, bool chosenByUser) { var parameters = t.GetParametersDictionary(); parameters.Add("method", "track.scrobble"); parameters.Add("timestamp", Util.GetUnixTimestamp().ToString()); if (!chosenByUser) parameters.Add("chosenByUser", "0"); var resp = LfmServiceProxy.GetResponse(parameters); }
public static IAsyncResult ScrobbleAsync(TrackInfo t, Action callback) { var parameters = t.GetParametersDictionary(); parameters.Add("method", "track.scrobble"); parameters.Add("timestamp", Util.GetUnixTimestamp().ToString()); return LfmServiceProxy.GetResponseAsync(parameters, (doc) => { if (callback != null) callback(); }); }
public static void UpdateNowPlaying(TrackInfo t) { var parameters = t.GetParametersDictionary(); parameters.Add("method", "track.updateNowPlaying"); var resp = LfmServiceProxy.GetResponse(parameters); }
public static IAsyncResult UpdateNowPlayingAsync(TrackInfo t) { var parameters = t.GetParametersDictionary(); parameters.Add("method", "track.updateNowPlaying"); return LfmServiceProxy.GetResponseAsync(parameters, null); }
/// <summary> /// Update the data about the currently playing song /// </summary> private void UpdateTrackData() { string filename = SendIPCCommandString(IPCCommand.GetFilename); //Logger.Instance.LogMessage("Filename = " + filename); bool hasMetadata = true; string playlistTitle = GetMetadata(filename, "title"); string title = playlistTitle; string artist = GetMetadata(filename, "artist"); string year = GetMetadata(filename, "year"); string album = GetMetadata(filename, "album"); string duration = GetMetadata(filename, "length"); string num = GetMetadata(filename, "track"); string bitrate = GetMetadata(filename, "bitrate"); string vbr = GetMetadata(filename, "vbr"); // if winamp can't get bitrate, then user is listening // to a radiostream or a track without an ID3 tag [UPD: ...or a .cue-file with the cue-player plug-in] //if (string.IsNullOrEmpty(bitrate)) // hasMetadata = false; // If the title is blank, we don't have any metadata :( // Better just get whatever Winamp gives us as the "title", and save // that. if (string.IsNullOrEmpty(artist) || string.IsNullOrEmpty(title)) //(String.IsNullOrEmpty(playlistTitle)) { playlistTitle = SendIPCCommandString(IPCCommand.GetTitle); } // [in case the user is playing a radio stream] // strip out the '[Buffer: XX%]' substring from the title before we compare it with the current title playlistTitle = Regex.Replace(playlistTitle, @"\[Buffer: \d{1,2}%\] ", "", RegexOptions.IgnoreCase); // Only update the data if it's changed //if (CurrentSong.Title == playlistTitle || CurrentSong.StreamTitle == playlistTitle) if ((!filename.Contains("http://") && CurrentTrack.Filename == filename) || (filename.Contains("http://") && CurrentTrack.PlaylistTitle == playlistTitle) || playlistTitle.Contains("http://")) { return; } long d = 0; long.TryParse(duration, out d); if (string.IsNullOrEmpty(artist) || string.IsNullOrEmpty(title)) { hasMetadata = false; } var track = new TrackInfo(artist, title) { Album = album, Year = year, Duration = d, // milliseconds Filename = filename, PlaylistTitle = playlistTitle, HasMetadata = hasMetadata }; if (string.IsNullOrEmpty(artist) || string.IsNullOrEmpty(title)) { TrackInfo.TryParseFromPlaylistTitle(playlistTitle, hasMetadata, ref track); } CurrentTrack = track; OnSongChanged(new TrackInfoEventArgs(track)); }
/// <summary> /// Initialise the Winamp class. Called from the constructor /// </summary> private void Init() { Logger.WriteEmptyLine(); Logger.LogMessage("hWnd: " + _WinampWindow); // Start with a blank "currently playing" song CurrentTrack = new TrackInfo("", ""); // Update the song data //Logger.Instance.LogMessage("init updateSongData"); //UpdateSongData(); // And now, let's set up our subclassing. We can only do this if we're // "in process", so let's bail if we're not. if (!_InProcess) { // TODO: This should not be a messagebox. This is just for debugging. System.Windows.Forms.MessageBox.Show("Not running 'in process', certain features will not work!"); return; } // Here's our delegate _WinampWndProc = new Win32.Win32WndProc(WinampWndProc); // Make sure it doesn't get garbage collected GC.KeepAlive(_WinampWndProc); // Let's go ahead and set the new one, saving the old one _OldWinampWndProc = Win32.SetWindowLong(_WinampWindow, Win32.GWL_WNDPROC, _WinampWndProc); Logger.LogMessage("Subclassed Winamp window (old proc = " + _OldWinampWndProc + ", new proc = " + _WinampWndProc + ")"); }
/// <summary> /// Create a new instance of SongChangedEventArgs for a specified song /// </summary> /// <param name="track">The current track</param> public TrackInfoEventArgs(TrackInfo track) { Track = track; }
public static bool TryParseFromPlaylistTitle(string playlistTitle, bool hasMetadata, ref TrackInfo track) { var songTitle = playlistTitle; if (!HasFileExtension(playlistTitle) && !hasMetadata) // radio stream { //track.IsChosenByUser = false; // strip out text in parentheses (which we believe to be a station name) at the end of string var streamName = Regex.Match(playlistTitle, @" (((?'Open'\()[^\(\)]*)+((?'Close-Open'\))[^\(\)]*)+)(?(Open)(?!))$"); if (!string.IsNullOrEmpty(streamName.Value)) { songTitle = playlistTitle.Replace(streamName.Value, ""); } } else // a file without an ID3 tag songTitle = StripOutFileExtension(songTitle); var match = Regex.Match(songTitle, @"(.+?) - (.+)"); if (match.Success) { var artist = match.Groups[1].Value; var title = match.Groups[2].Value; track.Artist = artist; track.Title = title; track.HasMetadata = true; track.PlaylistTitle = playlistTitle; return true; } return false; }
void LogTrackInfo(TrackInfo t) { var info = t.GetInfoString(includeDuration: true, includeChosenByUser: true); Logger.LogMessage(info, "Track data"); //System.Windows.Forms.MessageBox.Show(info, "Song info"); }