Esempio n. 1
0
        static String updateTrack(IITFileOrCDTrack track)
        {
            if (!File.Exists(track.Location)) {
                String result = "Deleted (" + track.Artist + ", " + track.Album + ", " + track.Name + ")";
                track.Delete();
                return result;
            }

            if (CHECK_TIMESTAMP) {
                DateTime fileStamp = File.GetLastWriteTime(track.Location);
                DateTime dbStamp = track.ModificationDate;

                // iTunes appears to get confused about daylight savings
                if (fileStamp.IsDaylightSavingTime()) {
                    dbStamp = dbStamp.AddHours(1);
                }

                if (dbStamp >= fileStamp) {
                    return null;
                }
            }

            track.UpdateInfoFromFile();
            return "UpdateInfo for " + track.Location;
        }
Esempio n. 2
0
 public static void UpdateProperty(IITFileOrCDTrack track, Dictionary<string, string> propertiesFromMetaData, Dictionary<string, string> propertiesFromRegex)
 {
     // Look at the metadata stored in the file first
     foreach (var entry in propertiesFromMetaData)
     {
         if (!string.IsNullOrEmpty(entry.Value))
         {
             int intV;
             string stringV;
             switch (entry.Key)
             {
                 case "Album":
                     track.Album = GetValueFromDictionary(entry.Value, propertiesFromRegex, "Album");
                     break;
                 case "Album/Performer":
                     track.AlbumArtist = GetValueFromDictionary(entry.Value, propertiesFromRegex, "Album/Performer");
                     break;
                 case "Performer":
                     track.Artist = GetValueFromDictionary(entry.Value, propertiesFromRegex, "Performer");
                     break;
                 case "Genre":
                     track.Genre = GetValueFromDictionary(entry.Value, propertiesFromRegex, "Genre");
                     break;
                 case "Track name/Position":
                     stringV = GetValueFromDictionary(entry.Value, propertiesFromRegex, "Track name/Position");
                     if (int.TryParse(stringV, out intV))
                         track.TrackNumber = int.Parse(stringV);
                     break;
                 case "Track name":
                     track.Name = GetValueFromDictionary(entry.Value, propertiesFromRegex, "Track name");
                     break;
                 case "Composer":
                     track.Composer = GetValueFromDictionary(entry.Value, propertiesFromRegex, "Composer");
                     break;
                 case "Grouping":
                     track.Grouping = GetValueFromDictionary(entry.Value, propertiesFromRegex, "Grouping");
                     break;
                 case "Recorded date":
                     stringV = GetValueFromDictionary(entry.Value, propertiesFromRegex, "Recorded date");
                     if (stringV != "")
                     {
                         if (stringV.Trim().Length >= 4)
                         {
                             var releaseDt = stringV.Trim().Substring(0, 4);
                             if (int.TryParse(releaseDt, out intV))
                                 track.Year = intV;
                         }
                     }
                     break;
             }
         }
     }
     if (string.IsNullOrEmpty(track.Artist))
         track.Artist = "Uknown Artist";
     if (string.IsNullOrEmpty(track.Album))
         track.Album = "Uknown Album";
     if (string.IsNullOrEmpty(track.Genre))
         track.Genre = "Uknown Genre";
 }
Esempio n. 3
0
 static void CPLFor(ref IITFileOrCDTrack TrackFile)
 {
     if (!Directory.Exists(DirLocation + "\\" + TrackFile.Album))
         Directory.CreateDirectory(DirLocation + "\\" + TrackFile.Album);
     string Extension = TrackFile.Location.Substring(TrackFile.Location.LastIndexOf(".") + 1);
     string Location = DirLocation + "\\" + TrackFile.Album + "\\" + TrackFile.TrackNumber.ToString() + " - " + TrackFile.Artist + " - " + TrackFile.Name + "." + Extension;
     File.Copy(TrackFile.Location, Location,OverWrite);
 }
Esempio n. 4
0
		private static string TranslateArtistInitial(SyncPattern pattern, IITFileOrCDTrack track, string patternstring)
		{
			string artist = (track.Artist == null ? "Unknown Artist" : track.Artist);            
            if (track.Compilation && pattern.CompilationsPattern != null && pattern.CompilationsPattern.Length > 0)
                artist = "Compilations";

            patternstring = patternstring.Replace("%ARTISTINITIAL%", artist.Substring(0,1).ToUpper());
            return patternstring;
		}
Esempio n. 5
0
 private void AddTrackToList(IITFileOrCDTrack fileTrack)
 {
     if (listView1.InvokeRequired)
     {
         var cb = new AddTrackToListCallback(AddTrackToList);
         Invoke(cb, new object[] { fileTrack });
     }
     else
         listView1.Items.Add(new ListViewItem(new string[] { fileTrack.Name, fileTrack.Artist, fileTrack.Location, fileTrack.BitRate.ToString() }));
 }
Esempio n. 6
0
        private SearchResult FetchLyrics(IITFileOrCDTrack currentTrack, string artist, string song, int index) {

            if (_lyricService.Exists(artist, song) == SearchResult.NotFound)
                return SearchResult.NotFound;

            string lyrics;
            var result = _lyricService.GetLyrics(artist, song, out lyrics);

            if (result == SearchResult.Found) {
                currentTrack.Lyrics = lyrics;
            }

            return result;
        }
