public static void nextTrack()
        {
            var app = new iTunesApp();

            app.NextTrack();
            app = null;
        }
        public static void pausePlay()
        {
            var app = new iTunesApp();

            app.PlayPause();
            app = null;
        }
        public static void previousTrack()
        {
            var app = new iTunesApp();

            app.PreviousTrack();
            app = null;
        }
        public static void volumeDown()
        {
            var app = new iTunesApp();

            app.SoundVolume -= 5;
            app              = null;
        }
Beispiel #5
0
        //ツイート
        private void button2_Click(object sender, RoutedEventArgs e)
        {
            //iTunes COMのセットアップ
            iTunesApp iTunes = new iTunesApp();
            IITTrack  track  = iTunes.CurrentTrack;

            if (iTunes == null)
            {
                System.Windows.Forms.MessageBox.Show("iTunesで曲が再生されていません");
                return;
            }


            //変数の指定
            var AlbumName  = track.Album;
            var TrackInfo  = track.TrackNumber + " / " + track.TrackCount;
            var Artist     = track.Artist;
            var TrackName  = track.Name;
            var Ruledline  = "│";
            var nowplaying = "#nowplaying\n";
            IITArtworkCollection artwork = track.Artwork;
            DateTime             dt      = DateTime.Now;

            //ツイート
            var text = nowplaying + AlbumName + Ruledline + TrackName + Ruledline + Artist + Ruledline + dt;

            tokens.Statuses.Update(status => text);

            //お知らせ
            System.Windows.Forms.MessageBox.Show("実行します。");
        }
Beispiel #6
0
        private static void getLibrary()
        {
            iTunesApp app = new iTunesApp();

            app.ForceToForegroundOnDialog = true;

            IITTrackCollection tc = app.LibraryPlaylist.Tracks;

            Controller.ShowMessage(tc.Count.ToString() + " tracks found...");

            List <string> tracks = new List <string>();

            foreach (IITTrack t in tc)
            {
                if (Cancel)
                {
                    break;
                }

                if (t.Kind == ITTrackKind.ITTrackKindFile)
                {
                    string l = (t as IITFileOrCDTrack).Location;
                    Controller.ShowMessage(t.Name);
                    tracks.Add(l);
                }
            }
            if (!Cancel)
            {
                FileAdder.AddItemsToLibrary(tracks, String.Empty, true, Controller.GetInstance().RefreshAll);
            }
        }
        public static void NextSong()
        {
            iTunesApp app = new iTunesApp();

            app.NextTrack();
            app = null;
        }
        private void CloseITunes()
        {
            while (ReadyForSync == null)
            {
                ;                                      // Wait if still opening iTunes before trying to close
            }
            ReadyForSync = false;

            if (Device.DeviceName != null)
            {
                Device.DeviceName = null;
                // Tell MusicBee to call Eject()
                Plugin.MbApiInterface.MB_SendNotification(Plugin.CallbackType.StorageEject);
            }

            if (iTunes != null)
            {
                try
                {
                    iTunes.Quit();
                }
                catch (Exception x)
                {
                    Trace.WriteLine(x);
                }
                Marshal.ReleaseComObject(iTunes);
                iTunes = null;
            }

            OpenMenu.Enabled = true;
        }
Beispiel #9
0
        public static IEnumerable <IITFileOrCDTrack> GetAllTracks(this iTunesApp iTunes)
        {
            var library = iTunes.LibraryPlaylist;
            var tracks  = library.Tracks;

            try
            {
                for (var i = tracks.Count; i > 0; --i)
                {
                    var track = tracks[i];
                    if (track.Kind == ITTrackKind.ITTrackKindFile)
                    {
                        yield return((IITFileOrCDTrack)track);
                    }
                    else
                    {
                        Marshal.ReleaseComObject(track);
                    }
                }
            }
            finally
            {
                Marshal.ReleaseComObject(tracks);
                Marshal.ReleaseComObject(library);
            }
        }
        private void PlayMatched(iTunesApp itunes, String best_match, MatchType best_matchtype)
        {
            String temp_artist;

            switch (best_matchtype)
            {
            case MatchType.song:
                this.PlayMatchedSong(itunes, best_match);
                break;

            case MatchType.song_artist:
                String song;
                ujoin(best_match, out song, out temp_artist);
                this.PlayMatchedSong(itunes, song, temp_artist);
                break;

            case MatchType.album:
                this.PlayMatchedAlbum(itunes, best_match);
                break;

            case MatchType.album_artist:
                String album;
                ujoin(best_match, out album, out temp_artist);
                this.PlayMatchedAlbum(itunes, album, temp_artist);
                break;

            case MatchType.artist:
                this.PlayMatchedArtist(itunes, best_match);
                break;

            case MatchType.playlist:
                this.PlayMatchedPlaylist(itunes, best_match);
                break;
            }
        }
