Esempio n. 1
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. 2
0
 public bool ContainsSyncPattern(SyncPattern sp) 
 {
     foreach(SyncPattern existingPattern in syncPatterns) {
         
         if(existingPattern.Identifier == sp.Identifier) {
             
             return true;
         }
     }
     return false;
 }
        public void TestTranslate()
        {
            SyncPattern pattern = new SyncPattern();
            pattern.Pattern = "%ARTIST%\\%ALBUM%\\%NAME%";

            MockFileOrCDTrack track = new MockFileOrCDTrack();
            track.Artist = "Coldplay";
            track.Album = "X&Y";
            track.Name = "Fix You";
            track.Location = "C:\\Music\\Coldplay\\X&Y\\Fix You.mp3";

            Assert.AreEqual("Coldplay\\X&Y\\Fix You.mp3",
                SyncPatternTranslator.Translate(pattern, track));
        }
Esempio n. 4
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. 5
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. 6
0
 /// <summary>
 /// Remove a SyncPattern.
 /// </summary>
 /// <param name="sp">SyncPattern to remove.</param>
 /// <returns></returns>
 public bool RemoveSyncPattern(SyncPattern sp)
 {
     return syncPatterns.Remove(sp);
 }
Esempio n. 7
0
 /// <summary>
 /// Add a SyncPattern.
 /// </summary>
 /// <param name="sp">SyncPattern sp</param>
 public void AddSyncPattern(SyncPattern sp)
 {
     syncPatterns.Add(sp);
 }