예제 #1
0
        public static void ApplyTags(OutputMetadata tagdata, ProgressUpdate procprogress, AudioBookConverterMain _owner)
        {
            if (Owner.bgAACEncoder.CancellationPending)
            {
                return;
            }

            Owner = _owner;
            procprogress.CurrentFilename = "Writing MetaData";
            procprogress.TotalFiles      = 1;
            procprogress.CurrentFile     = 1;
            procprogress.BentoWorking    = true;
            Owner.bgAACEncoder.ReportProgress(0, procprogress);
            TagLib.File Mp4File = TagLib.File.Create(tagdata.OutputFile);

            if (tagdata.Album != null)
            {
                Mp4File.Tag.Album = tagdata.Album;
            }
            if (tagdata.AlbumSort != null)
            {
                Mp4File.Tag.AlbumSort = tagdata.AlbumSort;
            }
            if (tagdata.Composer != null)
            {
                Mp4File.Tag.Composers = tagdata.Composer.Split(';');
            }
            if (tagdata.ComposerSort != null)
            {
                Mp4File.Tag.ComposersSort = tagdata.ComposerSort.Split(';');
            }
            Mp4File.Tag.Disc      = (uint)tagdata.Disc;
            Mp4File.Tag.DiscCount = (uint)tagdata.DiscTotal;
            Mp4File.Tag.Kind      = 2;
            if (tagdata.Artist != null)
            {
                Mp4File.Tag.Performers = tagdata.Artist.Split(';');
            }
            if (tagdata.ArtistSort != null)
            {
                Mp4File.Tag.PerformersSort = tagdata.ArtistSort.Split(';');
            }
            if (tagdata.Title != null)
            {
                Mp4File.Tag.Title = tagdata.Title;
            }
            if (tagdata.TitleSort != null)
            {
                Mp4File.Tag.TitleSort = tagdata.TitleSort;
            }
            Mp4File.Tag.Track = (uint)tagdata.Track;
            Mp4File.Tag.Track = (uint)tagdata.TrackTotal;
            Mp4File.Tag.Year  = (uint)tagdata.Year;
            if (tagdata.Comment != null)
            {
                Mp4File.Tag.Comment = tagdata.Comment;
            }
            if (tagdata.Image != null)
            {
                TagLib.Picture    ipic    = new TagLib.Picture();
                TagLib.ByteVector picdata = new TagLib.ByteVector();

                picdata.Add(tagdata.Image);
                ipic.Data        = picdata;
                ipic.MimeType    = "image/jpeg";
                ipic.Type        = PictureType.FrontCover;
                ipic.Description = "Front Cover";

                Picture[] PictFrames = { ipic };
                Mp4File.Tag.Pictures = PictFrames;
            }
            Mp4File.Save();
        }
예제 #2
0
 public bool StartsWith(ByteVector pattern)
 {
     return(ContainsAt(pattern, 0));
 }
예제 #3
0
        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("=========================================================");
        }
예제 #4
0
 public bool ContainsAt(ByteVector pattern, int offset)
 {
     return(ContainsAt(pattern, offset, 0));
 }
예제 #5
0
 public bool ContainsAt(ByteVector pattern, int offset, int patternOffset)
 {
     return(ContainsAt(pattern, offset, patternOffset, int.MaxValue));
 }
예제 #6
0
 public int RFind(ByteVector pattern)
 {
     return(RFind(pattern, 0, 1));
 }
예제 #7
0
 public int RFind(ByteVector pattern, int offset)
 {
     return(RFind(pattern, offset, 1));
 }
예제 #8
0
 public bool Equals(ByteVector other)
 {
     return(CompareTo(other) == 0);
 }