Beispiel #11
0
        private bool Init()
        {
            if (this.m_itunes == null)
            {
                // 아이튠즈가 실행중인지 확인
                if (this.GetWindowHandle() != IntPtr.Zero)
                {
                    try
                    {
                        this.m_itunes = new iTunesAppClass();
                        this.m_itunes.OnQuittingEvent += new _IiTunesEvents_OnQuittingEventEventHandler(this.m_itunes_OnQuittingEvent);
                        this.m_itunes.OnAboutToPromptUserToQuitEvent += new _IiTunesEvents_OnAboutToPromptUserToQuitEventEventHandler(this.m_itunes_OnAboutToPromptUserToQuitEvent);
                        this.m_itunes.OnPlayerPlayEvent += new _IiTunesEvents_OnPlayerPlayEventEventHandler(this.iTunes_SongChanged);
                        this.m_itunes.OnPlayerPlayingTrackChangedEvent += new _IiTunesEvents_OnPlayerPlayingTrackChangedEventEventHandler(this.iTunes_SongChanged);
                        return(true);
                    }
                    catch
                    { }
                }
            }
            else
            {
                // 아이튠즈가 실행중인지 확인
                if (this.GetWindowHandle() != IntPtr.Zero)
                {
                    return(true);
                }
                else
                {
                    this.DeleteITunes();
                }
            }

            return(false);
        }
        private void PlayMatchedSong(iTunesApp itunes, String song, String artist = null)
        {
            if (artist == null)
            {
                Logger.WriteLine("Playing Song: " + song);
            }
            else
            {
                Logger.WriteLine("Playing Song: " + song + ", by " + artist);
            }

            // Rather than storing the handle (will be incorrect when itunes closes and is reopened, just find playlist by searching!
            foreach (IITTrack track in itunes.LibraryPlaylist.Tracks)
            {
                if (track.Kind != ITTrackKind.ITTrackKindFile)
                {
                    continue;
                }
                if (track.Name != song)
                {
                    continue;
                }
                if (artist != null)
                {
                    if (track.Artist != artist)
                    {
                        continue;
                    }
                }
                this.SetupAndRunAutomatedPlaylist(itunes, track);
                return;
            }
            this.RefreshItunesData(itunes);
        }
        public static void PreviousSong()
        {
            iTunesApp app = new iTunesApp();

            app.PreviousTrack();
            app = null;
        }
Beispiel #14
0
        public static void Main(string[] args)
        {
            var _itApp = new iTunesApp();

            try
            {
                var songList = _itApp.LibraryPlaylist.Search("rain", ITPlaylistSearchField.ITPlaylistSearchFieldSongNames);

                if (songList != null)
                {
                    //var track = songList.ItemByPlayOrder[1];
                    //track.Play();
                    for (int i = 1; i <= songList.Count; i++)
                    {
                        System.Console.WriteLine(songList.ItemByPlayOrder[i].Name);
                        System.Console.ReadKey();
                        songList.ItemByPlayOrder[i].Play();
                    }
                }
            }
            catch (System.Exception ex)
            {
                throw ex;
            }
            System.Console.ReadKey();
        }
        public static void PlayPause()
        {
            iTunesApp app = new iTunesApp();

            app.PlayPause();
            app = null;
        }
        private void PlayMatchedArtist(iTunesApp itunes, String artist)
        {
            Logger.WriteLine("Playing Artist: " + artist);

            var tracks = new List <IITTrack>();

            // Rather than storing the handle (will be incorrect when itunes closes and is reopened, just find playlist by searching!
            foreach (IITTrack track in itunes.LibraryPlaylist.Tracks)
            {
                if (track.Kind != ITTrackKind.ITTrackKindFile)
                {
                    continue;
                }
                if (track.Artist != artist)
                {
                    continue;
                }
                tracks.Add(track);
            }
            if (tracks.Count > 0)
            {
                this.SetupAndRunAutomatedPlaylist(itunes, tracks.ToArray());
            }
            else
            {
                this.RefreshItunesData(itunes);
            }
        }
        public void SetupAndRunAutomatedPlaylist(iTunesApp itunes, params IITTrack[] tracks)
        {
            IITUserPlaylist pl;

            do // If we call delete mid loop, we sometimes don't get second instances of playlist.
            {
                pl = null;
                foreach (IITUserPlaylist old in itunes.LibrarySource.Playlists.OfType <IITUserPlaylist>())
                {
                    if (old.Name != automated_playlist_name)
                    {
                        continue;
                    }
                    pl = old;
                    break;
                }
                pl?.Delete();
            }while (pl != null);

            var sortable_tracks = tracks.Select(t => new SamTrack(t)).Sorted();

            pl = (IITUserPlaylist)(itunes.CreatePlaylist(automated_playlist_name));
            foreach (var t in sortable_tracks)
            {
                object track = t._Track;
                pl.AddTrack(ref track);
            }

            this.PlayPlaylist(pl);
        }
