Exemplo n.º 1
0
        public string GetDiscName()
        {
            foreach (XmlTrack track in Tracks)
            {
                if (!string.IsNullOrEmpty(track.Album))
                {
                    return(string.Format("{0} Disc {1}", track.Album, DiscNumber.ToString("000")));
                }
            }

            return(string.Format("{0} Disc {1}", ConstantStrings.UnknownDisc, DiscNumber.ToString("000")));
        }
 public void ListWithDefaultClientTest()
 {
     using (var server = new HttpServer(new RequestHandler
     {
         EstimatedMethod = "GET",
         EstimatedPathAndQuery = string.Format("/v1.0/accounts/{0}/discnumbers", Helper.AccountId),
         ContentToSend = new StringContent(TestXmlStrings.DiscNumberResponse, Encoding.UTF8, "application/xml")
     }))
     {
         var result = DiscNumber.List().Result;
         if (server.Error != null)
         {
             throw server.Error;
         }
         Assert.AreEqual(2, result.Length);
     }
 }
 public void GetTotalsTest()
 {
     using (var server = new HttpServer(new RequestHandler
     {
         EstimatedMethod = "GET",
         EstimatedPathAndQuery = string.Format("/v1.0/accounts/{0}/discnumbers/totals", Helper.AccountId),
         ContentToSend = new StringContent(TestXmlStrings.InServiceNumbersTotals, Encoding.UTF8, "application/xml")
     }))
     {
         var client = Helper.CreateClient();
         var result = DiscNumber.GetTotals(client).Result;
         if (server.Error != null)
         {
             throw server.Error;
         }
         Assert.AreEqual(3, result.Count);
     }
 }
Exemplo n.º 4
0
        /// <summary>
        /// Returns a string field
        /// </summary>
        /// <param name="name">Name of field</param>
        /// <returns></returns>
        public string this[string name]
        {
            get
            {
                switch (name.ToLower())
                {
                case "title":
                    return(Title);

                case "artist":
                    return(Artist);

                case "album":
                    return(Album);

                case "genre":
                    return(Genre);

                case "rating":
                    return(RatingString);

                case "length":
                    return(LengthString);

                case "play count":
                    return(PlayCount.ToString());

                case "date added":
                    return(DateAdded.ToShortTimeString());

                case "last played":
                    return(LastPlayed.ToShortDateString());

                case "track number":
                    return(TrackNumber.ToString());

                case "disc number":
                    return(DiscNumber.ToString());

                default:
                    return(null);
                }
            }
        }
Exemplo n.º 5
0
        private TagData toTagData()
        {
            TagData result = new TagData();

            result.Title              = Title;
            result.Artist             = Artist;
            result.Composer           = Composer;
            result.Comment            = Comment;
            result.Genre              = Genre;
            result.OriginalArtist     = OriginalArtist;
            result.OriginalAlbum      = OriginalAlbum;
            result.GeneralDescription = Description;
            result.Rating             = (Popularity * 5).ToString();
            result.Copyright          = Copyright;
            result.Publisher          = Publisher;
            if (!PublishingDate.Equals(DateTime.MinValue))
            {
                result.PublishingDate = TrackUtils.FormatISOTimestamp(PublishingDate);
            }
            result.AlbumArtist = AlbumArtist;
            result.Conductor   = Conductor;
            if (!Date.Equals(DateTime.MinValue))
            {
                result.RecordingDate = TrackUtils.FormatISOTimestamp(Date);
            }
            result.RecordingYear            = Year.ToString();
            result.Album                    = Album;
            result.TrackNumber              = TrackNumber.ToString();
            result.TrackTotal               = TrackTotal.ToString();
            result.DiscNumber               = DiscNumber.ToString();
            result.DiscTotal                = DiscTotal.ToString();
            result.ChaptersTableDescription = ChaptersTableDescription.ToString();

            result.Chapters = new List <ChapterInfo>();
            foreach (ChapterInfo chapter in Chapters)
            {
                result.Chapters.Add(new ChapterInfo(chapter));
            }

            if (Lyrics != null)
            {
                result.Lyrics = new LyricsInfo(Lyrics);
            }

            foreach (string s in AdditionalFields.Keys)
            {
                result.AdditionalFields.Add(new MetaFieldInfo(MetaDataIOFactory.TAG_ANY, s, AdditionalFields[s]));
            }

            // Detect and tag deleted Additional fields (=those which were in initialAdditionalFields and do not appear in AdditionalFields anymore)
            foreach (string s in initialAdditionalFields)
            {
                if (!AdditionalFields.ContainsKey(s))
                {
                    MetaFieldInfo metaFieldToDelete = new MetaFieldInfo(MetaDataIOFactory.TAG_ANY, s, "");
                    metaFieldToDelete.MarkedForDeletion = true;
                    result.AdditionalFields.Add(metaFieldToDelete);
                }
            }

            result.Pictures = new List <PictureInfo>();
            if (currentEmbeddedPictures != null)
            {
                foreach (PictureInfo targetPic in currentEmbeddedPictures)
                {
                    targetPic.TransientFlag = 0;
                }
            }

            if (initialEmbeddedPictures != null && currentEmbeddedPictures != null)
            {
                foreach (PictureInfo picInfo in initialEmbeddedPictures)
                {
                    // Detect and tag deleted pictures (=those which were in initialEmbeddedPictures and do not appear in embeddedPictures anymore)
                    if (!currentEmbeddedPictures.Contains(picInfo))
                    {
                        PictureInfo picToDelete = new PictureInfo(picInfo);
                        picToDelete.MarkedForDeletion = true;
                        result.Pictures.Add(picToDelete);
                    }
                    else // Only add new additions (pictures identical to initial list will be kept, and do not have to make it to the list, or else a duplicate will be created)
                    {
                        foreach (PictureInfo targetPic in currentEmbeddedPictures)
                        {
                            if (targetPic.Equals(picInfo))
                            {
                                // Compare picture contents
                                targetPic.ComputePicHash();

                                if (targetPic.PictureHash != picInfo.PictureHash)
                                {
                                    // A new picture content has been defined for an existing location
                                    result.Pictures.Add(targetPic);

                                    PictureInfo picToDelete = new PictureInfo(picInfo);
                                    picToDelete.MarkedForDeletion = true;
                                    result.Pictures.Add(picToDelete);
                                }

                                targetPic.TransientFlag = 1;
                            }
                        }
                    }
                }

                if (currentEmbeddedPictures != null)
                {
                    foreach (PictureInfo targetPic in currentEmbeddedPictures)
                    {
                        if (0 == targetPic.TransientFlag) // Entirely new pictures without equivalent in initialEmbeddedPictures
                        {
                            result.Pictures.Add(targetPic);
                        }
                    }
                }
            }

            return(result);
        }
Exemplo n.º 6
0
        public AlbumTrack(string path)
        {
            if (string.IsNullOrWhiteSpace(path))
            {
                throw new ArgumentNullException("path");
            }

            _path = path;

            if (ID3v2Tag.DoesTagExist(path))
            {
                ID3v2Tag id3v2 = new ID3v2Tag(path);
                DiscNumber  = id3v2.DiscNumber;
                TrackNumber = id3v2.TrackNumber;
                Artist      = id3v2.Artist;
                Title       = id3v2.Title;
                ReleaseDate = id3v2.Year;
                Album       = id3v2.Album;
                Genre       = id3v2.Genre;
                if (id3v2.PictureList != null && id3v2.PictureList.Count == 1)
                {
                    Picture = id3v2.PictureList[0];
                }
            }

            if (ID3v1Tag.DoesTagExist(path))
            {
                ID3v1Tag id3v1 = new ID3v1Tag(path);
                if (string.IsNullOrWhiteSpace(TrackNumber))
                {
                    TrackNumber = string.Format("{0}", id3v1.TrackNumber);
                }
                if (string.IsNullOrWhiteSpace(Artist))
                {
                    Artist = id3v1.Artist;
                }
                if (string.IsNullOrWhiteSpace(Title))
                {
                    Title = id3v1.Title;
                }
                if (string.IsNullOrWhiteSpace(ReleaseDate))
                {
                    ReleaseDate = id3v1.Year;
                }
                if (string.IsNullOrWhiteSpace(Album))
                {
                    Album = id3v1.Album;
                }
                if (string.IsNullOrWhiteSpace(Genre))
                {
                    Genre = GenreHelper.GenreByIndex[id3v1.GenreIndex];
                }
            }

            IAudioFile audioFile = AudioFile.Create(_path, throwExceptionIfUnknown: true);

            Bitrate      = audioFile.Bitrate;
            TotalSeconds = audioFile.TotalSeconds;

            // TODO: APE, Lyrics3

            // TODO: When no tags, try to guess from path and file names
            // TODO: Parse Tracks for TotalTracks
            // TODO: Parse Disc for TotalDiscs

            // Parse track # from TrackNumber including total tracks
            if (!string.IsNullOrWhiteSpace(TrackNumber))
            {
                if (TrackNumber.Contains('/'))
                {
                    TrackNumber = TrackNumber.Split(new[] { '/' }, StringSplitOptions.RemoveEmptyEntries)[0];
                    // TODO: Set total tracks?
                }
            }

            // Parse disc # from DiscNumber including total discs
            if (!string.IsNullOrWhiteSpace(DiscNumber))
            {
                if (DiscNumber.Contains('/'))
                {
                    DiscNumber = DiscNumber.Split(new[] { '/' }, StringSplitOptions.RemoveEmptyEntries)[0];
                    // TODO: Set total discs?
                }
            }
            else
            {
                DiscNumber = "1";
            }
        }