Esempio n. 7
0
        /// <summary>
        /// Translate a SyncPattern into a string using the provided IITFileOrCDTrack.
        /// Currently translating the following macros:
        /// %ARTIST%        = The artist name
        /// %ALBUMARTIST%   = The album artist name
        /// %ALBUM%         = The album name
        /// %ALBUMINITIAL% 	= The album initial
        /// %NAME%          = The track name
        /// %TRACKNUMINPLAYLIST% = Play order index from playlist with leading zero
        /// %TRACKNUMSPACE% = The track number with a trailing space
        /// %TRACKNUM%      = The track number (no trailing space)
        /// %DISCNUMDASH%   = The disc number with a trailing minus and space
        /// %DISCNUM%       = The disc number (no trailing space)
        /// </summary>
        /// <param name="pattern">SyncPattern to translate.</param>
        /// <param name="track">iTunes track containing track information.</param>
        /// <returns>A string representation of pattern and track.</returns>
        public static string Translate(SyncPattern pattern, IITFileOrCDTrack track)
        {
            try
            {
                if (track == null)
                    l.Debug("Track is null!");

                if (track.Location == null)
                {
                    l.Debug("track.Location is null!");
                    throw new MissingTrackException(track);
                }

                string patternstring = ((track.Compilation && pattern.CompilationsPattern != null && pattern.CompilationsPattern.Length > 0) ? pattern.CompilationsPattern : pattern.Pattern);

                patternstring = TranslateArtist(pattern, track, patternstring);
                patternstring = TranslateArtistInitial(pattern, track, patternstring);
                patternstring = TranslateTrackNumberInPlaylist(track, patternstring);
                patternstring = TranslateAlbumArtist(pattern, track, patternstring);
                patternstring = TranslateDiscNumber(track, patternstring);
                patternstring = TranslateAlbum(track.Album, patternstring);
                patternstring = TranslateName(track, patternstring);
                patternstring = TranslateTrackNumber(track, patternstring);
                patternstring = TranslateExtension(track, patternstring);

                l.Debug("patternstring=" + patternstring);

                return FileNameUtils.ConvertIllegalCharacters(patternstring);
            }
            catch (MissingTrackException ex)
            {
                throw ex;
            }
            catch (Exception ex)
            {
                string message = "Failed to translate track information according to the "
                    + "defined pattern for this device (" + ex.Message + ").";

                l.Error(message, ex);
                throw new ArgumentException(message, ex);
            }            
            
        }
Esempio n. 8
0
        /// <summary>
        /// Creates a new SongMetadata from the track information
        /// </summary>
        /// <param name="song">The iTunes track information</param>
        /// <returns>New Song</returns>
        private static SongMetadata SongMetadataFactory(IITFileOrCDTrack song)
        {
            var ret = new SongMetadata
            {
                AlbumArtist           = song.AlbumArtist,
                AlbumName             = song.Album,
                ArtistName            = song.Artist,
                BitRate               = song.BitRate == 0 ? (int?)null : song.BitRate,
                BPM                   = song.BPM == 0 ? (int?)null : song.BPM,
                Comments              = song.Comment,
                IsCompilation         = song.Compilation,
                Composer              = song.Composer,
                DateAdded             = song.DateAdded,
                DiscCount             = song.DiscCount == 0 ? (int?)null : song.DiscCount,
                DiscNumber            = song.DiscNumber == 0 ? (int?)null : song.DiscCount,
                Duration              = song.Duration <= 0 ? (TimeSpan?)null : TimeSpan.FromSeconds(song.Duration),
                IsEnabled             = song.Enabled,
                IsExcludedFromShuffle = song.ExcludeFromShuffle,
                Genre                 = song.Genre,
                Grouping              = song.Grouping,
                LibraryIndex          = song.Index < 0 ? (int?)null : song.Index,
                Kind                  = song.KindAsString,
                FileLocation          = song.Location,
                Modified              = song.ModificationDate,
                TrackName             = song.Name,
                PlayCount             = song.PlayedCount,
                LastPlayed            = song.PlayedDate,
                Rating                = song.Rating <= 0 ? (int?)null : song.Rating,
                SampleRate            = song.SampleRate <= 0 ? (int?)null : song.SampleRate,
                TrackCount            = song.TrackCount <= 0 ? (int?)null : song.TrackCount,
                TrackNumber           = song.TrackNumber <= 0 ? (int?)null : song.TrackNumber,
                Year                  = song.Year <= 0 ? (int?)null : song.Year
            };

            ret.ClearChanges();
            return(ret);
        }
Esempio n. 9
0
        /// <summary>
        /// Translate track number.
        /// </summary>
        /// <param name="track"></param>
        /// <param name="patternstring"></param>
        /// <returns></returns>
        private static string TranslateTrackNumber(IITFileOrCDTrack track, string patternstring)
        {
            //Replace track number with a number only if the iTunes track has this field set
            if (track.TrackNumber != 0)
            {
                //%TRACKNUMSPACE%
                patternstring = patternstring.Replace("%TRACKNUMSPACE%",
                                                      (track.TrackNumber.ToString().Length == 1 ?
                                                       "0" + track.TrackNumber.ToString() : track.TrackNumber.ToString()) + " ");

                //%TRACKNUM%
                patternstring = patternstring.Replace("%TRACKNUM%",
                                                      (track.TrackNumber.ToString().Length == 1 ?
                                                       "0" + track.TrackNumber.ToString() : track.TrackNumber.ToString()));
            }
            else //If there are no track number set for the track
            {
                //%TRACKNUMSPACE%
                patternstring = patternstring.Replace("%TRACKNUMSPACE%", "");
                //%TRACKNUM%
                patternstring = patternstring.Replace("%TRACKNUM%", "");
            }
            return(patternstring);
        }
Esempio n. 10
0
        public static byte[] GetAlbumArtwork(IITFileOrCDTrack track)
        {
            if (track == null || track.Artwork == null || track.Artwork.Count <= 0)
            {
                return(null);
            }

            string fileName = Path.Combine(Path.GetTempPath(), track.Name + ".image");

            try
            {
                foreach (IITArtwork image in track.Artwork)
                {
                    image.SaveArtworkToFile(fileName);
                    byte[] imageContents = File.ReadAllBytes(fileName);
                    return(imageContents);
                }
                return(null);
            }
            finally
            {
                File.Delete(fileName);
            }
        }