Beispiel #18
0
        private void DeleteITunes()
        {
            try
            {
                this.m_itunes.OnQuittingEvent -= this.m_itunes_OnQuittingEvent;
                this.m_itunes.OnAboutToPromptUserToQuitEvent -= this.m_itunes_OnAboutToPromptUserToQuitEvent;
                this.m_itunes.OnPlayerPlayEvent -= this.iTunes_SongChanged;
                this.m_itunes.OnPlayerPlayingTrackChangedEvent -= this.iTunes_SongChanged;
            }
            catch
            { }

            try
            {
                Marshal.ReleaseComObject(this.m_itunes);
            }
            catch
            { }

            GC.Collect();
            this.m_itunes = null;

            if (this.m_ad)
            {
                this.m_adTrack = null;
                this.m_timer.Change(Timeout.Infinite, Timeout.Infinite);
                this.m_timerDetect.Change(IParseRule.RefreshTimeSpan, IParseRule.RefreshTimeSpan);
            }
        }
Beispiel #19
0
        public static IEnumerable <IITUserPlaylist> GetPlaylists(this iTunesApp iTunes)
        {
            var library   = iTunes.LibrarySource;
            var playlists = library.Playlists;

            try
            {
                for (var i = playlists.Count; i > 0; --i)
                {
                    var playlist = playlists[i];
                    if (
                        playlist.Kind == ITPlaylistKind.ITPlaylistKindUser &&
                        ((IITUserPlaylist)playlist).SpecialKind == ITUserPlaylistSpecialKind.ITUserPlaylistSpecialKindNone &&
                        !((IITUserPlaylist)playlist).Smart
                        )
                    {
                        yield return((IITUserPlaylist)playlist);
                    }
                    else
                    {
                        Marshal.ReleaseComObject(playlist);
                    }
                }
            }
            finally
            {
                Marshal.ReleaseComObject(playlists);
                Marshal.ReleaseComObject(library);
            }
        }
        private void ComputeCurrentCDInfo(IProgress<ImportExportError> iIImportExportProgress)
        {
            try
            {
                iTunesApp iTunesApp = new iTunesApp();

                IITSourceCollection _sources = iTunesApp.Sources;

                var lib = iTunesApp.Sources.Cast<IITSource>().Where(s => s.Kind == ITSourceKind.ITSourceKindAudioCD).FirstOrDefault();

                if (lib == null)
                {
                    iIImportExportProgress.SafeReport(new ItunesCDNotFoundError());
                    return;
                }

                IITAudioCDPlaylist cd = lib.Playlists.get_ItemByName(lib.Name) as IITAudioCDPlaylist;

                if (cd == null)
                {
                    iIImportExportProgress.SafeReport(new ItunesUnknownError());
                    return;
                }

                IFullAlbumDescriptor ad = AlbumDescriptor.FromiTunes(cd);

                FoundCDInfo = new WebMatch<IFullAlbumDescriptor>(ad, MatchPrecision.Suspition, WebProvider.iTunes);
            }
            catch (Exception e)
            {
                Trace.WriteLine("iTunes CD information introspection failed "+e.ToString());
                iIImportExportProgress.SafeReport(new ITunesNotResponding());
            }
        }
 private void SongUpdateWatcher()
 {
     Trace.WriteLine("[DEBUG]song update watcher start.");
     while (true)
     {
         //wait
         Thread.Sleep(1000);
         sem.Wait();
         if (!isITunesInitialized)
         {
             break;
         }
         sem.Release();
         //Debug.WriteLine("[DEBUG]itunes COM initializing.");
         app = new iTunesApp();
         //Debug.WriteLine("[DEBUG]itunes COM initialized.");
         var ctrack = app.CurrentTrack;
         if (ctrack == null || app.PlayerState != ITPlayerState.ITPlayerStatePlaying)
         {
             ComRelease.FinalReleaseComObjects(ctrack, app);
             continue;
         }
         var trackdbid = ctrack?.TrackDatabaseID ?? 0;
         if (trackdbid != lastTrackID)
         {
             //song changed
             OnPlayerPlayingTrackChangedEvent(ctrack);
             lastTrackID = trackdbid;
         }
         ComRelease.FinalReleaseComObjects(ctrack, trackdbid, app);
     }
     Trace.WriteLine("[DEBUG]song update watcher stop.");
 }
