private static void SaveIsCompilation(TagLib.File file, bool is_compilation) { try { var xiph_tag = file.GetTag(TagLib.TagTypes.Xiph, true) as TagLib.Ogg.XiphComment; if (xiph_tag != null) { xiph_tag.IsCompilation = is_compilation; return; } } catch {} try { TagLib.Id3v2.Tag id3v2_tag = file.GetTag(TagLib.TagTypes.Id3v2, true) as TagLib.Id3v2.Tag; if (id3v2_tag != null) { id3v2_tag.IsCompilation = is_compilation; return; } } catch {} try { TagLib.Mpeg4.AppleTag apple_tag = file.GetTag(TagLib.TagTypes.Apple, true) as TagLib.Mpeg4.AppleTag; if (apple_tag != null) { apple_tag.IsCompilation = is_compilation; return; } } catch {} }
private static bool IsCompilation(TagLib.File file) { try { TagLib.Id3v2.Tag id3v2_tag = file.GetTag(TagLib.TagTypes.Id3v2, true) as TagLib.Id3v2.Tag; if (id3v2_tag != null && id3v2_tag.IsCompilation) { return(true); } } catch {} try { TagLib.Mpeg4.AppleTag apple_tag = file.GetTag(TagLib.TagTypes.Apple, true) as TagLib.Mpeg4.AppleTag; if (apple_tag != null && apple_tag.IsCompilation) { return(true); } } catch {} // FIXME the FirstAlbumArtist != FirstPerformer check might return true for half the // tracks on a compilation album, but false for some // TODO checked for 'Soundtrack' (and translated) in the title? if (file.Tag.Performers.Length > 0 && file.Tag.AlbumArtists.Length > 0 && (file.Tag.Performers.Length != file.Tag.AlbumArtists.Length || file.Tag.FirstAlbumArtist != file.Tag.FirstPerformer)) { return(true); } return(false); }
//TagLib.Mpeg4.AppleTag private static string appleCustomTag(TagLib.Mpeg4.AppleTag atags, string key) { var type = atags.GetType(); var mi = type.GetMethod("FixId", BindingFlags.NonPublic | BindingFlags.Static); if (mi is null) { return(null); } var bvKey = new TagLib.ByteVector(key); var aBvKey = mi.Invoke(atags, new object[] { bvKey }) as TagLib.ReadOnlyByteVector; var tag = atags.GetText(aBvKey); if (tag.Length > 1) { var sb = new StringBuilder(); foreach (string s in tag) { if (sb.Length > 0) { sb.Append("; "); } sb.Append(s); } return(sb.ToString()); } else { return(tag.FirstOrDefault()); } }
/// <summary> /// Gets the <see cref="uint" /> from the <see cref="TagLib.Mpeg4.AppleTag" /> using the specified type. /// </summary> /// <param name="appleTag">The apple tag.</param> /// <param name="type">The type.</param> /// <returns>The value.</returns> public static uint GetUInt32(this TagLib.Mpeg4.AppleTag appleTag, TagLib.ReadOnlyByteVector type) { foreach (var item in appleTag.DataBoxes(type)) { if (item.Data.Count == 4) { byte[] data; if (System.BitConverter.IsLittleEndian) { data = new byte[item.Data.Count]; data[0] = item.Data.Data[3]; data[1] = item.Data.Data[2]; data[2] = item.Data.Data[1]; data[3] = item.Data.Data[0]; } else { data = item.Data.Data; } return System.BitConverter.ToUInt32(data); } } return 0u; }
/// <summary>Function to read the various tags from file, if available /// These will be checked in various get functions /// </summary> private void ReadTags() { //currentFile = TagLib.File.Create(FileInfoView.FocusedItem.SubItems[4].Text); id3v1 = currentFile.GetTag(TagLib.TagTypes.Id3v1) as TagLib.Id3v1.Tag; id3v2 = currentFile.GetTag(TagLib.TagTypes.Id3v2) as TagLib.Id3v2.Tag; apple = currentFile.GetTag(TagLib.TagTypes.Apple) as TagLib.Mpeg4.AppleTag; ape = currentFile.GetTag(TagLib.TagTypes.Ape) as TagLib.Ape.Tag; // asf = currentFile.GetTag(TagLib.TagTypes.Asf) as TagLib.Asf.Tag; ogg = currentFile.GetTag(TagLib.TagTypes.Xiph) as TagLib.Ogg.XiphComment; flac = currentFile.GetTag(TagLib.TagTypes.FlacMetadata) as TagLib.Flac.Metadata; }
/// <summary> /// Gets a value indicating whether this <see cref="TagLib.Mpeg4.AppleTag" /> represents a TV show. /// </summary> /// <param name="appleTag">The apple tag.</param> /// <returns><see langword="true" /> if <paramref name="appleTag"/> represents a TV show.</returns> public static bool IsTvShow(this TagLib.Mpeg4.AppleTag appleTag) { foreach (var item in appleTag.DataBoxes(StikAtom)) { if (item.Data.Count == 1) { return item.Data.Data[0] == 10; } } return false; }
/// <summary> /// Gets the tag information from an audio file. /// </summary> /// <param name="fullPath"></param> /// <returns></returns> public Tag OpenTag(string fullPath) { Tag tag = null; try { TagLib.File file = TagLib.File.Create(fullPath); mCurrentTagIsCompilation = false; if ((file.TagTypes & TagTypes.Id3v2) > 0) { TagLib.Id3v2.Tag iTag = (TagLib.Id3v2.Tag)file.GetTag(TagTypes.Id3v2); if (iTag.IsCompilation) { mCurrentTagIsCompilation = true; } return(iTag); } if ((file.TagTypes & TagTypes.Apple) > 0) { TagLib.Mpeg4.AppleTag iTag = (TagLib.Mpeg4.AppleTag)file.GetTag(TagTypes.Apple); if (iTag.IsCompilation) { mCurrentTagIsCompilation = true; } return(iTag); } // If not any of above tags, then try the default create. tag = file.Tag; } catch { return(null); } mCurrentTagIsCompilation = false; return(tag); }
void SetTags(TagLib.Mpeg4.AppleTag tag) { tag.Title = "TEST title"; tag.Performers = new[] { "TEST performer 1", "TEST performer 2" }; tag.Comment = "TEST comment"; tag.Copyright = "TEST copyright"; tag.Genres = new[] { "TEST genre 1", "TEST genre 2" }; tag.Year = 1999; var atag = tag; Assert.IsNotNull(atag); var newbox1 = new TagLib.Mpeg4.AppleDataBox( ByteVector.FromString("TEST Long Description", StringType.UTF8), (int)TagLib.Mpeg4.AppleDataBox.FlagType.ContainsText); var newbox2 = new TagLib.Mpeg4.AppleDataBox( ByteVector.FromString("TEST TV Show", StringType.UTF8), (int)TagLib.Mpeg4.AppleDataBox.FlagType.ContainsText); atag.SetData(BOXTYPE_LDES, new[] { newbox1 }); atag.SetData(BOXTYPE_TVSH, new[] { newbox2 }); }
void CheckTags(TagLib.Mpeg4.AppleTag tag) { Assert.AreEqual("TEST title", tag.Title); Assert.AreEqual("TEST performer 1; TEST performer 2", tag.JoinedPerformers); Assert.AreEqual("TEST comment", tag.Comment); Assert.AreEqual("TEST copyright", tag.Copyright); Assert.AreEqual("TEST genre 1; TEST genre 2", tag.JoinedGenres); Assert.AreEqual(1999, tag.Year); var atag = tag; Assert.IsNotNull(atag); foreach (var adbox in atag.DataBoxes(new[] { BOXTYPE_LDES })) { Assert.AreEqual("TEST Long Description", adbox.Text); } foreach (var adbox in atag.DataBoxes(new[] { BOXTYPE_TVSH })) { Assert.AreEqual("TEST TV Show", adbox.Text); } }
static async Task HandleFile(FileInfo file) { var fileName = Path.GetFileNameWithoutExtension(file.FullName); Console.WriteLine("Processing File: '{0}'", file.FullName); var movies = await SearchForMovie(fileName); Console.WriteLine("Which Movie is this file? (enter -1 to skip)"); var count = 1; foreach (var movie in movies.Results) { Console.WriteLine(" [{0}] {1} - {2} - https://www.themoviedb.org/movie/{3}", count++, GetDateTime(movie.ReleaseDate).Year, movie.Title, movie.Id ); } var movieNumber = -1; var userInput = Console.ReadLine(); int.TryParse(userInput, out movieNumber); var index = movieNumber - 1; if (index < 0 || index > movies.Results.Count() - 1) { Console.WriteLine("Not renaming '{0}'", fileName); } else { var searchMovie = movies.Results.ToArray()[index]; var fullMovie = await GetMovie(searchMovie.Id); using (TagLib.File tagFile = TagLib.File.Create(file.FullName, "video/mp4", ReadStyle.Average)) { TagLib.Mpeg4.AppleTag customTag = (TagLib.Mpeg4.AppleTag)tagFile.GetTag(TagLib.TagTypes.Apple, true); // name customTag.Title = fullMovie.Title; // STIK || Media Type Tag customTag.ClearData("stik"); var stikVector = new TagLib.ByteVector(); stikVector.Add((byte)9); customTag.SetData("stik", stikVector, (int)TagLib.Mpeg4.AppleDataBox.FlagType.ContainsData); // Short Description customTag.ClearData("desc"); customTag.SetText("desc", ToShortDescription(fullMovie.Overview)); // Long Description customTag.ClearData("ldes"); customTag.SetText("ldes", fullMovie.Overview); // Release Date YYYY-MM-DD var releaseDate = GetDateTime(fullMovie.ReleaseDate); customTag.Year = (uint)releaseDate.Year; customTag.ClearData("tdrl"); customTag.SetText("tdrl", fullMovie.Overview); // Genre var mainGenre = fullMovie.Genres.Select(g => g.Name).First(); customTag.Genres = new string[] { mainGenre }; // Cast / Actors customTag.Performers = fullMovie.Credits.Cast.Select(c => c.Name).ToArray(); // HD Video //customTag.ClearData("hdvd"); var inputFile = new MediaFile { Filename = file.FullName }; using (var engine = new Engine()) { engine.GetMetadata(inputFile); } if (isHd(inputFile.Metadata.VideoData.FrameSize)) { var hdvdVector = new TagLib.ByteVector(); hdvdVector.Add(Convert.ToByte(true)); customTag.SetData("hdvd", hdvdVector, (int)TagLib.Mpeg4.AppleDataBox.FlagType.ContainsData); } // Artwork / Poster if (!String.IsNullOrWhiteSpace(fullMovie.Poster)) { Console.WriteLine(" getting movie poster"); var artworkUrl = "http://image.tmdb.org/t/p/original" + fullMovie.Poster; using (var client = new HttpClient()) { var response = await client.GetAsync(artworkUrl); var bytes = await response.Content.ReadAsByteArrayAsync(); tagFile.Tag.Pictures = new IPicture[] { new TagLib.Picture(bytes) }; } } tagFile.Save(); } var newFileName = SanitizeFileName(fullMovie.Title) + Path.GetExtension(file.FullName); var folder = ConfigurationManager.AppSettings["to"]; var newPath = Path.Combine(folder, newFileName); Console.WriteLine(" moving file to {0}", newPath); file.MoveTo(newPath); } Console.WriteLine("========================================================="); }
/// <summary> /// Returns whether the <see cref="TagLib.Mpeg4.AppleTag"/> represents a movie. /// </summary> /// <param name="appleTag">The apple tag.</param> /// <returns><see langword="true"/> if <paramref name="appleTag"/> is a movie; otherwise <see langword="false"/>.</returns> public static bool IsMovie(this TagLib.Mpeg4.AppleTag appleTag) => appleTag.DataBoxes(StikAtom).FirstOrDefault(item => item.Data.Count == 1) is TagLib.Mpeg4.AppleDataBox stikAtom && stikAtom.Data.Data[0] == 9;
private void openFileBtn_Click(object sender, EventArgs e) { filePath.Clear(); textBox.Clear(); OpenFileDialog open_dialog = new OpenFileDialog(); open_dialog.Filter = "Text Documents;Word Docx;PPTX;XLSX;Png;MP4;All |*.txt;*.docx;*pptx;*xlsx;*.png;*mp4;*.*"; if (open_dialog.ShowDialog() == DialogResult.OK) { filePath.Text = open_dialog.FileName; var extension = Path.GetExtension(open_dialog.FileName); switch (extension.ToLower()) { case ".docx": readMeta(open_dialog.FileName); break; case ".xlsx": readMeta(open_dialog.FileName); break; case ".pptx": readMeta(open_dialog.FileName); break; case ".png": string password = "******"; bmp = (Bitmap)Image.FromFile(open_dialog.FileName);; string extractedText = SteganographyHelper.extractText(bmp); extractedText = Crypto.DecryptStringAES(extractedText, password); textBox.Text = extractedText; break; case ".txt": System.Diagnostics.Process pProcess = new System.Diagnostics.Process(); pProcess.StartInfo.UseShellExecute = false; pProcess.StartInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden; //strCommand is path and file name of command to run pProcess.StartInfo.FileName = "cmd.exe"; //strCommandParameters are parameters to pass to program pProcess.StartInfo.Arguments = "/C more < " + open_dialog.FileName + ":DS1"; pProcess.StartInfo.UseShellExecute = false; //Set output of program to be written to process output stream pProcess.StartInfo.RedirectStandardOutput = true; //Optional //pProcess.StartInfo.WorkingDirectory = strWorkingDirectory; //Start the process pProcess.Start(); //Get program output string strOutput = pProcess.StandardOutput.ReadToEnd(); textBox.Text = strOutput; //Wait for process to finish pProcess.WaitForExit(); break; case ".mp4": TagLib.File videoFile = TagLib.File.Create(open_dialog.FileName); TagLib.Mpeg4.AppleTag customTag = (TagLib.Mpeg4.AppleTag)videoFile.GetTag(TagLib.TagTypes.Apple); string tokenValue = customTag.GetDashBox("User", "Downloaded"); textBox.Text = tokenValue; break; } } }