Esempio n. 11
0
 private void SetTrackArt(IITFileOrCDTrack track)
 {
     if (track.Artwork.Count == 0 && !track.Podcast)
     {
         string fileLoc = System.IO.Path.GetDirectoryName(track.Location);
         string artPath = System.IO.Path.Combine(fileLoc, "folder.jpg");
         if (System.IO.File.Exists(artPath))
         {
             _log.LogInfo("Adding art to " + track.Location);
             try
             {
                 track.AddArtworkFromFile(artPath);
             }
             catch
             {
                 _log.LogError("Couldn't set albumart...");
             }
         }
     }
 }
 static int MusicBeeAlbumRating(this IITFileOrCDTrack track)
 {
     return(track.AlbumRating / 20);
 }
Esempio n. 13
0
        private void RemoveDuplicates()
        {
            //create a reference to iTunes
            iTunesAppClass iTunes = new iTunesAppClass();

            //get a reference to the collection of all tracks
            IITTrackCollection tracks = iTunes.LibraryPlaylist.Tracks;

            int trackCount           = tracks.Count;
            int numberChecked        = 0;
            int numberDuplicateFound = 0;
            Dictionary <string, IITTrack> trackCollection = new Dictionary <string, IITTrack>();
            ArrayList tracksToRemove = new ArrayList();

            //setup the progress control
            this.SetupProgress(trackCount);

            for (int i = trackCount; i > 0; i--)
            {
                if (tracks[i].Kind == ITTrackKind.ITTrackKindFile)
                {
                    if (!this._shouldStop)
                    {
                        numberChecked++;
                        this.IncrementProgress();
                        this.UpdateLabel("Checking track # " + numberChecked.ToString() + " - " + tracks[i].Name);
                        string trackKey = tracks[i].Name + tracks[i].Artist + tracks[i].Album;

                        if (!trackCollection.ContainsKey(trackKey))
                        {
                            trackCollection.Add(trackKey, tracks[i]);
                        }
                        else
                        {
                            if (trackCollection[trackKey].Album != tracks[i].Album || trackCollection[trackKey].Artist != tracks[i].Artist)
                            {
                                trackCollection.Add(trackKey, tracks[i]);
                            }
                            else if (trackCollection[trackKey].BitRate > tracks[i].BitRate)
                            {
                                IITFileOrCDTrack fileTrack = (IITFileOrCDTrack)tracks[i];
                                numberDuplicateFound++;
                                tracksToRemove.Add(tracks[i]);
                            }
                            else
                            {
                                IITFileOrCDTrack fileTrack = (IITFileOrCDTrack)tracks[i];
                                trackCollection[trackKey] = fileTrack;
                                numberDuplicateFound++;
                                tracksToRemove.Add(tracks[i]);
                            }
                        }
                    }
                }
            }

            this.SetupProgress(tracksToRemove.Count);

            for (int i = 0; i < tracksToRemove.Count; i++)
            {
                IITFileOrCDTrack track = (IITFileOrCDTrack)tracksToRemove[i];
                this.UpdateLabel("Removing " + track.Name);
                this.IncrementProgress();
                this.AddTrackToList((IITFileOrCDTrack)tracksToRemove[i]);

                if (this.checkBoxRemove.Checked)
                {
                    track.Delete();
                }
            }

            this.UpdateLabel("Checked " + numberChecked.ToString() + " tracks and " + numberDuplicateFound.ToString() + " duplicate tracks found.");
            this.SetupProgress(1);
        }
Esempio n. 14
0
 public iTunesFile()
 {
     _file = null;
 }
Esempio n. 15
0
 /// <summary>
 /// Translate track playorder index from playlist.
 /// </summary>
 /// <param name="track"></param>
 /// <param name="patternstring"></param>
 /// <returns></returns>
 private static string TranslateTrackNumberInPlaylist(IITFileOrCDTrack track, string patternstring)
 {
     //%TRACKNUMINPLAYLIST%
     patternstring = patternstring.Replace("%TRACKNUMINPLAYLIST%",
         (track.PlayOrderIndex.ToString().Length == 1 ? "00" + track.PlayOrderIndex.ToString()
             : track.PlayOrderIndex.ToString().Length == 2 ? "0" + track.PlayOrderIndex.ToString()
             : track.PlayOrderIndex.ToString())
     );
     return patternstring;
 }
Esempio n. 16
0
        /// <summary>
        /// Synchronize the player with iTunes.
        /// </summary>
        public void Synchronize()
        {
            IEnumerator e = devices.Keys.GetEnumerator();

            while (e.MoveNext())
            {
                //Get drive letter
                string driveletter = ((string)e.Current).Substring(0, 1);

                Device device  = (Device)devices[e.Current];
                string usepath = GetWorkingPath(driveletter, device.Folderpattern);

                //check that we have a path to use, report error if not
                if (usepath == null)
                {
                    OnSynchronizeError("Could not locate the correct folder on the device.", device);
                }
                else
                {
                    foreach (IITSource source in itunes.Sources)
                    {
                        foreach (IITPlaylist playlist in source.Playlists)
                        {
                            if (playlist.Name != device.Name)
                            {
                                continue;
                            }

                            foreach (IITTrack track in playlist.Tracks)
                            {
                                //Check that the track is a file. iTA currently only supports synchronization of files.
                                if (track.Kind != ITTrackKind.ITTrackKindFile)
                                {
                                    OnSynchronizeError("The track '" + track.Artist + " - " + track.Name
                                                       + " can not be copied. iTunes Agent currently only supports synchronization "
                                                       + "of music files, not CD-tracks or other types of media.", device);
                                    continue;
                                }

                                IITFileOrCDTrack fileTrack      = (IITFileOrCDTrack)track;
                                string           playerFileName = GetPlayerLocation(fileTrack);

                                string priority = configuration.GetValue("SyncModule/Priority");
                                //Priority == itunes means that only the files in the playlist in iTunes will be available on
                                //the device. All other music files in the media folder for the device will be removed!
                                if (priority == "itunes")
                                {
                                    DirectoryInfo di    = new DirectoryInfo(usepath);
                                    FileInfo[]    files = di.GetFiles("*", SearchOption.AllDirectories);
                                }
                                else
                                {
                                    string fullPathOnDevice = usepath + "\\" + playerFileName;
                                    if (File.Exists(fullPathOnDevice))
                                    {
                                        continue;
                                    }

                                    try
                                    {
                                        ConstructDirectories(usepath, playerFileName);
                                        File.Copy(fileTrack.Location, fullPathOnDevice);
                                    }
                                    catch (Exception ex)
                                    {
                                        OnSynchronizeError("Failed to copy '" + fileTrack.Artist + " - " + fileTrack.Name
                                                           + "' (" + ex.Message + ").", device);
                                    }
                                }
                            }
                        }
                    }
                }
            }

            OnSynchronizeComplete();
        }