Beispiel #22
0
        /// <summary>
        /// Creates a timer to release the iTunes library after so many minutes of inactivity
        /// </summary>
        /// <param name="maximumMinutes"></param>
        private static void LibraryTimer(int maximumMinutes)
        {
            Timer timer = new Timer(60 * 1000.0)
            {
                AutoReset = true
            };

            timer.Elapsed += (sender, e) =>
            {
                lock (syncRoot)
                {
                    idleTimer++;
                    if (idleTimer >= maximumMinutes)
                    {
                        if (library != null)
                        {
                            library.Quit();
                        }
                        library = null;
                        timer.Stop();
                        timer.Dispose();
                        timer = null;
                    }
                }
            };
            timer.Start();
        }
        private void buttonConnect_Click(object sender, EventArgs e)
        {
            iTunes = new iTunesApp();
            IITSourceCollection sources = iTunes.Sources;
            foreach (IITSource source in sources)
            {
                if (source.Kind == ITSourceKind.ITSourceKindLibrary)
                {
                    librarySource = source;
                    break;
                }
            }

            if (librarySource != null)
            {
                panelConnection.Visible = false;
                toolStripStatusLabelConnection.Text = "Connected to iTunes.";
                populatePlaylists();
                panelEditor.Visible = true;
            }
            else
            {
                toolStripStatusLabelConnection.Text = "iTunes connection failed.";
                MessageBox.Show("Unable to connect to iTunes or find the default library.");
                // todo
            }
        }
        /// <summary>
        /// Maps the specified iTunes playlist to a directory structure.
        /// </summary>
        /// <param name="playlistName">The playlist.</param>
        /// <returns>A directory structure which represents the specified iTunes playlist</returns>
        public static IEnumerable<ITunesDirectoryInfo> MapPlaylistToDirectoryStructure(string playlistName)
        {
            if (String.IsNullOrEmpty(playlistName))
                throw new ArgumentException("The playlist name name cannot be null or empty", Reflector.GetMemberName(() => playlistName));

            var root = new ITunesDirectoryInfo(playlistName);

            var files = new iTunesApp()
                .LibrarySource
                .Playlists
                .ItemByName[playlistName]
                .Tracks
                .Cast<IITFileOrCDTrack>();

            var tracksByArtist = files
                .GroupBy(file => file.Artist)
                .OrderBy(group => group.Key);

            var artistDirectories = new List<ITunesDirectoryInfo>();

            foreach (var artistGroup in tracksByArtist)
            {
                var albumGroups = artistGroup
                    .GroupBy(track => track.Album);

                // The artist name has to be normalized, so that it doesn't contain any characters that are invalid for a path
                string artistName = NormalizeArtistOrAlbumName(artistGroup.Key);

                var albumDirectories = albumGroups
                    .Select(album => new { Album = album, AlbumName = NormalizeArtistOrAlbumName(album.Key) })
                    .Select
                    (
                        directory =>
                        new ITunesDirectoryInfo
                        (
                            directory.AlbumName,
                            directory.Album
                                .Where(track => track.Location != null)
                                .Select
                                (
                                    track => (IFileInfo)new LocalFileInfo(new FileInfo(track.Location))
                                ),
                            null
                        )
                    )
                    .ToList(); //Execute the query immediately, because a streaming causes weird bugs

                var artistDirectory = new ITunesDirectoryInfo(artistName, albumDirectories, root);

                foreach (ITunesDirectoryInfo albumDirectory in artistDirectory.GetDirectories())
                {
                    albumDirectory.Parent = artistDirectory;
                }

                artistDirectories.Add(artistDirectory);
            }

            return artistDirectories;
        }
Beispiel #25
0
        public static long GetPersistentId(this iTunesApp iTunes, IITObject item)
        {
            object o = item;
            int    high, low;

            iTunes.GetITObjectPersistentIDs(ref o, out high, out low);
            return(Encode(high, low));
        }
Beispiel #26
0
 public AIModule()
 {
     iTunes = new iTunesLib.iTunesApp();
     bot = new SpeechSynthesizer();
     bot.SelectVoice("VW Paul");
     bot.Rate = 1;
     bot.Volume = 100;
 }
 public ComiTunesLibrary()
 {
     app = new iTunesApp();
     CanModify = true;
     MusicFolderPath = Environment.GetFolderPath(Environment.SpecialFolder.MyMusic);
     Playlists = GetPlaylists();
     //TODO: Assign Artists and Albums
 }
Beispiel #28
0
 /*public methods start here!!!*/
 public LibraryScanner(Logger logger)
 {
     if (logger == null)
         throw new ArgumentException("logger parameter is null.");
     _log = logger;
     //FIXME: Move
     _library = new iTunesApp();
 }
Beispiel #29
0
 void iTunesDisconnect()
 {
     // Disconnect from iTunes
     iTunesControl = null;
     GC.Collect();
     // Update icon
     updateNotifyIcon();
 }
        public static string getartistname()
        {
            var    app    = new iTunesApp();
            string artist = app.CurrentTrack.Artist;

            app = null;
            return(artist);
        }
        public static string getsongname()
        {
            var    app   = new iTunesApp();
            string track = app.CurrentTrack.Name;

            app = null;
            return(track);
        }
Beispiel #32
0
        //public event EventHandler<CurrentTrackChangedEventArgs> CurrentTrackChanged;
        //public event EventHandler PlayerPlay;
        //public event EventHandler PlayerStop;
        //public event EventHandler SoundVolumeChanged;

        public iTunes()
        {
            _app = new iTunesApp();
            //_currentTrack = new Track(_app.CurrentTrack);
            //_app.OnPlayerPlayEvent += app_OnPlayerPlayEvent;
            //_app.OnPlayerStopEvent += app_OnPlayerStopEvent;
            //_app.OnSoundVolumeChangedEvent += app_OnSoundVolumeChangedEvent;
        }
