示例#1
0
 public iLyrics()
 {
     InitializeComponent();
     _iTunesApp = new iTunesAppClass();
     _iTunesApp.BrowserWindow.Visible   = true;
     _iTunesApp.BrowserWindow.Minimized = false;
 }
示例#2
0
 public iLyrics()
 {
     InitializeComponent();
     _iTunesApp = new iTunesAppClass();
     _iTunesApp.BrowserWindow.Visible = true;
     _iTunesApp.BrowserWindow.Minimized = false;
 }
示例#3
0
 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));
        }
示例#6
0
        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));
        }
示例#7
0
        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);
        }
示例#10
0
        /// <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;
        }
示例#12
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());
 }
示例#16
0
        /// <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}");
            }
        }
示例#17
0
 public void Init(PluginInitContext context)
 {
     _itApp = null;
 }
示例#18
0
 public string GetText(IiTunes iTunes)
 {
     return(iTunes.CurrentPlaylist.Name);
 }
示例#19
0
 public string GetText(IiTunes iTunes)
 {
     return(iTunes.CurrentTrack.Name);
 }
示例#20
0
 private void InitializeiTunes()
 {
     _iTunes = new iTunesApp();
 }
示例#21
0
 private static void SyncConnectedIpods(IiTunes app)
 {
     foreach (var ipodSource in app.Sources.OfType<IITIPodSource>())
     {
         ipodSource.UpdateIPod();
     }
 }
示例#22
0
 public string GetText(IiTunes iTunes)
 {
     return(iTunes.CurrentTrack.Artist);
 }
示例#23
0
        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);
        }