public iLyrics() { InitializeComponent(); _iTunesApp = new iTunesAppClass(); _iTunesApp.BrowserWindow.Visible = true; _iTunesApp.BrowserWindow.Minimized = false; }
private static void SyncConnectedIpods(IiTunes app) { foreach (var ipodSource in app.Sources.OfType <IITIPodSource>()) { ipodSource.UpdateIPod(); } }
public string GetText(IiTunes iTunes) { if (iTunes.CurrentPlaylist.Kind == ITPlaylistKind.ITPlaylistKindUser) { return(((IITUserPlaylist)iTunes.CurrentPlaylist).SpecialKind == ITUserPlaylistSpecialKind.ITUserPlaylistSpecialKindMusic ? "Album" : "Playlist"); } return("Album"); }
public static PersistentID GetTrackPersistentID(IiTunes iTunesApp, IITTrack t) { int persistentId_High; int persistentId_Low; object refFileTrack = (object)t; iTunesApp.GetITObjectPersistentIDs(ref refFileTrack, out persistentId_High, out persistentId_Low); return(new PersistentID(persistentId_High, persistentId_Low)); }
public List <Result> Query(Query query) { try { if (_itApp == null) { return(new List <Result> { new Result { Title = "Start Itunes Plugin", SubTitle = "", IcoPath = "Images\\Itunes.png", Action = e => { _itApp = new iTunesApp(); return true; } } }); } else if (query.Search.Contains("exit")) { return(new List <Result> { new Result { Title = "Quit Itunes", SubTitle = "", IcoPath = "Images\\Itunes.png", Action = e => { _itApp.Quit(); _itApp = null; return true; } } }); } } catch (Exception) { // TODO: Something to start the Itunes music player throw; } if (string.IsNullOrWhiteSpace(query.Search)) { return(StandardMenu()); } return(SearchTrack(query)); }
public string GetText(IiTunes iTunes) { if (_lastPush == 0) { _lastPush = DateTimeOffset.Now.ToUnixTimeSeconds(); return("Never"); } var now = DateTimeOffset.Now.ToUnixTimeSeconds(); var diff = now - _lastPush; _lastPush = now; return($"{diff} seconds ago"); }
private void tryEstablishConnect() { Process[] processes = Process.GetProcessesByName("iTunes"); if (processes.Length != 0 && processes[0].Id != pid) { pid = processes[0].Id; iTunes = new iTunesAppClass(); connectDown = false; } else { connectDown = true; trackName = getTrackNameInternal(); } }
public static Track GetTrack(IITFileOrCDTrack iFCT, IiTunes iTunesApp) { string filePath = iFCT.Location; string artist = iFCT.Artist; string albumArtist = iFCT.AlbumArtist; string album = iFCT.Album; string title = iFCT.Name; int trackNumber = iFCT.TrackNumber; int artworkCount = iFCT.Artwork.Count; PersistentID persistentID = PersistentID.GetTrackPersistentID(iTunesApp, iFCT); Track t = new Track(persistentID, filePath, artist, albumArtist, album, title, trackNumber, artworkCount); return(t); }
/// <summary> /// Create the instance to use /// </summary> static void InitializeServices() { ConfigureServices(); if (iTunesFeat) { iTunes = new iTunesApp(); //new instance of itunes using COM service } if (SpotifyFeat) { //Check for spotify errors before connecting if (!SpotifyLocalAPI.IsSpotifyInstalled()) { throw new Exception("Spotify Not Installed"); //Why run spotify mode if you don't have it installed? } if (!SpotifyLocalAPI.IsSpotifyRunning()) { SpotifyLocalAPI.RunSpotify(); //Start spotify if not running } if (!SpotifyLocalAPI.IsSpotifyWebHelperRunning()) { SpotifyLocalAPI.RunSpotifyWebHelper(); //Start webhelper if not running } Spotify = new SpotifyLocalAPI(); //new instance if (!Spotify.Connect()) //critical { throw new Exception("Couldn't connect to spotify"); } } if (FoobarFeat) { var ip = Arguments.FirstOrDefault(x => x.StartsWith("--foo-ip=", StringComparison.Ordinal)); //gets foo-ip if (ip != null) //checks for null { ip = ip.Remove(0, "--foo-ip=".Length); //remove the argument text if (int.TryParse(Arguments.FirstOrDefault(x => x.StartsWith("--foo-port=", StringComparison.Ordinal)).Remove(0, "--foo-port=".Length), out int port) && ip != null) //tries to convert foo-port argument to int after removing text, and checks if ip isn't null { Foobar = new Foobar(ip, Convert.ToInt32(port)); //use user-args } return; } Foobar = new Foobar("localhost", 8888); //no user-args, use default } }
/// <summary> /// Initializes the bridge and connects it to DiscordRPC /// </summary> /// <param name="applicationId">The Discord application ID for rich presence</param> public DiscordBridge(string applicationId) { var handlers = new DiscordRpc.EventHandlers(); DiscordRpc.Initialize(applicationId, ref handlers, true, null); Tokens = AppDomain.CurrentDomain.GetAssemblies().SelectMany(s => s.GetTypes()).Where(p => typeof(IToken).IsAssignableFrom(p) && p.IsClass).Select(Activator.CreateInstance).Select(i => (IToken)i).ToList(); _iTunes = new iTunesApp(); _timer = new DispatcherTimer { Interval = TimeSpan.FromSeconds(15) }; _timer.Tick += Timer_OnTick; _timer.Start(); _currentArtist = ""; _currentTitle = ""; _currentState = ITPlayerState.ITPlayerStateStopped; _currentPosition = 0; }
public string GetText(IiTunes iTunes) { return(iTunes.CurrentTrack.Year.ToString()); }
public string GetText(IiTunes iTunes) { return(iTunes.CurrentTrack.PlayedCount.ToString()); }
/// <summary> /// Handles checking for playing status changes and pushing out presence updates /// </summary> /// <param name="sender">Sender of this event</param> /// <param name="e">Args of this event</param> private void Timer_OnTick(object sender, EventArgs e) { try { if (_iTunes == null) { _iTunes = new iTunesApp(); } if (_iTunes.CurrentTrack == null) { DiscordRpc.ClearPresence(); return; } } catch (COMException) { _iTunes = null; var newPresence = new DiscordRpc.RichPresence { largeImageKey = "itunes_logo_big", details = "Error connecting to iTunes", state = "Playback information unavailable" }; DiscordRpc.UpdatePresence(newPresence); return; } if (_currentArtist == _iTunes.CurrentTrack.Artist && _currentTitle == _iTunes.CurrentTrack.Name && _currentState == _iTunes.PlayerState && _currentPosition == _iTunes.PlayerPosition) { return; } _currentArtist = _iTunes.CurrentTrack.Artist; _currentTitle = _iTunes.CurrentTrack.Name; _currentState = _iTunes.PlayerState; _currentPosition = _iTunes.PlayerPosition; var presence = new DiscordRpc.RichPresence { largeImageKey = "itunes_logo_big" }; if (_currentState != ITPlayerState.ITPlayerStatePlaying) { presence.details = TruncateString(RenderString(Settings.Default.PausedTopLine)); presence.state = TruncateString(RenderString(Settings.Default.PausedBottomLine)); } else { presence.details = TruncateString(RenderString(Settings.Default.PlayingTopLine)); presence.state = TruncateString(RenderString(Settings.Default.PlayingBottomLine)); if (Settings.Default.DisplayPlaybackDuration) { presence.startTimestamp = DateTimeOffset.Now.ToUnixTimeSeconds() - _currentPosition; presence.endTimestamp = DateTimeOffset.Now.ToUnixTimeSeconds() + (_iTunes.CurrentTrack.Duration - _currentPosition); } } try { DiscordRpc.UpdatePresence(presence); } catch (Exception exception) { exception.Data.Add("CurrentArtist", _currentArtist); exception.Data.Add("CurrentTitle", _currentTitle); exception.Data.Add("CurrentState", _currentState.ToString()); exception.Data.Add("CurrentPosition", _currentPosition.ToString()); exception.Data.Add("Details", presence.details); exception.Data.Add("State", presence.state); Globals.RavenClient.Capture(new SentryEvent(exception)); Globals.Log($"An unhandled exception has occurred and been reported to Sentry: {exception.Message}"); } }
public string GetText(IiTunes iTunes) { _pushes++; return(_pushes.ToString()); }
/// <summary> /// Handles checking for playing status changes and pushing out presence updates /// </summary> /// <param name="sender">Sender of this event</param> /// <param name="e">Args of this event</param> private void Timer_OnTick(object sender, EventArgs e) { try { if (ITunes == null) { ITunes = new iTunesApp(); } if (ITunes.CurrentTrack == null || (Settings.Default.ClearOnPause && ITunes.PlayerState != ITPlayerState.ITPlayerStatePlaying)) { DiscordRpc.ClearPresence(); return; } } catch (COMException) { ITunes = null; var newPresence = new DiscordRpc.RichPresence { largeImageKey = "itunes_logo_big", details = "Error connecting to iTunes", state = "Playback information unavailable" }; DiscordRpc.UpdatePresence(newPresence); return; } catch (EntryPointNotFoundException) { var newPresence = new DiscordRpc.RichPresence { largeImageKey = "itunes_logo_big", details = "No song playing", state = "Re-install iTunesRichPresence to clear this message" }; DiscordRpc.UpdatePresence(newPresence); return; } if (_currentArtist == ITunes.CurrentTrack.Artist && _currentTitle == ITunes.CurrentTrack.Name && _currentState == ITunes.PlayerState && _currentPosition == ITunes.PlayerPosition) { return; } _currentArtist = ITunes.CurrentTrack.Artist; _currentTitle = ITunes.CurrentTrack.Name; _currentState = ITunes.PlayerState; _currentPosition = ITunes.PlayerPosition; int _currentAlbumCoverCount = ITunes.CurrentTrack.Artwork.Count; string PREFIX = "itlps-"; foreach (var artT in ITunes.CurrentTrack.Artwork) { var art = artT as IITArtwork; string ext = ".tmp"; switch (art.Format) { case ITArtworkFormat.ITArtworkFormatBMP: ext = ".bmp"; break; case ITArtworkFormat.ITArtworkFormatJPEG: ext = ".jpg"; break; case ITArtworkFormat.ITArtworkFormatPNG: ext = ".png"; break; } string path = Path.Combine(Path.GetTempPath(), PREFIX + Path.GetRandomFileName() + ext); art.SaveArtworkToFile(path); //Debug.WriteLine(path); } Debug.WriteLine("DB ID: " + ITunes.CurrentTrack.TrackDatabaseID); Debug.WriteLine("Track ID: " + ITunes.CurrentTrack.trackID); Debug.WriteLine("Artwork: " + ITunes.CurrentTrack.Artwork); var presence = new DiscordRpc.RichPresence { largeImageKey = path }; if (_currentState != ITPlayerState.ITPlayerStatePlaying) { presence.details = TruncateString(RenderString(Settings.Default.PausedTopLine)); presence.state = TruncateString(RenderString(Settings.Default.PausedBottomLine)); } else { presence.details = "[" + _currentArtist + "](https://google.co.uk)"; //Embed top line presence.state = _currentTitle; //Embed bottom line. if (Settings.Default.DisplayPlaybackDuration) { presence.startTimestamp = DateTimeOffset.Now.ToUnixTimeSeconds() - _currentPosition; presence.endTimestamp = DateTimeOffset.Now.ToUnixTimeSeconds() + (ITunes.CurrentTrack.Duration - _currentPosition); } } try { DiscordRpc.UpdatePresence(presence); } catch (Exception exception) { exception.Data.Add("CurrentArtist", _currentArtist); exception.Data.Add("CurrentTitle", _currentTitle); exception.Data.Add("CurrentState", _currentState.ToString()); exception.Data.Add("CurrentPosition", _currentPosition.ToString()); exception.Data.Add("Details", presence.details); exception.Data.Add("State", presence.state); Globals.RavenClient.Capture(new SentryEvent(exception)); Globals.Log($"An unhandled exception has occurred and been reported to Sentry: {exception.Message}"); } }
public void Init(PluginInitContext context) { _itApp = null; }
public string GetText(IiTunes iTunes) { return(iTunes.CurrentPlaylist.Name); }
public string GetText(IiTunes iTunes) { return(iTunes.CurrentTrack.Name); }
private void InitializeiTunes() { _iTunes = new iTunesApp(); }
private static void SyncConnectedIpods(IiTunes app) { foreach (var ipodSource in app.Sources.OfType<IITIPodSource>()) { ipodSource.UpdateIPod(); } }
public string GetText(IiTunes iTunes) { return(iTunes.CurrentTrack.Artist); }
public static int CleaniTunesPlaylistByPlayed(DownloadItem item, IITPlaylist playlist, IiTunes iitApp) { int tracksremoved = 0; try { FeedItem feedItem = Settings.Default.Feeds[item.FeedGUID]; ArrayList tracks = new ArrayList(); foreach (IITFileOrCDTrack track in playlist.Tracks) { tracks.Add(track); } for (int q = 0; q < tracks.Count; q++) { try { IITFileOrCDTrack track = (IITFileOrCDTrack)tracks[q]; if (track.PlayedCount == 1) { string trackName = track.Name; int trackID = track.trackID; if (Settings.Default.LogLevel > 0) { log.Info(String.Format("Track {0} has been listened to. Deleted", track.Name)); } if (File.Exists(track.Location)) { tracksremoved++; File.Delete(track.Location); } track.Delete(); // remove the entry completely from the library, it's dead anyway try { IITFileOrCDTrack libraryTrack = (IITFileOrCDTrack)iitApp.LibraryPlaylist.Tracks.get_ItemByName(trackName); while (libraryTrack != null && libraryTrack.Location != "") { libraryTrack.Delete(); libraryTrack = (IITFileOrCDTrack)iitApp.LibraryPlaylist.Tracks.get_ItemByName(trackName); } } catch (Exception ex) { if (Settings.Default.LogLevel > 0) { log.Error(ex); } } } } catch { } } } catch (Exception ex) { if (Settings.Default.LogLevel > 0) { log.Error("Error while communicating with iTunes", ex); } } return(tracksremoved); }