Beispiel #33
0
        public void Start()
        {
            app = new iTunesApp();

            app.OnPlayerPlayingTrackChangedEvent += new _IiTunesEvents_OnPlayerPlayingTrackChangedEventEventHandler(app_OnPlayerPlayingTrackChangedEvent);
            app.OnPlayerPlayEvent += new _IiTunesEvents_OnPlayerPlayEventEventHandler(app_OnPlayerPlayEvent);
            app.OnPlayerStopEvent += new _IiTunesEvents_OnPlayerStopEventEventHandler(app_OnPlayerStopEvent);
        }
Beispiel #34
0
        //iTunes COM SDKを解放
        void ReleaseCOM()
        {
            iTunes.OnPlayerPlayEvent -= iTunes_OnPlayerPlayEvent;
            iTunes.OnAboutToPromptUserToQuitEvent -= iTunes_OnAboutToPromptUserToQuitEvent;

            Marshal.ReleaseComObject(iTunes);
            iTunes = null;
        }
Beispiel #35
0
 //初期化
 private void initiTunes()
 {
     itunes = new iTunesApp();
     itunes.OnAboutToPromptUserToQuitEvent +=
         new _IiTunesEvents_OnAboutToPromptUserToQuitEventEventHandler(itunes_OnAboutToPromptUserToQuitEvent);
     itunes.OnPlayerPlayEvent +=
         new _IiTunesEvents_OnPlayerPlayEventEventHandler(itunes_OnPlayerPlayEvent);
 }
Beispiel #36
0
        private void button1_Click(object sender, EventArgs e)
        {
            Dictionary<string, IITFileOrCDTrack> maps = new Dictionary<string,IITFileOrCDTrack>();

            string m3uLoc;
            openFileDialog1.Filter = "M3U Playlists|*.m3u";
            openFileDialog1.CheckFileExists = true;
            if (openFileDialog1.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                m3uLoc = openFileDialog1.FileName;
            }
            else
            {
                MessageBox.Show("Please select a file!");
                return;
            }

            iTunesApp iT = new iTunesApp();
            IITTrackCollection tCol = iT.LibraryPlaylist.Tracks;
            prog.Maximum = tCol.Count;
            for(int i = 1; i <= tCol.Count; i++) {
                IITTrack t = iT.LibraryPlaylist.Tracks[i];
                if (t.Kind == ITTrackKind.ITTrackKindFile)
                {
                    IITFileOrCDTrack ft = (IITFileOrCDTrack)t;
                    string location = ft.Location;
                    if(location == null || location == "" ){
                        notFoundiTunes(ft);
                    } else {
                        location = location.ToLower();
                        maps[location] = ft;
                    }

                }
                prog.Value = i;
                prog.Refresh();
            }

            // and now iterate through them and print them
            string[] lines = System.IO.File.ReadAllLines(m3uLoc);
            prog.Maximum = lines.Length;
            prog.Value = 0;
            StringBuilder sb = new StringBuilder();
            foreach (string l in lines)
            {
                string line = l.ToLower();
                if(maps.ContainsKey(line)) {
                    sb.AppendLine(getOutput(maps[line]));
                } else {
                    sb.AppendLine(getDefOutput());
                    notFoundM3U(line);
                }
                prog.Value += 1;
            }

            txtOut.Text = sb.ToString();
        }
 private void connect()
 {
     lock (lockObject)
     {
         this.iTunesApp = new iTunesApp();
         this.iTunesApp.OnQuittingEvent += new _IiTunesEvents_OnQuittingEventEventHandler(iTunesApp_OnQuittingEvent);
     }
     this.IsConnected = true;
 }
Beispiel #38
0
 public void Initialize()
 {
     app = new iTunesAppClass(){AppCommandMessageProcessingEnabled = true};
     _checkTimer = new Timer();
     _isLaunched = true;
     _checkTimer.Interval = 2000.0;
     _checkTimer.Elapsed += CheckTimerOnElapsed;
     _checkTimer.Enabled = true;
 }
Beispiel #39
0
        private void Form1_Load(object sender, EventArgs e)
        {
            iTunes = new iTunesApp();

            // add mouse event handler to capture wheel up/down events
            this.MouseWheel += new MouseEventHandler(this.Form1_MouseWheel);

            notifyIcon1.ShowBalloonTip(30);
        }
Beispiel #40
0
 private static void AddMissingTracks(iTunesApp app, IEnumerable<IITFileOrCDTrack> allTracks)
 {
     var tracksByLocation = allTracks.ToDictionary(track => track.Location);
     AddMissingTracks(app, tracksByLocation, SinglesLocation);
     foreach (var dir in Directory.GetDirectories(AlbumsLocation))
     {
         AddMissingTracks(app, tracksByLocation, dir);
     }
 }
