Example #1
0
        /// <summary>
        /// Asynchronously saves all the album arts in the library.
        /// </summary>
        /// <param name="Data">ID3 tag of the song to get album art data from.</param>
        private async void SaveImages(ID3v2 Data)
        {
            try
            {
                var albumartFolder = ApplicationData.Current.LocalFolder;
                await albumartFolder.CreateFileAsync(@"AlbumArts\" + Mediafile.Title + ".jpg", CreationCollisionOption.ReplaceExisting);

                var albumart = await albumartFolder.GetFileAsync(@"AlbumArts\" + Mediafile.Title + ".jpg");

                using (var albumstream = await albumart.OpenStreamForWriteAsync())
                {
                    BitmapDecoder decoder = await BitmapDecoder.CreateAsync(Data.AttachedPictureFrames[0].Data.AsRandomAccessStream());

                    WriteableBitmap bmp = new WriteableBitmap((int)decoder.PixelWidth, (int)decoder.PixelHeight);
                    await bmp.SetSourceAsync(Data.AttachedPictureFrames[0].Data.AsRandomAccessStream());

                    BitmapEncoder encoder = await BitmapEncoder.CreateAsync(BitmapEncoder.JpegEncoderId, albumstream.AsRandomAccessStream());

                    var    pixelStream = bmp.PixelBuffer.AsStream();
                    byte[] pixels      = new byte[bmp.PixelBuffer.Length];
                    await pixelStream.ReadAsync(pixels, 0, pixels.Length);

                    encoder.SetPixelData(BitmapPixelFormat.Bgra8, BitmapAlphaMode.Ignore, (uint)bmp.PixelWidth, (uint)bmp.PixelHeight, 96, 96, pixels);
                    await encoder.FlushAsync();

                    pixelStream.Dispose();
                }
            }
            catch { }
        }
Example #2
0
        public async Task <Mediafile> CreateMediafile(Stream stream)
        {
            var   Mediafile = new Mediafile();
            ID3v2 Data      = new ID3v2(true, stream);

            Mediafile._id        = LiteDB.ObjectId.NewObjectId();
            Mediafile.Path       = LibraryViewModel.Path;
            Mediafile.Title      = GetStringForNullOrEmptyProperty((await LibVM.GetTextFrame(Data, "TIT2")), System.IO.Path.GetFileNameWithoutExtension(LibraryViewModel.Path));
            Mediafile.LeadArtist = GetStringForNullOrEmptyProperty(await LibVM.GetTextFrame(Data, "TPE1"), "Unknown Artist");
            Mediafile.Album      = GetStringForNullOrEmptyProperty(await LibVM.GetTextFrame(Data, "TALB"), "Unknown Album");
            Mediafile.Length     = (await GetMediaDuration(stream)).ToString(); /* GetStringForNullOrEmptyProperty(await LibVM.GetTextFrame(Data, "TLEN"), "0")*/;
            Mediafile.State      = PlayerState.Stopped;
            Mediafile.Genre      = (await LibVM.GetTextFrame(Data, "TCON")).Remove(0, (await LibVM.GetTextFrame(Data, "TCON")).IndexOf(')') + 1);
            Mediafile.Date       = DateTime.Now.Date.ToString("dd/MM/yyyy");
            if (Mediafile.Genre != null && Mediafile.Genre != "NaN")
            {
                LibVM.GenreCollection.Add(Mediafile.Genre);
            }
            if (Data.AttachedPictureFrames.Count > 0)
            {
                var albumartFolder = ApplicationData.Current.LocalFolder;//Data.AttachedPictureFrames[0].Picture;
                LibVM.SaveImages(Data, Mediafile);
                Mediafile.AttachedPicture = albumartFolder.Path + @"\AlbumArts\" + (Mediafile.Album + Mediafile.LeadArtist).ToLower().ToSha1() + ".jpg";
                GC.Collect();
            }
            return(Mediafile);
        }
Example #3
0
 public void ReadID3v2(string file)
 {
     // read id3 stuff
     id3v2 = new ID3v2(file);
     id3v2.Read();
     this.hasID3v2 = id3v2.hasTag;
 }
Example #4
0
        public listMusicItem(string path, string bg, string outpath)
        {
            this.path = path;
            updatePaths(bg, outpath);

            // get ze id3 dataz!
            // http://www.codeproject.com/KB/cs/Do_Anything_With_ID3.aspx
            ID3Info f   = new ID3Info(path, true);
            ID3v2   id3 = f.ID3v2Info;

            this.title  = id3.GetTextFrame("TIT2");
            this.artist = id3.GetTextFrame("TPE1");
            this.album  = id3.GetTextFrame("TALB");

            Console.WriteLine("------ File ID3 data :: " + Path.GetFileName(path));
            Console.WriteLine("Title: " + title);
            Console.WriteLine("Artist: " + artist);
            Console.WriteLine("Album: " + album);

            // try to get any images if possible
            images = new Image[id3.AttachedPictureFrames.Count];
            for (int i = 0; i < id3.AttachedPictureFrames.Count; i++)
            {
                AttachedPictureFrame ap = id3.AttachedPictureFrames.Items[i];

                // Empty catch!? :o SHOCK! HORROR! no seriously, who cares what goes wrong here...
                try { images[i] = Image.FromStream(ap.Data); } catch { }
            }

            Console.WriteLine("Images Found: " + images.Length.ToString());
        }
Example #5
0
        private void Button_Lyrics_OK_Click(object sender, RoutedEventArgs e)
        {
            int SelectedIndex = DataListBox.SelectedIndex;

            if (SelectedIndex < 0 || SelectedIndex > SongList.Count - 1)
            {
                return;
            }

            ID3v2 id3v2 = new ID3v2(SongList[SelectedIndex].SongPath, true);

            if (id3v2.TextWithLanguageFrames.Count > 0)
            {
                id3v2.TextWithLanguageFrames.Clear();
            }

            id3v2.TextWithLanguageFrames.Add(new ID3.ID3v2Frames.TextFrames.TextWithLanguageFrame("USLT", 0, Textbox_EditLyrics.Text, "", TextEncodings.UTF_16, "eng"));
            SongList[SelectedIndex].SongLyrics = Textbox_EditLyrics.Text;
            id3v2.Save();
            DataListBox.SelectedIndex = -1;
            DataListBox.SelectedIndex = SelectedIndex;

            Sb5.Begin();
            DataListBox.IsEnabled = true;
        }
Example #6
0
        public TrackTags Read(string filePath)
        {
            if (!File.Exists(filePath))
            {
                return(new TrackTags());
            }

            var id3V2Tags = ID3v2.FromFile(filePath);

            var tags = new TrackTags();

            tags.Album       = Get(id3V2Tags, ID3v2Mapping.Album);
            tags.AlbumArtist = Get(id3V2Tags, ID3v2Mapping.AlbumArtist);
            tags.Artist      = Get(id3V2Tags, ID3v2Mapping.Artist);
            tags.Comment     = Get(id3V2Tags, ID3v2Mapping.Comment);
            tags.Composer    = Get(id3V2Tags, ID3v2Mapping.Composer);
            tags.DiscNumber  = Get(id3V2Tags, ID3v2Mapping.DiscNumber);
            tags.FileName    = Path.GetFileNameWithoutExtension(filePath);
            tags.Genre       = Get(id3V2Tags, ID3v2Mapping.Genre);
            tags.Title       = Get(id3V2Tags, ID3v2Mapping.Title);
            tags.TrackNumber = Get(id3V2Tags, ID3v2Mapping.TrackNumber);
            tags.Year        = Get(id3V2Tags, ID3v2Mapping.Year);

            var codec = CodecFactory.Instance.GetCodec(filePath);

            if (codec != null)
            {
                tags.Length = codec.GetLength();
            }

            return(tags);
        }
Example #7
0
        /// <summary>
        /// Asynchronously saves all the album arts in the library.
        /// </summary>
        /// <param name="Data">ID3 tag of the song to get album art data from.</param>
        public async void SaveImages(ID3v2 Data, Mediafile file)
        {
            var albumartFolder = ApplicationData.Current.LocalFolder;
            //Debug.Write(albumartFolder.Path);
            var md5Path = (file.Album + file.LeadArtist).ToLower().ToSha1();

            if (!File.Exists(albumartFolder.Path + @"\AlbumArts\" + md5Path + ".jpg"))
            {
                var albumart = await albumartFolder.CreateFileAsync(@"AlbumArts\" + md5Path + ".jpg", CreationCollisionOption.FailIfExists);

                using (var albumstream = await albumart.OpenStreamForWriteAsync())
                {
                    BitmapDecoder decoder = await BitmapDecoder.CreateAsync(Data.AttachedPictureFrames[0].Data.AsRandomAccessStream());

                    WriteableBitmap bmp = new WriteableBitmap((int)decoder.PixelWidth, (int)decoder.PixelHeight);
                    await bmp.SetSourceAsync(Data.AttachedPictureFrames[0].Data.AsRandomAccessStream());

                    BitmapEncoder encoder = await BitmapEncoder.CreateAsync(BitmapEncoder.JpegEncoderId, albumstream.AsRandomAccessStream());

                    var    pixelStream = bmp.PixelBuffer.AsStream();
                    byte[] pixels      = new byte[bmp.PixelBuffer.Length];
                    await pixelStream.ReadAsync(pixels, 0, pixels.Length);

                    encoder.SetPixelData(BitmapPixelFormat.Bgra8, BitmapAlphaMode.Ignore, (uint)bmp.PixelWidth, (uint)bmp.PixelHeight, 96, 96, pixels);
                    await encoder.FlushAsync();

                    pixelStream.Dispose();
                }
            }
        }
Example #8
0
        public async Task <Mediafile> CreateMediafile(Stream stream)
        {
            var   Mediafile = new Mediafile();
            ID3v2 Data      = new ID3v2(true, stream);

            Mediafile._id        = LiteDB.ObjectId.NewObjectId();
            Mediafile.Path       = Path;
            Mediafile.Title      = GetStringForNullOrEmptyProperty((await GetTextFrame(Data, "TIT2")), System.IO.Path.GetFileNameWithoutExtension(Path));
            Mediafile.LeadArtist = GetStringForNullOrEmptyProperty(await GetTextFrame(Data, "TPE1"), "Unknown Artist");
            Mediafile.Album      = GetStringForNullOrEmptyProperty(await GetTextFrame(Data, "TALB"), "Unknown Album");
            Mediafile.State      = PlayerState.Stopped;
            Mediafile.Genre      = (await GetTextFrame(Data, "TCON")).Remove(0, (await GetTextFrame(Data, "TCON")).IndexOf(')') + 1);
            Mediafile.Date       = DateTime.Now.Date.ToString("dd/MM/yyyy");
            if (Mediafile.Genre != null && Mediafile.Genre != "NaN")
            {
                Mediafile.Playlists.Add(new Playlist()
                {
                    Name = "Hello"
                });
                GenreCollection.Add(Mediafile.Genre);
            }
            if (Data.AttachedPictureFrames.Count > 0)
            {
                Mediafile.Playlists.Add(new Playlist()
                {
                    Name = "Top Songs"
                });
                //Mediafile.AttachedPicture = Data.AttachedPictureFrames[0].Picture;
                //SaveImages(Data);
                GC.Collect();
            }
            return(Mediafile);
        }
Example #9
0
        public void LoadTags(string filename)
        {
            ID3v2 t2 = ID3v2.FromFile(filename);
            ID3v1 t1 = ID3v1.FromFile(filename);

            if (t2 != null)
            {
                Title          = t2.QuickInfo.Title;
                Artist         = t2.QuickInfo.Artist;
                Album          = t2.QuickInfo.Album;
                Year           = t2.QuickInfo.Year.ToString();
                LeadPerformers = t2.QuickInfo.LeadPerformers;
                Genre          = t2.QuickInfo.Genre.ToString();
                TrackNumber    = t2.QuickInfo.TrackNumber.ToString();
                Comments       = t2.QuickInfo.Comments;

                if (t2.QuickInfo.Image != null)
                {
                    if (Image != null)
                    {
                        (Image as BitmapImage).StreamSource.Dispose();
                        Image = null;
                    }

                    MemoryStream imgstream = new MemoryStream();
                    t2.QuickInfo.Image.Save(imgstream, System.Drawing.Imaging.ImageFormat.Png);
                    var img = new BitmapImage();
                    img.BeginInit();
                    imgstream.Seek(0, SeekOrigin.Begin);
                    img.StreamSource = imgstream;
                    img.EndInit();
                    Image = img;
                }
            }
            if (t1 != null)
            {
                if (String.IsNullOrWhiteSpace(Title))
                {
                    Title = t1.Title;
                }
                if (String.IsNullOrWhiteSpace(Artist))
                {
                    Artist = t1.Artist;
                }
                if (String.IsNullOrWhiteSpace(Album))
                {
                    Album = t1.Album;
                }
                if (String.IsNullOrWhiteSpace(Year))
                {
                    Year = t1.Year.ToString();
                }
                if (string.IsNullOrWhiteSpace(Comments))
                {
                    Comments = t1.Comment;
                }
                Genre = t1.Genre.ToString();
            }
        }
Example #10
0
        private void ParseForMp3Frames(Stream stream, bool enableSeeking)
        {
            Mp3Frame frame = null;
            long     offsetOfFirstFrame = 0;

            stream = new BufferedStream(stream);

            if (enableSeeking)
            {
                while (ID3v2.SkipTag(stream))
                {
                    /* skip all id3 tags (see https://github.com/filoe/cscore/issues/63)
                     * there are some files with multiple id3v2 tags
                     * not sure whether this is according to the id3 specification but we have to handle it anyway
                     * as long as the SkipTag method returns true, another id3 tag has been found
                     */
                }
            }

            while (frame == null)
            {
                if (enableSeeking && stream.IsEndOfStream())
                {
                    break;
                }

                if (enableSeeking)
                {
                    offsetOfFirstFrame = stream.Position;
                }
                frame = Mp3Frame.FromStream(stream);
            }

            if (frame == null)
            {
                throw new Exception("Could not find any MP3-Frames in the stream.");
            }

            if (enableSeeking)
            {
                XingHeader xingHeader = XingHeader.FromFrame(frame);
                if (xingHeader != null)
                {
                    offsetOfFirstFrame = stream.Position;
                }
            }
            _inputFormat = new Mp3Format(frame.SampleRate, frame.ChannelCount, frame.FrameLength, frame.BitRate);

            //Prescan stream
            if (enableSeeking)
            {
                _frameInfoCollection = new FrameInfoCollection();
                while (_frameInfoCollection.AddFromMp3Stream(stream))
                {
                }

                stream.Position = offsetOfFirstFrame;
            }
        }
Example #11
0
        public void ID3v2ConstructorTest()
        {
            string filePath = string.Empty; // TODO: Initialize to an appropriate value
            bool   LoadData = false;        // TODO: Initialize to an appropriate value
            ID3v2  target   = new ID3v2(filePath, LoadData);

            Assert.Inconclusive("TODO: Implement code to verify target");
        }
Example #12
0
        public void LoadLinkedFramesTest()
        {
            ID3v2 target   = new ID3v2(filePath, true);
            bool  expected = true;

            target.LoadLinkedFrames = expected;
            Assert.AreEqual(expected, target.LoadLinkedFrames);
        }
Example #13
0
        public void LinkFramesTest()
        {
            ID3v2 target = new ID3v2(filePath, true);
            FramesCollection <LinkFrame> expected = new FramesCollection <LinkFrame>();
            FramesCollection <LinkFrame> actual;

            actual = target.LinkFrames;
            Assert.AreEqual(expected.Count, actual.Count);
        }
Example #14
0
 public async void GetText(ID3v2 Data)
 {
     if (Data != null)
     {
         Album            = string.IsNullOrEmpty((await GetTextFrame(Data, "TALB"))) ? "Unknown Album" : (await GetTextFrame(Data, "TALB"));
         Title            = string.IsNullOrEmpty((await GetTextFrame(Data, "TIT2"))) ? System.IO.Path.GetFileNameWithoutExtension(path) : (await GetTextFrame(Data, "TIT2"));
         LeadArtist       = string.IsNullOrEmpty((await GetTextFrame(Data, "TPE1"))) ? "Unknown LeadArtist" : (await GetTextFrame(Data, "TPE1"));
         BeatsPerMinutes  = string.IsNullOrEmpty((await GetTextFrame(Data, "TBPM"))) ? "Unknown BPM(BeatsPerMinutes)" : (await GetTextFrame(Data, "TBPM"));
         Composer         = string.IsNullOrEmpty((await GetTextFrame(Data, "TCOM"))) ? "Unknown Composer" : (await GetTextFrame(Data, "TCOM"));
         Genre            = string.IsNullOrEmpty((await GetTextFrame(Data, "TCON"))) ? "Unknown ContentType" : (await GetTextFrame(Data, "TCON"));
         CopyrightMessage = string.IsNullOrEmpty((await GetTextFrame(Data, "TCOP"))) ? "Unknown CopyrightMessage" : (await GetTextFrame(Data, "TCOP"));
         Date             = string.IsNullOrEmpty((await GetTextFrame(Data, "TDAT"))) ? "Unknown Date" : (await GetTextFrame(Data, "TDAT"));
         //EncodingTime = string.IsNullOrEmpty((await GetTextFrame(Data, "TDEN"))) ? "Unknown EncodingTime" : (await GetTextFrame(Data, "TDEN"));
         //PlaylistDelay = string.IsNullOrEmpty((await GetTextFrame(Data, "TDLY"))) ? "Unknown PlaylistDelay" : (await GetTextFrame(Data, "TDLY"));
         //OrginalReleaseTime = string.IsNullOrEmpty((await GetTextFrame(Data, "TDOR"))) ? "Unknown OrginalReleaseTime" : (await GetTextFrame(Data, "TDOR"));
         //RecordingTime = string.IsNullOrEmpty((await GetTextFrame(Data, "TDRC"))) ? "Unknown RecordingTime" : (await GetTextFrame(Data, "TDRC"));
         //ReleaseTime = string.IsNullOrEmpty((await GetTextFrame(Data, "TDRL"))) ? "Unknown ReleaseTime" : (await GetTextFrame(Data, "TDRL"));
         //TaggingTime = string.IsNullOrEmpty((await GetTextFrame(Data, "TDTG"))) ? "Unknown TaggingTime" : (await GetTextFrame(Data, "TDTG"));
         EncodedBy = string.IsNullOrEmpty((await GetTextFrame(Data, "TENC"))) ? "Unknown EncodedBy" : (await GetTextFrame(Data, "TENC"));
         Lyric     = string.IsNullOrEmpty((await GetTextFrame(Data, "TEXT"))) ? "Unknown Lyric/TextWriter" : (await GetTextFrame(Data, "TEXT"));
         //FileType = string.IsNullOrEmpty((await GetTextFrame(Data, "TFLT"))) ? "Unknown FileType" : (await GetTextFrame(Data, "TFLT"));
         //Time = string.IsNullOrEmpty((await GetTextFrame(Data, "TIME"))) ? "Unknown Time" : (await GetTextFrame(Data, "TIME"));
         InvolvedPeopleList = string.IsNullOrEmpty((await GetTextFrame(Data, "TIPL"))) ? "Unknown InvolvedPeopleList" : (await GetTextFrame(Data, "TIPL"));
         //ContentGroupDescription = string.IsNullOrEmpty((await GetTextFrame(Data, "TIT1"))) ? "Unknown ContentGroupDescription" : (await GetTextFrame(Data, "TIT1"));
         Subtitle = string.IsNullOrEmpty((await GetTextFrame(Data, "TIT3"))) ? "Unknown Subtitle/Desripction" : (await GetTextFrame(Data, "TIT3"));
         //InitialKey = string.IsNullOrEmpty((await GetTextFrame(Data, "TKEY"))) ? "Unknown InitialKey" : (await GetTextFrame(Data, "TKEY"));
         Language            = string.IsNullOrEmpty((await GetTextFrame(Data, "TLAN"))) ? "Unknown Language" : (await GetTextFrame(Data, "TLAN"));
         Length              = string.IsNullOrEmpty((await GetTextFrame(Data, "TLEN"))) ? "Unknown Length" : (await GetTextFrame(Data, "TLEN"));
         MusicianCreditsList = string.IsNullOrEmpty((await GetTextFrame(Data, "TMCL"))) ? "Unknown MusicianCreditsList" : (await GetTextFrame(Data, "TMCL"));
         //MediaType = string.IsNullOrEmpty((await GetTextFrame(Data, "TMED"))) ? "Unknown MediaType" : (await GetTextFrame(Data, "TMED"));
         Mood = string.IsNullOrEmpty((await GetTextFrame(Data, "TMOO"))) ? "Unknown Mood" : (await GetTextFrame(Data, "TMOO"));
         //OrginalTitle = string.IsNullOrEmpty((await GetTextFrame(Data, "TOAL"))) ? "Unknown OrginalTitle" : (await GetTextFrame(Data, "TOAL"));
         //OrginalFilename = string.IsNullOrEmpty((await GetTextFrame(Data, "TOFN"))) ? "Unknown OrginalFilename" : (await GetTextFrame(Data, "TOFN"));
         //OrginalLyricist = string.IsNullOrEmpty((await GetTextFrame(Data, "TOLY"))) ? "Unknown OrginalLyricist" : (await GetTextFrame(Data, "TOLY"));
         //OrginalArtist = string.IsNullOrEmpty((await GetTextFrame(Data, "TOPE"))) ? "Unknown OrginalArtist" : (await GetTextFrame(Data, "TOPE"));
         //OrginalReleaseYear = string.IsNullOrEmpty((await GetTextFrame(Data, "TORY"))) ? "Unknown OrginalReleaseYear" : (await GetTextFrame(Data, "TORY"));
         FileOwner = string.IsNullOrEmpty((await GetTextFrame(Data, "TOWN"))) ? "Unknown FileOwner" : (await GetTextFrame(Data, "TOWN"));
         //BandArtist = string.IsNullOrEmpty((await GetTextFrame(Data, "TPE2"))) ? "Unknown BandArtist" : (await GetTextFrame(Data, "TPE2"));
         Conductor = string.IsNullOrEmpty((await GetTextFrame(Data, "TPE3"))) ? "Unknown Conductor" : (await GetTextFrame(Data, "TPE3"));
         //Interpreted = string.IsNullOrEmpty((await GetTextFrame(Data, "TPE4"))) ? "Unknown Interpreted" : (await GetTextFrame(Data, "TPE4"));
         //Partofset = string.IsNullOrEmpty((await GetTextFrame(Data, "TPOS"))) ? "Unknown Partofset" : (await GetTextFrame(Data, "TPOS"));
         //ProducedNotice = string.IsNullOrEmpty((await GetTextFrame(Data, "TPRO"))) ? "Unknown ProducedNotice" : (await GetTextFrame(Data, "TPRO"));
         Publisher     = string.IsNullOrEmpty((await GetTextFrame(Data, "TPUB"))) ? "Unknown Publisher" : (await GetTextFrame(Data, "TPUB"));
         TrackNumber   = string.IsNullOrEmpty((await GetTextFrame(Data, "TRCK"))) ? "Unknown TrackNumber" : (await GetTextFrame(Data, "TRCK"));
         RecordingDate = string.IsNullOrEmpty((await GetTextFrame(Data, "TRDA"))) ? "Unknown RecordingDate" : (await GetTextFrame(Data, "TRDA"));
         //InternetRadioStationName = string.IsNullOrEmpty((await GetTextFrame(Data, "TRSN"))) ? "Unknown InternetRadioStationName" : (await GetTextFrame(Data, "TRSN"));
         //InternetRadioStationOwner = string.IsNullOrEmpty((await GetTextFrame(Data, "TRSO"))) ? "Unknown InternetRadioStationOwner" : (await GetTextFrame(Data, "TRSO"));
         Size = string.IsNullOrEmpty((await GetTextFrame(Data, "TSIZ"))) ? "Unknown Size" : (await GetTextFrame(Data, "TSIZ"));
         //AlbumSortOrder = string.IsNullOrEmpty((await GetTextFrame(Data, "TSOA"))) ? "Unknown AlbumSortOrder" : (await GetTextFrame(Data, "TSOA"));
         //PreformerSortOrder = string.IsNullOrEmpty((await GetTextFrame(Data, "TSOP"))) ? "Unknown PreformerSortOrder" : (await GetTextFrame(Data, "TSOP"));
         //TitleSortOrder = string.IsNullOrEmpty((await GetTextFrame(Data, "TSOT"))) ? "Unknown TitleSortOrder" : (await GetTextFrame(Data, "TSOT"));
         ISRC = string.IsNullOrEmpty((await GetTextFrame(Data, "TSRC"))) ? "Unknown ISRC" : (await GetTextFrame(Data, "TSRC"));
         //SoftwareHardwareAndSettingUsedForEncoding = string.IsNullOrEmpty((await GetTextFrame(Data, "TSSE"))) ? "Unknown Software/HardwareAndSettingUsedForEncoding" : (await GetTextFrame(Data, "TSSE"));
         //SetSubtitle = string.IsNullOrEmpty((await GetTextFrame(Data, "TSST"))) ? "Unknown SetSubtitle" : (await GetTextFrame(Data, "TSST"));
         Year = string.IsNullOrEmpty((await GetTextFrame(Data, "TYER"))) ? "Unknown Year" : (await GetTextFrame(Data, "TYER"));
     }
 }
Example #15
0
        public void ClearAllTest()
        {
            string filePath = string.Empty;                  // TODO: Initialize to an appropriate value
            bool   LoadData = false;                         // TODO: Initialize to an appropriate value
            ID3v2  target   = new ID3v2(filePath, LoadData); // TODO: Initialize to an appropriate value

            target.ClearAll();
            Assert.Inconclusive("A method that does not return a value cannot be verified.");
        }
Example #16
0
        public static Frame FromStream(Stream stream, ID3v2 tag)
        {
            bool result = false;
            FrameHeader header = new FrameHeader(stream, tag.Header.Version);
            long streamPosition = stream.Position + header.FrameSize;
            var frame = FrameFactory.Instance.TryGetFrame(header, tag.Header.Version, stream, out result);
            stream.Position = streamPosition;

            return frame;
        }
Example #17
0
        public void SetMinorVersionTest()
        {
            string filePath = string.Empty;                  // TODO: Initialize to an appropriate value
            bool   LoadData = false;                         // TODO: Initialize to an appropriate value
            ID3v2  target   = new ID3v2(filePath, LoadData); // TODO: Initialize to an appropriate value
            int    ver      = 0;                             // TODO: Initialize to an appropriate value

            target.SetMinorVersion(ver);
            Assert.Inconclusive("A method that does not return a value cannot be verified.");
        }
Example #18
0
        private void Button_SaveSong_Click(object sender, RoutedEventArgs e)
        {
            //保存信息
            //悲催的代码让我的歌曲化为灰烬……
            try
            {
                int NowSelect = DataListBox.SelectedIndex;
                if (NowSelect < 0)
                {
                    return;
                }
                string FileName   = SongList[NowSelect].SongPath;
                bool   NeedToSave = false;

                ID3v2 id3v2 = new ID3v2(FileName, true);

                id3v2.TextFrames.Add(new ID3.ID3v2Frames.TextFrames.TextFrame("TIT2", 0, TextBox_Title.Text, TextEncodings.UTF_16, 3));
                id3v2.TextFrames.Add(new ID3.ID3v2Frames.TextFrames.TextFrame("TPE1", 0, TextBox_Artist.Text, TextEncodings.UTF_16, 3));
                id3v2.TextFrames.Add(new ID3.ID3v2Frames.TextFrames.TextFrame("TALB", 0, TextBox_Album.Text, TextEncodings.UTF_16, 3));

                if (Checkbox_lyrics.IsChecked == true && (string)Checkbox_lyrics.Content == "保存歌曲歌词" && !string.IsNullOrEmpty(SongList[NowSelect].SongLyricsUnsaved))
                {
                    NeedToSave = true;
                    SongList[NowSelect].SongLyrics = SongList[NowSelect].SongLyricsUnsaved;

                    id3v2.TextWithLanguageFrames.Add(new ID3.ID3v2Frames.TextFrames.TextWithLanguageFrame("USLT", 0, SongList[NowSelect].SongLyrics, "", TextEncodings.UTF_16, "eng"));
                }
                if (Checkbox_albumpicture.IsChecked == true && (string)Checkbox_albumpicture.Content == "保存专辑封面")
                {
                    NeedToSave = true;
                    BitmapImage Bitmap = (BitmapImage)Image_album.Source;
                    while (Bitmap.IsDownloading)
                    {
                        Thread.Sleep(50);
                        System.Windows.Forms.Application.DoEvents();
                    }
                    SongList[NowSelect].SongAlbum = Bitmap;

                    JpegBitmapEncoder encoder = new JpegBitmapEncoder();
                    encoder.Frames.Add(BitmapFrame.Create(Bitmap));
                    MemoryStream stream = new MemoryStream();
                    encoder.Save(stream);
                    id3v2.AttachedPictureFrames.Add(new ID3.ID3v2Frames.BinaryFrames.AttachedPictureFrame(0, "", TextEncodings.UTF_16, "image/jpeg",
                                                                                                          ID3.ID3v2Frames.BinaryFrames.AttachedPictureFrame.PictureTypes.Cover_Front, stream));
                }
                if (NeedToSave)
                {
                    id3v2.Save();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("保存出错,请将下列信息反馈到官方博客,以帮助我们改进软件。谢谢!\n(官方博客:http://www.4321.la,下列信息Ctrl+C可复制)" + ex.Message);
            }
        }
Example #19
0
        public void SetTextFrameTest()
        {
            string filePath = string.Empty;                  // TODO: Initialize to an appropriate value
            bool   LoadData = false;                         // TODO: Initialize to an appropriate value
            ID3v2  target   = new ID3v2(filePath, LoadData); // TODO: Initialize to an appropriate value
            string FrameID  = string.Empty;                  // TODO: Initialize to an appropriate value
            string Text     = string.Empty;                  // TODO: Initialize to an appropriate value

            target.SetTextFrame(FrameID, Text);
            Assert.Inconclusive("A method that does not return a value cannot be verified.");
        }
Example #20
0
        public void SaveTest2()
        {
            string filePath = string.Empty;                  // TODO: Initialize to an appropriate value
            bool   LoadData = false;                         // TODO: Initialize to an appropriate value
            ID3v2  target   = new ID3v2(filePath, LoadData); // TODO: Initialize to an appropriate value
            int    Ver      = 0;                             // TODO: Initialize to an appropriate value
            string Formula  = string.Empty;                  // TODO: Initialize to an appropriate value

            target.Save(Ver, Formula);
            Assert.Inconclusive("A method that does not return a value cannot be verified.");
        }
Example #21
0
        public static Frame FromStream(Stream stream, ID3v2 tag)
        {
            bool        result         = false;
            FrameHeader header         = new FrameHeader(stream, tag.Header.Version);
            long        streamPosition = stream.Position + header.FrameSize;
            var         frame          = FrameFactory.Instance.TryGetFrame(header, tag.Header.Version, stream, out result);

            stream.Position = streamPosition;

            return(frame);
        }
Example #22
0
 /// <summary>
 /// Create new ID3 Info class
 /// </summary>
 /// <param name="FileAddress">FileAddress for read ID3 info</param>
 /// <param name="LoadData">Indicate load data in constructor or not</param>
 public ID3Info(string FilePath, bool LoadData)
 {
     _ID3v1 = new ID3v1(FilePath, LoadData);
     try
     {
         _ID3v2 = new ID3v2(FilePath, LoadData);
     }
     catch
     {
         // Falls oben was schiefging haben wir immerhin noch die Daten aus id3v1
     }
 }
Example #23
0
        public void GetTextFrameTest()
        {
            string filePath = string.Empty;                  // TODO: Initialize to an appropriate value
            bool   LoadData = false;                         // TODO: Initialize to an appropriate value
            ID3v2  target   = new ID3v2(filePath, LoadData); // TODO: Initialize to an appropriate value
            string FrameID  = string.Empty;                  // TODO: Initialize to an appropriate value
            string expected = string.Empty;                  // TODO: Initialize to an appropriate value
            string actual;

            actual = target.GetTextFrame(FrameID);
            Assert.AreEqual(expected, actual);
            Assert.Inconclusive("Verify the correctness of this test method.");
        }
Example #24
0
        public Tags(int coreHandle, string filePath)
        {
            inStream = new FileStream(filePath, FileMode.Open,
                                      FileAccess.Read, FileShare.ReadWrite);
            Stream FS = new MemoryStream();

            inStream.CopyTo(FS);
            Path = filePath;
            Data = new ID3v2(true, FS);
            Init();
            inStream.Dispose();
            FS.Dispose();
        }
Example #25
0
        public void CommercialTest()
        {
            string          filePath = string.Empty;                  // TODO: Initialize to an appropriate value
            bool            LoadData = false;                         // TODO: Initialize to an appropriate value
            ID3v2           target   = new ID3v2(filePath, LoadData); // TODO: Initialize to an appropriate value
            CommercialFrame expected = null;                          // TODO: Initialize to an appropriate value
            CommercialFrame actual;

            target.Commercial = expected;
            actual            = target.Commercial;
            Assert.AreEqual(expected, actual);
            Assert.Inconclusive("Verify the correctness of this test method.");
        }
Example #26
0
        public void FilterTypeTest()
        {
            string      filePath = string.Empty;                  // TODO: Initialize to an appropriate value
            bool        LoadData = false;                         // TODO: Initialize to an appropriate value
            ID3v2       target   = new ID3v2(filePath, LoadData); // TODO: Initialize to an appropriate value
            FilterTypes expected = new FilterTypes();             // TODO: Initialize to an appropriate value
            FilterTypes actual;

            target.FilterType = expected;
            actual            = target.FilterType;
            Assert.AreEqual(expected, actual);
            Assert.Inconclusive("Verify the correctness of this test method.");
        }
Example #27
0
 public async Task <string> GetTextFrame(ID3v2 info, string FrameID)
 {
     // string Text = "";
     return(await Task.Run(() =>
     {
         foreach (TextFrame TF in info.TextFrames)
         {
             if (TF.FrameID == FrameID)
             {
                 return TF.Text;
             }
         }
         return "";
     }));
 }
Example #28
0
        public LectorMetadatos(string s)
        {
            switch (Path.GetExtension(s))
            {
            case ".mp3":
                ID3v2 mp3tag = ID3v2.FromFile(s);
                _mp3iD3 = new ID3v2QuickInfo(mp3tag);
                Artista = _mp3iD3.LeadPerformers;
                Titulo  = _mp3iD3.Title;
                break;

            case ".flac":
                _FLACfile = new FLACFile(s, true);
                Artista   = _FLACfile.ARTIST;
                Titulo    = _FLACfile.TITLE;
                break;

            case ".ogg":
                _vorbisReader = new VorbisReader(s);
                foreach (String meta in _vorbisReader.Comments)
                {
                    if (meta.Contains("TITLE="))
                    {
                        Titulo = meta.Replace("TITLE=", "");
                    }
                    else if (meta.Contains("TITLE=".ToLower()))
                    {
                        Titulo = meta.Replace("title=", "");
                    }
                }
                foreach (String meta in _vorbisReader.Comments)
                {
                    if (meta.Contains("ARTIST="))
                    {
                        Artista = meta.Replace("ARTIST=", "");
                    }
                    else if (meta.Contains("ARTIST=".ToLower()))
                    {
                        Artista = meta.Replace("artist=", "");
                    }
                }
                Cerrar();
                break;

            default:
                break;
            }
        }
Example #29
0
        private string Get(ID3v2 id3V2Tags, string frameId)
        {
            var frame = id3V2Tags[frameId];

            if (frame is TextFrame)
            {
                return(((TextFrame)frame).Text.StripControlChars());
            }

            if (frame is CommentAndLyricsFrame)
            {
                return(((CommentAndLyricsFrame)frame).Text.StripControlChars());
            }

            return(string.Empty);
        }
        public async Task <string> GetTextFrame(ID3v2 info, string FrameID)
        {
            // string Text = "";

            return(await Task.Run(() =>
            {
                if ((info.TextFrames[FrameID] as TextFrame) != null)
                {
                    return (info.TextFrames[FrameID] as TextFrame).Text;
                }
                else
                {
                    return "";
                }
            }));
        }
Example #31
0
        private void OnSaveFile()
        {
            List <IAttachedPicture> deleteList = new List <IAttachedPicture>(ID3v2.PictureList);

            foreach (var picture in PictureCollection)
            {
                if (picture.AttachedPicture != null)
                {
                    picture.AttachedPicture.Description = picture.Description;
                    picture.AttachedPicture.PictureType = picture.PictureType;
                    deleteList.Remove(picture.AttachedPicture);
                }
                else
                {
                    IAttachedPicture apic = ID3v2.PictureList.AddNew();
                    apic.Description = picture.Description;
                    apic.PictureType = picture.PictureType;
                    apic.PictureData = picture.PictureBytes;
                }
            }

            foreach (var deletePicture in deleteList)
            {
                ID3v2.PictureList.Remove(deletePicture);
            }

            // TODO: Multiple comments

            /*IComments comments = _id3v2.CommentsList.FirstOrDefault();
             *
             * if (!string.IsNullOrWhiteSpace(Comment))
             * {
             *  if (comments == null)
             *  {
             *      comments = _id3v2.CommentsList.AddNew();
             *  }
             *  comments.Value = Comment;
             * }
             * else
             * {
             *  if (comments != null)
             *      _id3v2.CommentsList.Remove(comments);
             * }*/

            ID3v2.Save(FullFileName);
        }
Example #32
0
 public virtual void RemoveId3v2Tag()
 {
     this.id3v2Tag = null;
 }
Example #33
0
 /// <exception cref="System.IO.IOException"></exception>
 /// <exception cref="Mp3net.UnsupportedTagException"></exception>
 /// <exception cref="Mp3net.InvalidDataException"></exception>
 private void InitId3v2Tag(RandomAccessFile file)
 {
     if (xingOffset == 0 || startOffset == 0)
     {
         id3v2Tag = null;
     }
     else
     {
         int bufferLength;
         if (HasXingFrame())
         {
             bufferLength = xingOffset;
         }
         else
         {
             bufferLength = startOffset;
         }
         byte[] bytes = new byte[bufferLength];
         file.Seek(0);
         int bytesRead = file.Read(bytes, 0, bufferLength);
         if (bytesRead < bufferLength)
         {
             throw new IOException("Not enough bytes read");
         }
         try
         {
             id3v2Tag = ID3v2TagFactory.CreateTag(bytes);
         }
         catch (NoSuchTagException)
         {
             id3v2Tag = null;
         }
     }
 }
Example #34
0
 private void SetTagFields(ID3v2 id3tag)
 {
     id3tag.SetTrack("1");
     id3tag.SetArtist("ARTIST");
     id3tag.SetTitle("TITLE");
     id3tag.SetAlbum("ALBUM");
     id3tag.SetYear("1954");
     id3tag.SetGenre(unchecked((int)(0x0d)));
     id3tag.SetComment("COMMENT");
     id3tag.SetComposer("COMPOSER");
     id3tag.SetOriginalArtist("ORIGINALARTIST");
     id3tag.SetCopyright("COPYRIGHT");
     id3tag.SetUrl("URL");
     id3tag.SetEncoder("ENCODER");
     byte[] albumImage = TestHelper.LoadFile("Resources/image.png");
     id3tag.SetAlbumImage(albumImage, "image/png");
 }
Example #35
0
 public ID3Wrapper(ID3v1 id3v1Tag, ID3v2 id3v2Tag)
 {
     this.id3v1Tag = id3v1Tag;
     this.id3v2Tag = id3v2Tag;
 }
Example #36
0
        /// <summary>
        /// Get artist name from song
        /// </summary>
        /// <param></param>
        private void GetSongInfo()
        {
            tagFile = File.Create(this.FilePath);
            tag = tagFile.Tag;

            if(!tag.IsEmpty)
            {
                if (tag.FirstPerformer != null)
                {
                    this.Artist = tag.FirstPerformer;
                }
                else if (tag.FirstAlbumArtist != null)
                {
                    this.Artist = tag.FirstAlbumArtist;
                }
                else
                    this.Artist = "Unknown";

                if (tag.Title != null)
                {
                    this.SongName = tag.Title;
                }
                else
                    this.SongName = this.FilePath;

                this.Genre = tag.FirstGenre;
                TrackNum = tag.Track;
            }
            else
            {
                // in the rare chance taglibs doesnt recognise tags, try reading tags via cscore
                cTag = ID3v2.FromFile(this.FilePath);
                if (cTag.QuickInfo.LeadPerformers != "")
                {
                    this.Artist = cTag.QuickInfo.LeadPerformers;
                }
                else if (cTag.QuickInfo.Artist != "")
                {
                    this.Artist = cTag.QuickInfo.Artist;
                }
                else
                    this.Artist = "Unknown";

                this.SongName = cTag.QuickInfo.Title;
                this.Genre = cTag.QuickInfo.Genre.ToString();
                if (cTag.QuickInfo.TrackNumber == null)
                    TrackNum = 1;
                else
                    TrackNum = (uint)cTag.QuickInfo.TrackNumber;
            }
        }
Example #37
0
 public virtual void SetId3v2Tag(ID3v2 id3v2Tag)
 {
     this.id3v2Tag = id3v2Tag;
 }
Example #38
0
 public ID3v2QuickInfo(ID3v2 id3)
 {
     if (id3 == null)
         throw new ArgumentNullException("id3");
     _id3 = id3;
 }