Пример #1
0
 /// <summary>Read specific frame from ID3V2 tag
 /// </summary>
 private string ReadID3V2Tag(string tag)
 {
     TagLib.Id3v2.TextInformationFrame frame = TagLib.Id3v2.TextInformationFrame.Get(id3v2, tag, false);
     if (frame == null)
     {
         return("");
     }
     return(frame.ToString());
 }
Пример #2
0
        /// <summary>For each file retrieve all tag info and store in TagInfo list
        /// </summary>
        private void FillTagInfoStruct(string file)
        {
            TagInfo currentTag = new TagInfo();

            currentTag.Tags        = currentFile.TagTypesOnDisk.ToString();
            currentTag.file        = file;
            currentTag.Artist      = string.Join("; ", currentFile.Tag.Performers);
            currentTag.Title       = currentFile.Tag.Title;
            currentTag.AlbumArtist = string.Join("; ", currentFile.Tag.AlbumArtists); //tagFile.Tag.AlbumArtists.Length == 0 ? "" : tagFile.Tag.AlbumArtists[0];
            currentTag.Album       = currentFile.Tag.Album;
            currentTag.Year        = currentFile.Tag.Year.ToString();

            currentTag.Disc      = currentFile.Tag.Disc == 0 ? "" : currentFile.Tag.Disc.ToString();
            currentTag.DiscTotal = currentFile.Tag.DiscCount == 0 ? "" : currentFile.Tag.DiscCount.ToString();

            currentTag.Genre   = string.Join("; ", currentFile.Tag.Genres);
            currentTag.Bitrate = currentFile.Properties.AudioBitrate;

            currentTag.Duration = currentFile.Properties.Duration.Hours.ToString() + ":" + currentFile.Properties.Duration.Minutes.ToString("0#") + "." + currentFile.Properties.Duration.Seconds.ToString("0#");

            currentTag.BPM = currentFile.Tag.BeatsPerMinute;

            if (id3v2 != null)
            {
                TagLib.Id3v2.TextInformationFrame trackFrame = TagLib.Id3v2.TextInformationFrame.Get(id3v2, "TRCK", false);
                if (trackFrame != null)
                {
                    if (trackFrame.Text[0].Contains("/"))
                    {
                        int nSlash = trackFrame.Text[0].IndexOf("/");
                        currentTag.Track      = trackFrame.Text[0].Substring(0, nSlash);
                        currentTag.TrackTotal = (trackFrame.Text[0].Length > nSlash + 1) ? trackFrame.Text[0].Substring(nSlash + 1) : "";
                    }
                    else
                    {
                        currentTag.Track      = currentFile.Tag.Track == 0 ? "" : currentFile.Tag.Track.ToString();
                        currentTag.TrackTotal = currentFile.Tag.TrackCount == 0 ? "" : currentFile.Tag.TrackCount.ToString();
                    };

                    currentTag.Key       = currentFile.Tag.InitialKey; // ReadID3V2Tag("TKEY");// TagLib.Id3v2.TextInformationFrame.Get(id3v2, "TKEY", false).ToString();
                    currentTag.ISRC      = ReadID3V2Tag("TSRC");       // TagLib.Id3v2.TextInformationFrame.Get(id3v2, "TSRC", false).ToString();
                    currentTag.Publisher = ReadID3V2Tag("TPUB");       // TagLib.Id3v2.TextInformationFrame.Get(id3v2, "TPUB", false).ToString();
                    currentTag.RemixedBy = ReadID3V2Tag("TPE4");       // TagLib.Id3v2.TextInformationFrame.Get(id3v2, "TPE4", false).ToString();
                }
            }

            //            ContainsSeratoData(currentTag);
            IsVBR();

            //            currentTag.ID = fileTags.Count();
            //            fileTags.Add(currentTag);
        }