Beispiel #41
0
 public Library(UpdateProgressDelegate progressUpdateDelegate, iTunesApp app)
 {
     trackList      = new Dictionary <string, Song>();
     bumperList     = new Dictionary <string, Song>();
     signoffList    = new Dictionary <string, Song>();
     itunesApp      = app;
     updateProgress = progressUpdateDelegate;
     this.CrawlFiles();
 }
Beispiel #42
0
        /// <summary>
        /// Determines, if the playlist with the specified name exists.
        /// </summary>
        /// <param name="playlistName">Th name of the playlist.</param>
        /// <returns>True, if the playlist exists; otherwise, false.</returns>
        private static bool PlaylistExists(string playlistName)
        {
            var playlist = new iTunesApp()
                           .LibrarySource
                           .Playlists
                           .ItemByName[playlistName];

            return(playlist != null);
        }
 private void connect()
 {
     lock (lockObject)
     {
         this.iTunesApp = new iTunesApp();
         this.iTunesApp.OnQuittingEvent += new _IiTunesEvents_OnQuittingEventEventHandler(iTunesApp_OnQuittingEvent);
     }
     this.IsConnected = true;
 }
 public SelectSongForm(iTunesApp player)
 {
     if (player == null) return;
     _player = player;
     InitializeComponent();
     Icon = new Icon(GetType(), "Main.ico");
     playButton.Tag = false;
     shuffleButton.Tag = true;
 }
        private static void FindDeadTracks(bool delete)
        {
            Console.WriteLine("Connecting to iTunes");
            iTunesApp itunes = new iTunesApp();
            int trackCount = itunes.LibraryPlaylist.Tracks.Count;

            Console.WriteLine("Inspecting {0} tracks", trackCount);
            IITFileOrCDTrack fileOrCdTrack;
            int currentTrackIndex = 0;
            int numberOfDeadTracksFound = 0;
            foreach (IITTrack track in itunes.LibraryPlaylist.Tracks)
            {
                // Show progress
                if (currentTrackIndex % 500 == 0)
                {
                    Console.WriteLine(
                        "[{0:000}%] Inspected {1} tracks so far",
                        currentTrackIndex * 100 / trackCount,
                        currentTrackIndex);
                }

                currentTrackIndex++;

                // Filter out everything which is not a file track
                fileOrCdTrack = track as IITFileOrCDTrack;
                if (fileOrCdTrack == null || fileOrCdTrack.Kind != ITTrackKind.ITTrackKindFile)
                {
                    continue;
                }

                // Filter out tracks with known file location
                if (fileOrCdTrack.Location != null)
                {
                    continue;
                }

                // If we are here, the track has missing file
                numberOfDeadTracksFound++;
                Console.WriteLine(
                    "[{0:000}%] {1} dead track: {2} - {3}",
                    currentTrackIndex * 100 / trackCount,
                    delete ? "Removing" : "Found",
                    fileOrCdTrack.Artist,
                    fileOrCdTrack.Name);
                if (delete)
                {
                    fileOrCdTrack.Delete();
                }
            }

            Console.WriteLine("[{0:000}%] Inspected {1} tracks", 100, trackCount);
            Console.WriteLine(
                "{0} {1} tracks where it's file doesn't exist",
                delete ? "Removed" : "Found",
                numberOfDeadTracksFound);
        }
Beispiel #46
0
        public Form1()
        {

            InitializeComponent();
            //iTunes COMのセットアップ
            iTunes = new iTunesApp();
            iTunes.OnAboutToPromptUserToQuitEvent += new _IiTunesEvents_OnAboutToPromptUserToQuitEventEventHandler(iTunes_OnAboutToPromptUserToQuitEvent);
            iTunes.OnPlayerPlayEvent += new _IiTunesEvents_OnPlayerPlayEventEventHandler(iTunes_OnPlayerPlayEvent);

        }