Esempio n. 17
0
          /// <summary>
        /// Translate track album artist.
        /// </summary>
        /// <param name="pattern"></param>
        /// <param name="track"></param>
        /// <param name="patternstring"></param>
        /// <returns></returns>
        private static string TranslateAlbumArtist(SyncPattern pattern, IITFileOrCDTrack track, string patternstring)
        {
            string artist = (track.AlbumArtist == null ? "Unknown Artist" : track.AlbumArtist);            
            if (track.Compilation && pattern.CompilationsPattern != null && pattern.CompilationsPattern.Length > 0)
                artist = "Compilations";

            patternstring = patternstring.Replace("%ALBUMARTIST%", artist);
            return patternstring;
        }
Esempio n. 18
0
 static void AICFor(ref IITFileOrCDTrack TrackFile)
 {
     // TrackFile.Artwork = TrackFile.Artwork;
 }
Esempio n. 19
0
 public Track(IITFileOrCDTrack itunesTrack)
 {
     this.ITunesTrack = itunesTrack;
 }
 public iTunesPlayChangeEventArgs(ITunesSongChangeType changeType, IITFileOrCDTrack changedTrack)
 {
     ChangeType = changeType;
     ChangedTrack = changedTrack;
 }
Esempio n. 21
0
        private void timer1_Tick(object sender, EventArgs e)
        {
            IITTrack track = iTunes.CurrentTrack;

            if (track == null)
            {
                label1.Text   = "Disabled";
                textBox1.Text = "Disabled";
                return;
            }
            if (!track.Enabled)
            {
                label1.Text   = "Disabled";
                textBox1.Text = "Disabled";
                return;
            }

            string trackName   = track.Name;
            string trackArtist = track.Artist;
            string trackAlbum  = track.Album;

            label1.Text = trackName + " | " + trackArtist + " | " + trackAlbum;
            int duration = track.Duration;

            if (MusixMatchMode)
            {
                if (check == trackName + " | " + trackArtist + " | " + trackAlbum)
                {
                    return;
                }
                check = trackName + " | " + trackArtist + " | " + trackAlbum;
                Dictionary <string, string> dic = GetMusixMatchLyrics(trackName, trackArtist);
                if (dic != null && dic["instrumental"] == "1")
                {
                    textBox1.Text = "Instrumental";
                    return;
                }
                string lyrics = dic["lyrics"];
                string artist = dic["artist"];
                if (lyrics == null)
                {
                    dic = GetMusixMatchLyrics(trackName);
                    if (dic != null)
                    {
                        lyrics = dic["lyrics"];
                        artist = dic["artist"];
                    }
                }
                if (lyrics != null)
                {
                    textBox1.Text = lyrics;
                    label3.Text   = artist;
                }
                else
                {
                    if (dic != null && dic["instrumental"] == "1")
                    {
                        textBox1.Text = "Instrumental";
                    }
                    else
                    {
                        textBox1.Text = "見つかりませんでした。";
                        label3.Text   = "";
                    }
                }
            }
            else
            {
                IITFileOrCDTrack cdtrack = (IITFileOrCDTrack)track;
                textBox1.Text = cdtrack.Lyrics;
            }
        }
Esempio n. 22
0
        private void button3_Click(object sender, EventArgs e)
        {
            if (MusixMatchMode)
            {
                MusixMatchMode = false;
                button3.Text   = "MusixMatchMode";
                Console.WriteLine("button3_Click: " + "NOW iTunesLyricsMode");

                label3.Text = "iTunesLyricsMode";

                IITTrack track = iTunes.CurrentTrack;
                if (!track.Enabled)
                {
                    label1.Text   = "Disabled";
                    textBox1.Text = "";
                }

                string trackName   = track.Name;
                string trackArtist = track.Artist;
                string trackAlbum  = track.Album;

                IITFileOrCDTrack cdtrack = (IITFileOrCDTrack)track;
                textBox1.Text = cdtrack.Lyrics;
            }
            else
            {
                MusixMatchMode = true;
                button3.Text   = "iTunesLyricsMode";
                Console.WriteLine("button3_Click: " + "NOW MusixMatchMode");

                label3.Text = "MusixMatchMode";

                IITTrack track = iTunes.CurrentTrack;
                if (!track.Enabled)
                {
                    label1.Text   = "Disabled";
                    textBox1.Text = "";
                }

                string trackName   = track.Name;
                string trackArtist = track.Artist;
                string trackAlbum  = track.Album;

                Dictionary <string, string> dic = GetMusixMatchLyrics(trackName, trackArtist);
                if (dic != null && dic["instrumental"] == "1")
                {
                    textBox1.Text = "Instrumental";
                    return;
                }
                string lyrics = dic["lyrics"];
                string artist = dic["artist"];
                if (lyrics == null)
                {
                    dic = GetMusixMatchLyrics(trackName);
                    if (dic != null)
                    {
                        lyrics = dic["lyrics"];
                        artist = dic["artist"];
                    }
                }
                if (lyrics != null)
                {
                    textBox1.Text = lyrics;
                    label3.Text   = artist;
                }
                else
                {
                    if (dic != null && dic["instrumental"] == "1")
                    {
                        textBox1.Text = "Instrumental";
                    }
                    else
                    {
                        textBox1.Text = "見つかりませんでした。";
                    }
                }
            }
        }
Esempio n. 23
0
        public static void PerformCPD()
        {
            Console.Title = "Performing CPD (Copy Playlist to Directory)";
            WelcomeCPD();
            int KeySource = PickSource();

            WelcomeCPD();
            int KeyPlayList = PickPlaylist(KeySource);

            //=============================================================================
            //
            WelcomeCPD();
            if (!PickDirectory())
            {
                Console.WriteLine("\r\nOperation Cancelled, Press any key to continue.");
                Console.ReadKey(true);
                return;
            }
            //=============================================================================
            //
            WelcomeCPD();
            PickOverWrite();
            Console.WriteLine("Now Copying PlayList:");
            //try
            //{
            int tot = iTunes.Sources[KeySource].Playlists[KeyPlayList].Tracks.Count;

            for (int i = 1; i <= tot; i++)
            {
                IITTrack Track = ((IITTrack)iTunes.Sources[KeySource].Playlists[KeyPlayList].Tracks[i]);
                if (Track.Kind == ITTrackKind.ITTrackKindFile)
                {
                    IITFileOrCDTrack TrackFile = (IITFileOrCDTrack)Track;
                    if (TrackFile.Location != null || TrackFile.Location != "")
                    {
                        if (File.Exists(TrackFile.Location))
                        {
                            CPLFor(ref TrackFile);
                            Console.WriteLine("Copied [" + i.ToString() + "/" + tot.ToString() + "]");
                        }
                    }
                    else
                    {
                        Console.WriteLine("File Location FAILED");
                        Console.WriteLine("FAILED [" + i.ToString() + "/" + tot.ToString() + "]");
                    }
                }
                else
                {
                    Console.WriteLine("TrackKind FAILEd With: " + Track.Kind);
                    Console.WriteLine("FAILED [" + i.ToString() + "/" + tot.ToString() + "]");
                }
            }
            //}
            //catch( Exception e)
            //{
            //    MessageBox.Show("Something went wrong with copying the files!\r\n"+e.Message);
            //}
            //=============================================================================
            //
            Console.WriteLine("\r\nTask Finished, Press any key to continue.");
            Console.ReadKey(true);
        }
Esempio n. 24
0
        private void button15_Click(object sender, EventArgs e)
        {
            iTunes      = new iTunesAppClass();
            mainLibrary = iTunes.LibraryPlaylist;
            tracks      = mainLibrary.Tracks;

            var count = tracks.Count;

            var sb = new StringBuilder();

            for (int i = 1; i < tracks.Count + 1; i++)
            {
                IITFileOrCDTrack track = tracks[i] as IITFileOrCDTrack;

                if (track != null)
                {
                    if (track.Location != null)
                    {
                        if (track.Location.StartsWith(FileRoot))
                        {
                            if (string.IsNullOrWhiteSpace(track.Description))
                            {
                                try {
                                    string sortAlbumString = string.Format("{0} {1}", track.Year, track.Album);

                                    var fiSong       = new FileInfo(track.Location);
                                    var artistString = fiSong.Directory.Parent.Name;

                                    if (track.SortAlbum != sortAlbumString)
                                    {
                                        track.SortAlbum = sortAlbumString;
                                    }

                                    if (string.IsNullOrWhiteSpace(track.Description))
                                    {
                                        track.Description = track.Artist; // stick MusicBrainz' Artist info into Description
                                    }
                                    track.Artist          = artistString;
                                    track.AlbumArtist     = artistString;
                                    track.SortAlbumArtist = artistString;

                                    // todo: is albumartist null?

                                    //if (track.SortArtist != track.AlbumArtist)
                                    //    track.SortArtist = track.AlbumArtist;

                                    sb.AppendLine(track.Location);
                                    //track.UpdateInfoFromFile();
                                }
                                catch (Exception ex)
                                {
                                    sb.AppendLine(ex.Message);
                                }
                            }
                        }
                    }
                }
            }

            textBox1.Text = sb.ToString();
        }
Esempio n. 25
0
        /// <summary>
        /// Translate track number.
        /// </summary>
        /// <param name="track"></param>
        /// <param name="patternstring"></param>
        /// <returns></returns>
        private static string TranslateTrackNumber(IITFileOrCDTrack track, string patternstring)
        {
            //Replace track number with a number only if the iTunes track has this field set
            if (track.TrackNumber != 0)
            {
                //%TRACKNUMSPACE%
                patternstring = patternstring.Replace("%TRACKNUMSPACE%",
                    (track.TrackNumber.ToString().Length == 1 ?
                    "0" + track.TrackNumber.ToString() : track.TrackNumber.ToString()) + " ");

                //%TRACKNUM%
                patternstring = patternstring.Replace("%TRACKNUM%",
                    (track.TrackNumber.ToString().Length == 1 ?
                    "0" + track.TrackNumber.ToString() : track.TrackNumber.ToString()));
            }
            else //If there are no track number set for the track
            {
                //%TRACKNUMSPACE%
                patternstring = patternstring.Replace("%TRACKNUMSPACE%", "");
                //%TRACKNUM%
                patternstring = patternstring.Replace("%TRACKNUM%", "");
            }
            return patternstring;
        }
Esempio n. 26
0
 private void notFoundiTunes(IITFileOrCDTrack ft)
 {
     txtLog.Text = "Could not find file: " + ft.Artist + ";" + ft.Album + ";" + ft.Name + "=\r\n" + txtLog.Text;
 }
Esempio n. 27
0
        /// <summary>
        /// Translate disc number.
        /// </summary>
        /// <param name="track"></param>
        /// <param name="patternstring"></param>
        /// <returns></returns>
        private static string TranslateDiscNumber(IITFileOrCDTrack track, string patternstring)
        {
            //Replace track number with a number only if the iTunes track has this field set
            if (track.DiscNumber != 0 && track.DiscCount > 1)
            {
                //%DISCNUMDASH%%
                patternstring = patternstring.Replace("%DISCNUMDASH%",
                    track.DiscNumber.ToString() + "-");

                //%DISCNUM%
                patternstring = patternstring.Replace("%DISCNUM%",
                    track.DiscNumber.ToString());
            }
            else //If there are no track number set for the track
            {
                //%DISCNUMDASH%
                patternstring = patternstring.Replace("%DISCNUMDASH%", "");
                //%DISCNUM%
                patternstring = patternstring.Replace("%DISCNUM%", "");
            }
            return patternstring;
        }
Esempio n. 28
0
        private string getOutput(IITFileOrCDTrack ft)
        {
            // format to use in mass tagger
            // %rating%|%play_count%|%last_played%|%skip_count%|%last_skipped%|%added%

            string added = "";
            added = (ft.Rating / 20).ToString();
            added += "|" + ft.PlayedCount;
            added += "|" + getDateString(ft.PlayedDate) + "|" + ft.SkippedCount + "|" + getDateString(ft.SkippedDate) + "|" + getDateString(ft.DateAdded);
            return added;
        }
Esempio n. 29
0
 private bool TrackExistsInFileSystem(IITFileOrCDTrack fileTrack)
 {
     return System.IO.File.Exists(fileTrack.Location);
 }
 public MissingTrackException(IITFileOrCDTrack track) : base()
 {
     this.track = track;
 }
Esempio n. 31
0
 /// <summary>
 /// Translate track name.
 /// </summary>
 /// <param name="track"></param>
 /// <param name="patternstring"></param>
 /// <returns></returns>
 private static string TranslateName(IITFileOrCDTrack track, string patternstring)
 {
     patternstring = patternstring.Replace("%NAME%", (track.Name == null ? "Unknown Track" : track.Name));
     return(patternstring);
 }
Esempio n. 32
0
        static void StartDelete(ref IITTrack Tkeep, ref IITTrack Tdel)
        {
            int ModDate = DateTime.Compare(Tkeep.ModificationDate, Tdel.ModificationDate);

            if (ModDate >= 0)
            {
                if (Tkeep.Composer != null && Tdel.Composer != null)
                {
                    Tkeep.Composer = (string)CompareTrack(Tkeep.Composer, Tdel.Composer, "");
                }
                else if (Tdel.Composer != null)
                {
                    Tkeep.Composer = Tdel.Composer;
                }

                if (Tkeep.Genre != null && Tdel.Genre != null)
                {
                    Tkeep.Genre = (string)CompareTrack(Tkeep.Genre, Tdel.Genre, UserGenre);
                }
                else if (Tdel.Genre != null)
                {
                    Tkeep.Genre = Tdel.Genre;
                }

                Tkeep.Rating       = (int)CompareTrack(Tkeep.Rating, Tdel.Rating, 0);
                Tkeep.Year         = (int)CompareTrack(Tkeep.Year, Tdel.Year, 0);
                Tkeep.PlayedCount += Tdel.PlayedCount;
                //Tkeep.PlayedDate    = CompareTrack(Tkeep.PlayedDate, Tdel.PlayedDate);
            }
            else
            {
                if (Tkeep.Composer != null && Tdel.Composer != null)
                {
                    Tkeep.Composer = (string)CompareTrack(Tdel.Composer, Tkeep.Composer, "");
                }
                else if (Tdel.Composer != null)
                {
                    Tkeep.Composer = Tdel.Composer;
                }

                if (Tkeep.Genre != null && Tdel.Genre != null)
                {
                    Tkeep.Genre = (string)CompareTrack(Tdel.Genre, Tkeep.Genre, UserGenre);
                }
                else if (Tdel.Genre != null)
                {
                    Tkeep.Genre = Tdel.Genre;
                }

                Tkeep.Rating       = (int)CompareTrack(Tdel.Rating, Tkeep.Rating, 0);
                Tkeep.Compilation  = Tdel.Compilation;
                Tkeep.Year         = (int)CompareTrack(Tdel.Year, Tkeep.Year, 0);
                Tkeep.PlayedCount += Tdel.PlayedCount;
                //Tdel.PlayedDate   = CompareTrack(Tdel.PlayedDate, Tkeep.PlayedDate);
            }

            if (Tdel.Kind == ITTrackKind.ITTrackKindFile)
            {
                IITFileOrCDTrack file = (IITFileOrCDTrack)Tdel;
                if (file.Location != null || file.Location != "")
                {
                    FileInfo fi = new FileInfo(file.Location);
                    if (fi.Exists)
                    {
                        fi.Delete();
                    }
                }
            }
            Console.WriteLine("Deleted: " + Tdel.PlayOrderIndex.ToString() + ":" + Tdel.Name);
            Tdel.Delete();
        }
Esempio n. 33
0
 public bool Load(int index, IITTrackCollection tracks)
 {
     // only work with files
     _file = tracks[index] as IITFileOrCDTrack;
     return null != _file;
 }
Esempio n. 34
0
 static void AICFor(ref IITFileOrCDTrack TrackFile)
 {
     // TrackFile.Artwork = TrackFile.Artwork;
 }
Esempio n. 35
0
        private void RebuildTag(string filename, IITFileOrCDTrack track)
        {
            var mediaFile = TagLib.File.Create(filename);

            var tag = mediaFile.Tag;

            tag.Title = track.Name;
            if (track.SortName != track.Name)
            {
                tag.TitleSort = track.SortName;
            }
            tag.Performers = new[] { track.Artist };
            if (track.SortArtist != track.Artist)
            {
                tag.PerformersSort = new[] { track.SortArtist }
            }
            ;
            tag.Album = track.Album;
            if (track.SortAlbum != track.Album)
            {
                tag.AlbumSort = track.SortAlbum;
            }
            tag.AlbumArtists = new[] { track.AlbumArtist };
            if (track.SortAlbumArtist != track.AlbumArtist)
            {
                tag.AlbumArtistsSort = new[] { track.SortAlbumArtist }
            }
            ;
            tag.Composers = new[] { track.Composer };
            if (track.SortComposer != track.Composer)
            {
                tag.ComposersSort = new[] { track.SortComposer }
            }
            ;

            tag.Genres = new[] { track.Genre };
            if (track.Year > 0)
            {
                tag.Year = (uint)track.Year;
            }
            if (track.TrackNumber > 0)
            {
                tag.Track = (uint)track.TrackNumber;
            }
            if (track.TrackCount > 0)
            {
                tag.TrackCount = (uint)track.TrackCount;
            }
            if (track.DiscNumber > 0)
            {
                tag.Disc = (uint)track.DiscNumber;
            }
            if (track.DiscCount > 0)
            {
                tag.DiscCount = (uint)track.DiscCount;
            }
            if (track.BPM > 0)
            {
                tag.BeatsPerMinute = (uint)track.BPM;
            }

            tag.Lyrics  = track.Lyrics;
            tag.Comment = track.Comment;

            var arts = track.Artwork;

            tag.Pictures = (
                from IITArtwork artwork
                in arts
                select WriteArtwork(track, artwork)
                ).ToArray();

            mediaFile.RemoveTags(mediaFile.TagTypes & ~mediaFile.TagTypesOnDisk);
            mediaFile.Save();
            mediaFile.Dispose();
        }
Esempio n. 36
0
 /// <summary>
 /// Translate file extension.
 /// </summary>
 /// <param name="track"></param>
 /// <param name="patternstring"></param>
 /// <returns></returns>
 private static string TranslateExtension(IITFileOrCDTrack track, string patternstring)
 {
     int extensionstart = track.Location.LastIndexOf(".");
     patternstring = patternstring + track.Location.Substring(extensionstart, track.Location.Length - extensionstart);
     return patternstring;
 }
 static void SetMusicBeeAlbumRating(this IITFileOrCDTrack track, int value)
 {
     track.AlbumRating = value * 20;
 }
Esempio n. 38
0
 /// <summary>
 /// Translate track name.
 /// </summary>
 /// <param name="track"></param>
 /// <param name="patternstring"></param>
 /// <returns></returns>
 private static string TranslateName(IITFileOrCDTrack track, string patternstring)
 {
     patternstring = patternstring.Replace("%NAME%", (track.Name == null ? "Unknown Track" : track.Name));
     return patternstring;
 }
Esempio n. 39
0
        public Track(IITFileOrCDTrack track)
        {
            /*Album = track.Album;
             * AlbumArtist = track.AlbumArtist;
             * AlbumRating = track.AlbumRating;
             * AlbumRatingKind = track.AlbumRatingKind;
             * Artist = track.Artist;
             * BitRate = track.BitRate;
             * BookmarkTime = track.BookmarkTime;
             * BPM = track.BPM;
             * Category = track.Category;*/
            Comment = track.Comment;

            /*Compilation = track.Compilation;
             * DateAdded = track.DateAdded;
             * Description = track.Description;
             * DiscCount = track.DiscCount;
             * DiscNumber = track.DiscNumber;
             * Duration = track.Duration;
             * Enabled = track.Enabled;
             * EpisodeNumber = track.EpisodeNumber;
             * ExcludeFromShuffle = track.ExcludeFromShuffle;
             * Finish = track.Finish;
             * Genre = track.Genre;
             * Index = track.Index;
             * Kind = track.Kind;
             * KindAsString = track.KindAsString;*/
            Location = track.Location;

            /*LongDescription = track.LongDescription;
             * Lyrics = track.Lyrics;
             * ModificationDate = track.ModificationDate;
             * Name = track.Name;
             * PartOfGaplessAlbum = track.PartOfGaplessAlbum;
             * PlayedCount = track.PlayedCount;
             * PlayedDate = track.PlayedDate;
             * PlayOrderIndex = track.PlayOrderIndex;
             * Podcast = track.Podcast;
             * Rating = track.Rating;
             * ReleaseDate = track.ReleaseDate;
             * RememberBookmark = track.RememberBookmark;
             * SampleRate = track.SampleRate;
             * SeasonNumber = track.SeasonNumber;
             * Size = track.Size;
             * Size64High = track.Size64High;
             * Size64Low = track.Size64Low;
             * SkippedCount = track.SkippedCount;
             * SkippedDate = track.SkippedDate;
             * SortAlbum = track.SortAlbum;
             * SortAlbumArtist = track.SortAlbumArtist;
             * SortArtist = track.SortArtist;
             * SortComposer = track.SortComposer;
             * SortName = track.SortName;
             * SortShow = track.SortShow;
             * Start = track.Start;
             * Time = track.Time;
             * TrackCount = track.TrackCount;
             * TrackNumber = track.TrackNumber;
             * Unplayed = track.Unplayed;
             * VolumeAdjustment = track.VolumeAdjustment;
             * Year = track.Year;*/
            iTunesTrack = track;

            try
            {
                Fingerprint = new TrackFingerprint(Comment);
            }
            catch { }
        }
Esempio n. 40
0
        private void Form1_Load(object sender, EventArgs e)
        {
            timer1.Start();

            IITTrack track = iTunes.CurrentTrack;

            if (track == null)
            {
                label1.Text   = "Disabled";
                textBox1.Text = "Disabled";
                return;
            }
            if (!track.Enabled)
            {
                label1.Text   = "Disabled";
                textBox1.Text = "Disabled";
            }

            string trackName   = track.Name;
            string trackArtist = track.Artist;
            string trackAlbum  = track.Album;

            label2.Text = textBox1.Font.Size.ToString();

            label3.Text = "";

            label1.Text = trackName + " | " + trackArtist + " | " + trackAlbum;
            int duration = track.Duration;

            if (MusixMatchMode)
            {
                Dictionary <string, string> dic = GetMusixMatchLyrics(trackName, trackArtist);
                if (dic != null && dic["instrumental"] == "1")
                {
                    textBox1.Text = "Instrumental";
                    return;
                }
                string lyrics = dic["lyrics"];
                string artist = dic["artist"];
                if (lyrics == null)
                {
                    dic = GetMusixMatchLyrics(trackName);
                    if (dic != null)
                    {
                        lyrics = dic["lyrics"];
                        artist = dic["artist"];
                    }
                }
                if (lyrics != null)
                {
                    textBox1.Text = lyrics;
                    label3.Text   = artist;
                }
                else
                {
                    if (dic != null && dic["instrumental"] == "1")
                    {
                        textBox1.Text = "Instrumental";
                    }
                    else
                    {
                        textBox1.Text = "見つかりませんでした。";
                    }
                }
            }
            else
            {
                IITFileOrCDTrack cdtrack = (IITFileOrCDTrack)track;
                textBox1.Text = cdtrack.Lyrics;
            }

            /*
             * string loc = cdtrack.Location;
             * label1.Text = loc;
             *
             * string dir = Path.GetDirectoryName(loc);
             * string filename = Path.GetFileNameWithoutExtension(loc);
             *
             * string lyricsFilePathLRC = dir + "\\" + filename + ".lrc";
             * string lyricsFilePathTXT = dir + "\\" + filename + ".txt";
             *
             * if (File.Exists(lyricsFilePathLRC))
             * {
             *  // 歌詞ファイルがある
             *  using (StreamReader r = new StreamReader(lyricsFilePathLRC, Encoding.GetEncoding("shift_jis")))
             *  {
             *      string line;
             *      while ((line = r.ReadLine()) != null)
             *      {
             *          Console.WriteLine(line); // [00:00:00]Welcome to ようこそジャパリパーク!
             *          // TODO []内を:で切って、分秒ミリ秒?で処理、秒に直してうんちゃら
             *      }
             *  }
             * }
             * else if (File.Exists(lyricsFilePathTXT))
             * {
             *  // 歌詞ファイルがある
             *  using (StreamReader r = new StreamReader(lyricsFilePathTXT, Encoding.GetEncoding("shift_jis")))
             *  {
             *      string line;
             *      while ((line = r.ReadLine()) != null)
             *      {
             *          Console.WriteLine(line);
             *      }
             *  }
             * }
             * else {
             *  // 歌詞ファイルがない
             *
             * }
             */
        }
Esempio n. 41
0
        //NOT CONSOLIDATED SONGS
        public static void PerformNCS()
        {
            Console.Clear();
            Console.WriteLine("Performing NCS (Not Consolidated Songs)");
            Console.Title = "Performing NCS (Not Consolidated Songs)";
            Console.WriteLine("Scanning will now start.\r\n");
            //string dt1 = DateTime.Now.ToLongTimeString();
            int tot  = iTunes.LibraryPlaylist.Tracks.Count;
            int ncss = 0;

            //File.Delete("C:\\NCS.txt");
            //StreamWriter sw = File.AppendText("C:\\NCS.txt");
            //sw.AutoFlush = true;
            for (int i = 1; i <= tot; i++)
            {
                if (iTunes.LibraryPlaylist.Tracks[i].Kind == ITTrackKind.ITTrackKindFile)
                {
                    IITFileOrCDTrack file = (IITFileOrCDTrack)iTunes.LibraryPlaylist.Tracks[i];
                    if (file.Location != null)
                    {
                        if (!file.Location.Contains("iTunes Music"))
                        {
                            string location = file.Location;
                            if (file.Location.StartsWith(@"C:\Documents and Settings\Amelie\Mes documents\Ma musique\MyiPodBackup\"))
                            {
                                location = file.Location.Replace(@"C:\Documents and Settings\Amelie\Mes documents\Ma musique\MyiPodBackup\", @"C:\MusicFolder\");
                            }
                            if (file.Location.StartsWith(@"C:\audiograbber\"))
                            {
                                location = file.Location.Replace(@"C:\audiograbber\", @"C:\MusicFolder\");
                            }

                            string origdir = location.Remove(location.LastIndexOf("\\")) + "\\";
                            if (Directory.Exists(origdir) == false)
                            {
                                string dir = "";
                                while (Directory.Exists(origdir) == false)
                                {
                                    int l = dir.Length;
                                    dir = location.Substring(0, location.IndexOf("\\", l)) + "\\";
                                    Directory.CreateDirectory(dir);
                                }
                            }

                            File.Move(file.Location, location);
                            Console.WriteLine("Moved the song to:");
                            Console.WriteLine(location);
                            ncss++;
                        }
                    }
                }
                Console.WriteLine("Scanning: " + i + "/" + tot);
            }
            //sw.Close();
            //Process.Start("C:\\NCS.txt");
            string[] files = Directory.GetFiles(@"C:\MusicFolder", "*", SearchOption.AllDirectories);
            tot = files.Length;
            for (int a = 0; a < tot; a++)
            {
                string newname = files[a];
                newname  = newname.Remove(newname.LastIndexOf("\\")) + "\\";
                newname += a.ToString() + "algkjfovuoa.mp3";
                //Console.WriteLine("Changed;");
                //Console.WriteLine(files[a]);
                //Console.WriteLine(newname);
                File.Move(files[a], newname);
                Console.WriteLine("Correcting Names for Import... (" + a.ToString() + "/" + tot);
            }
            Console.WriteLine("Total NCSs: " + ncss.ToString());
            Console.WriteLine(@"Now add the folder 'C:\MusicFolder\' to ur itunes library and then perform DDS, or Sync Ratings with your ipod, then do RMS");
            Console.ReadKey(false);
        }
Esempio n. 42
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);
        }