Пример #3
0
        /// <summary>
        /// Read changed info
        /// </summary>
        /// ToDO: GetInfoFromForm needs to be changed - handled for each field if it's changed
        public void GetInfoFromForm()
        {
            TagLib.File tagFile = mainForm.currentFile;                         // track is the name of the mp3

            editArtist.Text      = string.Join("; ", tagFile.Tag.Performers);   //tagFile.Tag.Performers[0];
            tagFile.Tag.Title    = editTitle.Text;
            editAlbumArtist.Text = string.Join("; ", tagFile.Tag.AlbumArtists); //tagFile.Tag.AlbumArtists.Length == 0 ? "" : tagFile.Tag.AlbumArtists[0];
            tagFile.Tag.Album    = editAlbumTitle.Text;
            editYear.Text        = tagFile.Tag.Year.ToString();

            editDisc.Text      = tagFile.Tag.Disc == 0 ? "" : tagFile.Tag.Disc.ToString();
            editDiscTotal.Text = tagFile.Tag.DiscCount == 0 ? "" : tagFile.Tag.DiscCount.ToString();

            editGenre.Text   = string.Join("; ", tagFile.Tag.Genres);
            editBitrate.Text = tagFile.Properties.AudioBitrate.ToString();

            editDuration.Text = tagFile.Properties.Duration.Hours.ToString() + ":" + tagFile.Properties.Duration.Minutes.ToString("0#") + "." + tagFile.Properties.Duration.Seconds.ToString("0#");

            uint.TryParse(editBPM.Text, out uint BPM);
            tagFile.Tag.BeatsPerMinute = BPM;

            //            editTags.Text = tagFile.TagTypesOnDisk.ToString();

            tagFile.Tag.InitialKey = editKey.Text;
            tagFile.Tag.ISRC       = editISRC.Text;
            tagFile.Tag.Publisher  = editPublisher.Text;
            tagFile.Tag.RemixedBy  = editRemixer.Text;

            editComment.Text = tagFile.Tag.Comment;
            if (mainForm.id3v2 != null)
            {
                TagLib.Id3v2.PlayCountFrame pcf = TagLib.Id3v2.PlayCountFrame.Get(mainForm.id3v2, false);
                editPlaycount.Text = pcf == null ? "" : pcf.ToString();

                TagLib.Id3v2.TextInformationFrame trackFrame = TagLib.Id3v2.TextInformationFrame.Get(mainForm.id3v2, "TRCK", false);
                if (trackFrame != null)
                {
                    if (trackFrame.Text[0].Contains("/"))
                    {
                        int nSlash = trackFrame.Text[0].IndexOf("/");
                        editTrack.Text      = trackFrame.Text[0].Substring(0, nSlash);
                        editTrackTotal.Text = (trackFrame.Text[0].Length > nSlash + 1) ? trackFrame.Text[0].Substring(nSlash + 1) : "";
                    }
                    else
                    {
                        editTrack.Text      = tagFile.Tag.Track == 0 ? "" : tagFile.Tag.Track.ToString();
                        editTrackTotal.Text = tagFile.Tag.TrackCount == 0 ? "" : tagFile.Tag.TrackCount.ToString();
                    };
                }
            }
        }
Пример #4
0
        /// <summary>
        ///  insert / update a song in database
        /// </summary>
        /// <param name="tag">id3 tag</param>
        /// <param name="tag_file">id3 tag file</param>
        /// <param name="art_id">sql art id</param>
        /// <param name="artist_id">sql artist id</param>
        /// <param name="album_id">sql album id</param>
        private object InsertSong(
            TagLib.Tag tag, TagLib.File tag_file, string art_id, object artist_id, object album_id)
        {
            // format the timespane (H:M:SS)
            TimeSpan      ts     = tag_file.Properties.Duration;
            string        h      = ts.Hours != 0 ? ts.Hours.ToString() + ":" : "";
            string        m      = ts.Minutes != 0 ? ts.Minutes.ToString() : "0";
            string        s      = ts.Seconds < 10 ? "0" + ts.Seconds.ToString() : ts.Seconds.ToString();
            StringBuilder length = new StringBuilder(h + m + ":" + s);
            StringBuilder file   = new StringBuilder(tag_file.Name);
            StringBuilder lyrics = ((tag.Lyrics != null) && (tag.Lyrics != string.Empty)) ?
                                   new StringBuilder(tag.Lyrics) : null;

            // change path to unix style
            file.Remove(0, 2);
            file.Replace('\\', '/');
            object       song_id = GetKey("song", "file", file.ToString());
            MySqlCommand cmd     = new MySqlCommand();

            cmd.Parameters.AddWithValue("?artist_id", artist_id);
            cmd.Parameters.AddWithValue("?album_id", album_id);
            cmd.Parameters.AddWithValue("?track", tag.Track);
            cmd.Parameters.AddWithValue("?title", tag.Title);
            cmd.Parameters.AddWithValue("?file", file);
            cmd.Parameters.AddWithValue("?genre", tag.FirstGenre);
            cmd.Parameters.AddWithValue("?bitrate", tag_file.Properties.AudioBitrate.ToString());
            cmd.Parameters.AddWithValue("?length", length);
            // (MySql Year) the allowable values are 1901 to 2155, and 0000
            string year = (tag.Year == 0000 || (tag.Year > 1900 && tag.Year < 2155)) ? tag.Year.ToString() : "0000";

            cmd.Parameters.AddWithValue("?year", year);
            cmd.Parameters.AddWithValue("?comments", tag.Comment);
            TagLib.Id3v2.Tag idv2 = null;
            try
            {
                idv2 = tag_file.GetTag(TagLib.TagTypes.Id3v2) as TagLib.Id3v2.Tag;
            }
            catch (Exception e)
            {
                // taglib throws an exception on some file types?
                OnError(e.Message);
            }
            string encoder = "NA";

            if (idv2 != null)
            {
                TagLib.Id3v2.TextInformationFrame frame =
                    TagLib.Id3v2.TextInformationFrame.Get((TagLib.Id3v2.Tag)idv2, "TSSE", false);
                encoder = frame != null && frame.Text.Length > 0 ? frame.Text[0] : "Unknown";
            }
            cmd.Parameters.AddWithValue("?encoder", encoder);
            cmd.Parameters.AddWithValue("?file_size", tag_file.Length.ToString());
            cmd.Parameters.AddWithValue("?file_type", tag_file.MimeType);
            cmd.Parameters.AddWithValue("?art_id", art_id);
            cmd.Parameters.AddWithValue("?lyrics", lyrics);
            cmd.Parameters.AddWithValue("?composer", tag.FirstComposer);
            cmd.Parameters.AddWithValue("?conductor", tag.Conductor);
            cmd.Parameters.AddWithValue("?copyright", tag.Copyright);
            cmd.Parameters.AddWithValue("?disc", tag.Disc);
            cmd.Parameters.AddWithValue("?disc_count", tag.DiscCount);
            cmd.Parameters.AddWithValue("?performer", tag.FirstPerformer);
            cmd.Parameters.AddWithValue("?tag_types", tag.TagTypes.ToString());
            cmd.Parameters.AddWithValue("?track_count", tag.TrackCount);
            cmd.Parameters.AddWithValue("?beats_per_minute", tag.BeatsPerMinute);
            cmd.Parameters.AddWithValue("?song_id", song_id);
            byte[] sha1 = null;
            if (Settings.Default.compute_sha1)
            {
                sha1 = TagLibExt.MediaSHA1(tag_file);
                string hex = Utility.Functions.Bytes2HexString(sha1);
                Trace.WriteLine("SHA1 - " + hex, Logger.Level.Information.ToString());
            }
            cmd.Parameters.AddWithValue("?sha1", sha1);
            string sql = string.Empty;

            if (song_id == null)
            {
                sql = "INSERT INTO song (artist_id, album_id, track, title, file, genre, bitrate, length, year, comments, " +
                      "encoder, file_size, file_type, art_id, lyrics, composer, conductor, copyright, " +
                      "disc, disc_count, performer, tag_types, track_count, beats_per_minute, sha1) VALUES(" +
                      "?artist_id, ?album_id, ?track, ?title, ?file, ?genre, ?bitrate, ?length, ?year, ?comments, " +
                      "?encoder, ?file_size, ?file_type, ?art_id, ?lyrics, ?composer, ?conductor, ?copyright, " +
                      "?disc, ?disc_count, ?performer, ?tag_types, ?track_count, ?beats_per_minute, ?sha1)";
                OnMessage("INSERTED SONG: " + Path.GetFileName(tag_file.Name));
                cmd.CommandText = sql;
                mysql_connection.ExecuteNonQuery(cmd);
                song_id = mysql_connection.LastInsertID;
                reporter.InsertSongCount++;
            }
            else
            {
                sql = "UPDATE song SET artist_id=?artist_id, album_id=?album_id, track=?track, title=?title, file=?file, genre=?genre, " +
                      "bitrate=?bitrate, length=?length, year=?year, comments=?comments, encoder=?encoder, file_size=?file_size, file_type=?file_type, " +
                      "art_id=?art_id, lyrics=?lyrics, composer=?composer, conductor=?conductor, copyright=?copyright, disc=?disc, disc_count=?disc_count, " +
                      "performer=?performer, tag_types=?tag_types, track_count=?track_count, beats_per_minute=?beats_per_minute, sha1=?sha1 " +
                      "WHERE id = ?song_id";
                OnMessage("UPDATED SONG: " + Path.GetFileName(tag_file.Name));
                cmd.CommandText = sql;
                mysql_connection.ExecuteNonQuery(cmd);
                reporter.UpdateSongCount++;
            }
            return(song_id);
        }
Пример #5
0
        public void SetMp3FileTags(string fileName, ISermon sermon)
        {
            if (!string.IsNullOrEmpty(fileName))
                return;

            if (sermon.RecordingDate.HasValue)
            {
                var mp3File = TagLib.File.Create(HttpContext.Current.Server.MapPath(fileName));

                mp3File.Tag.Clear();
                mp3File.Tag.Album = sermon.RecordingSession;
                mp3File.Tag.AlbumArtists = new[] { sermon.SpeakerName };
                mp3File.Tag.Comment = "Providence Presbyterian Church - " + sermon.RecordingDate.Value.ToShortDateString() + " - " + sermon.RecordingSession;
                mp3File.Tag.Genres = new[] { "Speech" };
                mp3File.Tag.Title = sermon.Title;
                mp3File.Tag.Year = (uint)sermon.RecordingDate.Value.Year;
                mp3File.Tag.Copyright = "Providence Presbyterian Church - " + sermon.RecordingDate.Value.Year;

                var id3v2Tags = (TagLib.Id3v2.Tag)mp3File.GetTag(TagLib.TagTypes.Id3v2);

                // The 'Official artist/performer webpage' frame is a URL pointing at the artists official webpage.
                id3v2Tags.RemoveFrames("WOAR");
                var frame = new TagLib.Id3v2.UnknownFrame("WOAR");
                frame.Data = Encoding.ASCII.GetBytes("www.providence-pca.net");
                id3v2Tags.AddFrame(frame);

                // The 'Official audio file webpage' frame is a URL pointing at a file specific webpage.
                id3v2Tags.RemoveFrames("WOAF");
                frame = new TagLib.Id3v2.UnknownFrame("WOAF");
                frame.Data = Encoding.ASCII.GetBytes(sermon.SermonUrl);
                id3v2Tags.AddFrame(frame);

                // Sub title
                id3v2Tags.RemoveFrames("TIT3");
                var textFrame = new TagLib.Id3v2.TextInformationFrame("TIT3", TagLib.StringType.Latin1);
                textFrame.Text = new[] { sermon.ScriptureReference.ToString() };
                id3v2Tags.AddFrame(textFrame);
            }
        }
Пример #6
0
        // ID3v2 Tags Reference: http://id3.org/id3v2.4.0-frames
        /// <summary>
        /// Full TagDetailInfoForm with information from the currently selected file
        /// </summary>
        public void SetInfoToForm()
        {
            try
            {
                TagLib.File tagFile = mainForm.currentFile;                         // track is the name of the mp3

                editArtist.Text      = string.Join("; ", tagFile.Tag.Performers);   //tagFile.Tag.Performers[0];
                editTitle.Text       = tagFile.Tag.Title;
                editAlbumArtist.Text = string.Join("; ", tagFile.Tag.AlbumArtists); //tagFile.Tag.AlbumArtists.Length == 0 ? "" : tagFile.Tag.AlbumArtists[0];
                editAlbumTitle.Text  = tagFile.Tag.Album;
                editYear.Text        = tagFile.Tag.Year.ToString();

                editDisc.Text      = tagFile.Tag.Disc == 0 ? "" : tagFile.Tag.Disc.ToString();
                editDiscTotal.Text = tagFile.Tag.DiscCount == 0 ? "" : tagFile.Tag.DiscCount.ToString();

                editGenre.Text   = string.Join("; ", tagFile.Tag.Genres);
                editBitrate.Text = tagFile.Properties.AudioBitrate.ToString();

                editDuration.Text = tagFile.Properties.Duration.Hours.ToString() + ":" + tagFile.Properties.Duration.Minutes.ToString("0#") + "." + tagFile.Properties.Duration.Seconds.ToString("0#");

                editBPM.Text = tagFile.Tag.BeatsPerMinute.ToString();

                editTags.Text = tagFile.TagTypesOnDisk.ToString();

                editKey.Text       = tagFile.Tag.InitialKey;
                editISRC.Text      = tagFile.Tag.ISRC;
                editPublisher.Text = tagFile.Tag.Publisher;
                editRemixer.Text   = tagFile.Tag.RemixedBy;

                editComment.Text = tagFile.Tag.Comment;
                if (mainForm.id3v2 != null)
                {
                    TagLib.Id3v2.PlayCountFrame pcf = TagLib.Id3v2.PlayCountFrame.Get(mainForm.id3v2, false);
                    editPlaycount.Text = pcf == null ? "" : pcf.ToString();

                    TagLib.Id3v2.TextInformationFrame trackFrame = TagLib.Id3v2.TextInformationFrame.Get(mainForm.id3v2, "TRCK", false);
                    if (trackFrame != null)
                    {
                        if (trackFrame.Text[0].Contains("/"))
                        {
                            int nSlash = trackFrame.Text[0].IndexOf("/");
                            editTrack.Text      = trackFrame.Text[0].Substring(0, nSlash);
                            editTrackTotal.Text = (trackFrame.Text[0].Length > nSlash + 1) ? trackFrame.Text[0].Substring(nSlash + 1) : "";
                        }
                        else
                        {
                            editTrack.Text      = tagFile.Tag.Track == 0 ? "" : tagFile.Tag.Track.ToString();
                            editTrackTotal.Text = tagFile.Tag.TrackCount == 0 ? "" : tagFile.Tag.TrackCount.ToString();
                        };

                        //                    editKey.Text = ReadID3V2Tag("TKEY");// TagLib.Id3v2.TextInformationFrame.Get(id3v2, "TKEY", false).ToString();
                        //                    editISRC.Text = ReadID3V2Tag("TSRC");// TagLib.Id3v2.TextInformationFrame.Get(id3v2, "TSRC", false).ToString();
                        //                    editPublisher.Text = ReadID3V2Tag("TPUB");// TagLib.Id3v2.TextInformationFrame.Get(id3v2, "TPUB", false).ToString();
                        //                    editRemixer.Text = ReadID3V2Tag("TPE4");// TagLib.Id3v2.TextInformationFrame.Get(id3v2, "TPE4", false).ToString();
                    }
                }
                else
                {
                    editTrack.Text      = tagFile.Tag.Track.ToString();
                    editTrackTotal.Text = tagFile.Tag.TrackCount.ToString();
                }

                if (mainForm.serato.ContainsSeratoData())
                {
                    if (mainForm.serato.serato_struct.seratoAnalysis.raw.Length > 0)
                    {
                        //ToDo: Is able to get here when raw data is just zeroes
                        editSeratoAnalysis.Text = string.Empty;
                        for (int i = 0; i < mainForm.serato.serato_struct.seratoAnalysis.raw.Length; i++)
                        {
                            if (mainForm.serato.serato_struct.seratoAnalysis.raw[i] > 0)
                            {
                                if (i > 0)
                                {
                                    editSeratoAnalysis.Text += ".";
                                }
                                editSeratoAnalysis.Text += mainForm.serato.serato_struct.seratoAnalysis.raw[i].ToString();
                            }
                        }
                    }
                    else
                    {
                        editSeratoAnalysis.Text = "Field not available";
                    }

                    if (!string.IsNullOrEmpty(mainForm.serato.serato_struct.seratoAutotags.data))
                    {
                        editSeratoAutotags.Text = "BPM: " + mainForm.serato.serato_struct.BPM + " - tag2: " + mainForm.serato.serato_struct.tag2 + " - tag3: " + mainForm.serato.serato_struct.tag3;
                    }
                    else
                    {
                        editSeratoAutotags.Text = "Field not available";
                    }
                    string Markers = string.Empty;
                    if (mainForm.serato.serato_struct.HighestMarker > 0)
                    {
                        Markers += mainForm.serato.serato_struct.HighestMarker + " Cues ";
                        string CueNames = string.Empty;
                        for (int i = 0; i < 8; i++)
                        {
                            if (mainForm.serato.serato_struct.Cues[i].Name != string.Empty)
                            {
                                if (CueNames.Length > 0)
                                {
                                    CueNames += "; ";
                                }
                                else
                                {
                                    CueNames += "(";
                                }
                                CueNames += mainForm.serato.serato_struct.Cues[i].Name;
                            }
                        }
                        if (CueNames.Length > 1)
                        {
                            Markers += CueNames + ")";
                        }
                        editSeratoCue1.Text      = mainForm.serato.serato_struct.Cues[0].Name;
                        editSeratoCue1.BackColor = mainForm.serato.serato_struct.Cues[0].color;
                    }
                    if (mainForm.serato.serato_struct.HighestLoop > 0)
                    {
                        if (Markers.Length > 0)
                        {
                            Markers += "; ";
                        }
                        Markers += mainForm.serato.serato_struct.HighestLoop + " Loops ";
                        string LoopNames = string.Empty;
                        for (int i = 0; i < 4; i++)
                        {
                            if (mainForm.serato.serato_struct.loops[i].Name != string.Empty)
                            {
                                if (LoopNames.Length > 0)
                                {
                                    LoopNames += "; ";
                                }
                                else
                                {
                                    LoopNames += "(";
                                }
                                LoopNames += mainForm.serato.serato_struct.loops[i].Name;
                            }
                        }
                        if (LoopNames.Length > 1)
                        {
                            Markers += LoopNames + ")";
                        }
                    }
                    editSeratoMarkers.Text = Markers;
                    editSeratoBPMLock.Text = mainForm.serato.serato_struct.BPMLock == 0 ? "Off" : "On";
                }
                else
                {
                    editSeratoMarkers.Text  = "Field not available";
                    editSeratoAutotags.Text = "Field not available";
                }

                //            editGenre.Text = tagFile.Tag.Genres[0];
                //            foreach (CommentFrame comment in id3Tag.Comments)
                //                textBox_Comments.Text += comment.Comment + "\n";

                //if( mainFrm.ContainsSeratoData() )
                //    checkSerato.CheckState = CheckState.Checked;
                //else
                //    checkSerato.CheckState = CheckState.Unchecked;

                pictureBoxPreview.Image = null;
                if (tagFile.Tag.Pictures.Length >= 1)
                {
                    for (int i = 0; i < tagFile.Tag.Pictures.Length; i++)
                    {
                        var bin = (byte[])(tagFile.Tag.Pictures[i].Data.Data);
                        //                pictureBoxPreview.Image = Image.FromStream(new MemoryStream(bin)).GetThumbnailImage(100, 100, null, IntPtr.Zero);
                        try
                        {
                            pictureBoxPreview.Image = Image.FromStream(new MemoryStream(bin));
                            break;
                        }
                        catch (ArgumentException)
                        {
                        }
                    }
                }
                //TagLib.Id3v2.TextInformationFrame test = tagFile.TagTypes
            }
            catch (Exception e)
            {
            }
        }