Beispiel #47
0
        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        static void Main()
        {
            AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler( UnhandledException );
            iTunesApp application = new iTunesApp();

            if( application.PlayerState == ITPlayerState.ITPlayerStateStopped )
                application.Play();
            else
                application.Pause();
        }
        public CommentSettingWindow()
        {
            InitializeComponent();

            var itunes = new iTunesApp();

            var o = itunes.LibraryPlaylist.Tracks.Cast<IITTrack>().GroupBy(x => x.Album).ToArray();

            List<ViewModel> ret = new List<ViewModel>();

            foreach (var a in o)
            {
                var minAritistsLength = a.ToArray().Select(x => x.Artist.Length).Min();

                string artist = a.ToArray().Where(x => x.Artist.Length == minAritistsLength).First().Artist;

                var model = new ViewModel();
                model.IsInitailizing = true;
                model.AlbumName = a.Key;

                if (a.ToArray().Where(x => string.IsNullOrWhiteSpace(x.Comment) == true).Any() == false)
                {
                    if (a.ToArray().Select(x => x.Comment.Split('@').First()).Distinct().Count() == 1)
                    {
                        model.ArtistName = a.ToArray().Select(x => x.Comment.Split('@').First()).Distinct().First();
                    }

                    if (string.IsNullOrWhiteSpace(model.ArtistName) == false)
                    {
                        if (a.ToArray().Select(x => x.Comment.Split('@').ElementAtOrDefault(1)).Distinct().Count() == 1)
                        {
                            model.ReleaseYear = a.ToArray().Select(x => x.Comment.Split('@').ElementAtOrDefault(1)).Distinct().First();
                        }
                    }

                    if (string.IsNullOrWhiteSpace(model.ReleaseYear) == false)
                    {
                        if (a.ToArray().Select(x => x.Comment.Split('@').ElementAtOrDefault(2)).Distinct().Count() == 1)
                        {
                            model.ReleaseOrder = a.ToArray().Select(x => x.Comment.Split('@').ElementAtOrDefault(2)).Distinct().First();
                        }
                    }
                }

                if (string.IsNullOrWhiteSpace(model.ArtistName) == true)
                {
                    model.ArtistName = artist;
                }
                model.IsInitailizing = false;

                ret.Add(model);
            }

            this.dataGrid.ItemsSource = ret.ToArray();
        }
        public byte[] GetAlbumArtByAlbum(Album album)
        {
            byte[] imageData = null;
            Track foundTrack = null;
            iTunesApp iTunes = null;

            try
            {
                iTunes = new iTunesApp();

                foreach (IITFileOrCDTrack track in iTunes.LibraryPlaylist.Search(album.Title,
                    ITPlaylistSearchField.ITPlaylistSearchFieldAlbums))
                {
                    if (!string.Equals(track.Artist, album.ArtistName))
                    {
                        continue;
                    }

                    foundTrack = track.GetTrack();
                    break;
                }

                if (foundTrack != null && File.Exists(foundTrack.FilePath))
                {
                    using (FileStream fileStream = new FileStream(foundTrack.FilePath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
                    {
                        try
                        {
                            TagContainer tags = new Id3TagManager().ReadV2Tag(fileStream);
                            if (tags != null)
                            {
                                IFrame apicFrame = tags.SearchFrame("APIC");
                                if (apicFrame != null)
                                {
                                    PictureFrame pictureFrame = FrameUtilities.ConvertToPictureFrame(apicFrame);
                                    imageData = pictureFrame.PictureData.ToArray<byte>();
                                }
                            }
                        }
                        catch (Id3TagException) { /* Do nothing */}
                    }
                }

                return imageData;
            }
            catch (Exception ex)
            {
                LogUtility.LogException(ex);
                throw;
            }
            finally
            {
                // Marshall.ReleaseComObject?
            }
        }
Beispiel #50
0
        public override void Load()
        {
            // invoke relies on the form..........................

            this.iTunesApplication = new iTunesApp();

            this.iTunesApplication.OnPlayerPlayEvent += new _IiTunesEvents_OnPlayerPlayEventEventHandler(this.App_OnPlayerPlayEvent);
            this.iTunesApplication.OnPlayerPlayingTrackChangedEvent += new _IiTunesEvents_OnPlayerPlayingTrackChangedEventEventHandler(this.App_OnPlayerPlayingTrackChangedEvent);
            this.iTunesApplication.OnPlayerStopEvent += new _IiTunesEvents_OnPlayerStopEventEventHandler(this.App_OnPlayerStopEvent);
            this.iTunesApplication.OnQuittingEvent += new _IiTunesEvents_OnQuittingEventEventHandler(this.App_OnPlayerQuittingEvent);
        }
 public ITunesController(AIModule aim)
 {
     try
     {
         this.iTunes = new iTunesLib.iTunesApp();
         this.aim = aim;
     }
     catch (Exception)
     {
         throw new Exception("Problem loading iTunes.");
     }
 }
        private void sortButton_Click(object sender, RoutedEventArgs e)
        {
            Task.Factory.StartNew(() =>
            {
                try
                {
                    this.Dispatch(() =>
                    {
                        this.IsEnabled = false;
                    });

                    var iTunes = new iTunesApp();

                    var playlists =
                        this.playlistSortListView.Items
                        .Cast<UserPlaylistViewModel>()
                        .Where(x => x.IsChecked == true);

                    playlists.AsParallel().ForAll(playlist =>
                    {
                        var created = iTunes.CreatePlaylist(playlist.Name) as IITUserPlaylist;

                        var source = playlist.Model;

                        created.Shuffle = source.Shuffle;
                        created.SongRepeat = source.SongRepeat;

                        created.AddRangeTracks(
                            source.Tracks
                            .Cast<IITTrack>()
                            .OrderBy("Comment", "DiscNumber", "TrackNumber")
                            .ToArray());

                        source.Delete();

                        playlist.Model = created;
                        playlist.IsChecked = false;
                    });

                    this.Dispatch(() =>
                    {
                        MessageBox.Show(this, "completed");
                    });
                }
                finally
                {
                    this.Dispatch(() =>
                    {
                        this.IsEnabled = true;
                    });
                }
            });
        }
 public bool Disconnect()
 {
     lock (lockObject)
     {
         if (iTunesApp != null)
         {
             System.Runtime.InteropServices.Marshal.ReleaseComObject(iTunesApp);
             iTunesApp = null;
             GC.Collect();
         }
     }
     return true;
 }
Beispiel #54
0
        public override void Unload()
        {
            base.Unload();

            if (this.iTunesApplication != null)
            {
                this.iTunesApplication.OnPlayerPlayEvent -= this.App_OnPlayerPlayEvent;
                this.iTunesApplication.OnPlayerPlayingTrackChangedEvent -= this.App_OnPlayerPlayingTrackChangedEvent;
                this.iTunesApplication.OnPlayerStopEvent -= this.App_OnPlayerStopEvent;
                this.iTunesApplication.OnQuittingEvent -= this.App_OnPlayerQuittingEvent;

                this.iTunesApplication = null;
            }
        }
Beispiel #55
0
        static void Main(string[] args)
        {
            iTunesApp iTunesInstance = new iTunesApp();

            if (args.Length == 0)
            {
                return;
            }

            switch(args[0].ToLower())
            {
                case "next":
                    iTunesInstance.NextTrack();

                    break;

                case "prev":
                    iTunesInstance.PreviousTrack();

                    break;

                case "play":
                    iTunesInstance.Play();

                    break;

                case "pause":
                    iTunesInstance.Pause();

                    break;

                case "current_track_artist":
                    Console.WriteLine(iTunesInstance.CurrentTrack.Artist);

                    break;

                case "current_track_name":
                    Console.WriteLine(iTunesInstance.CurrentTrack.Name);

                    break;

                case "state":
                    Console.WriteLine(iTunesInstance.PlayerState.ToString());

                    break;

                default:
                    break;
            }
        }
Beispiel #56
0
 public PlaylistBuilder(MediaInfoKeeper p_keeper, IMonitorThreadInterface p_monitor)
 {
     try
     {
         iTunes = p_monitor.PlayerObject as iTunesApp;
         monitor = p_monitor;
         keeper = p_keeper;
     }
     catch (Exception e)
     {
         Log.Write(e);
         throw e;
     }
 }
Beispiel #57
0
        public Logic()
        {
            armed = true;

            resetTimer = new Timer();
            itunes = new iTunesApp();
            speaker = new SpeechSynthesizer();

            resetTimer.Interval = TimeSpan.FromMinutes(30).TotalMilliseconds;
            resetTimer.Elapsed += (o, e) =>
                                      {
                                          armed = true;
                                          resetTimer.Stop();
                                      };
        }
Beispiel #58
0
        public void iTunesConnect()
        {
            // Connect to iTunes
              try
              {
            iTunesControl = new iTunesAppClass();
              }
              catch (COMException ex)
              {
            iTunesError(ex, "Could not connect to iTunes.");
              }

              // Set up iTunes
              updateNotifyIcon();
        }
Beispiel #59
0
 private static void AddMissingTracks(iTunesApp app, IDictionary<string, IITFileOrCDTrack> tracksByLocation, string dir)
 {
     foreach (var file in Directory.GetFiles(dir))
     {
         if (!MusicFileExtensions.Contains(Path.GetExtension(file.ToLower())))
         {
             continue;
         }
         if (!tracksByLocation.ContainsKey(file))
         {
             Console.WriteLine("Adding track: " + file);
             app.LibraryPlaylist.AddFile(file);
         }
     }
 }
Beispiel #60
0
        public override void Load()
        {
            try
            {
                this.iTunesApplication = new iTunesApp();

                this.iTunesApplication.OnPlayerPlayEvent += new _IiTunesEvents_OnPlayerPlayEventEventHandler(this.App_OnPlayerPlayEvent);
                this.iTunesApplication.OnPlayerPlayingTrackChangedEvent += new _IiTunesEvents_OnPlayerPlayingTrackChangedEventEventHandler(this.App_OnPlayerPlayingTrackChangedEvent);
                this.iTunesApplication.OnPlayerStopEvent += new _IiTunesEvents_OnPlayerStopEventEventHandler(this.App_OnPlayerStopEvent);
                this.iTunesApplication.OnQuittingEvent += new _IiTunesEvents_OnQuittingEventEventHandler(this.App_OnPlayerQuittingEvent);
            }
            catch (System.Runtime.InteropServices.COMException comException)
            {
                MessageBox.Show(Globals.ResourceManager.GetString("iTunesException") + "\n\n" + comException.Message, Globals.ResourceManager.GetString("SnipForm"), MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }