Exemplo n.º 1
0
        public Mp3File(FileInfo info)
        {
            this._FileName = info.Name;
            this.FileBytes = System.IO.File.ReadAllBytes(info.FullName);
            this.Mp3       = new Id3.Mp3(this.FileBytes);

            /* Por que no carga los tags de Tu Locura de cerati */
            /* El flag esta en true, pero no hay datos */
            if (this.Mp3.HasTags)
            {
                Id3.Id3Tag[] tags = this.Mp3.GetAllTags().ToArray();
                this.Tag = tags.FirstOrDefault(o => o.Version == Id3.Id3Version.V23) ??
                           tags.FirstOrDefault(o => o.Version == Id3.Id3Version.V1X);
            }
        }
Exemplo n.º 2
0
        public static Image GetMusicPicture(this string MusicPath)
        {
            //List<Image> imgList = new List<Image>();
            string nameMusic = null;

            try
            {
                if (File.Exists(MusicPath))
                {
                    using (var mp3 = new Id3.Mp3(MusicPath))
                    {
                        Id3.Id3Tag tag = mp3.GetTag(Id3.Id3TagFamily.Version2X);
                        if (tag == null)
                        {
                            tag = mp3.GetTag(Id3.Id3TagFamily.Version1X);
                        }
                        if (tag != null)
                        {
                            if (tag.Pictures != null && tag.Pictures.Count > 0)
                            {
                                return(tag.Pictures[0].PictureData.ToImage());
                            }
                            else
                            {
                                nameMusic = tag.Artists;
                            }
                        }
                        //Console.WriteLine("Title: {0}", tag.Title);
                        //Console.WriteLine("艺术家: {0}", tag.Artists);
                        //Console.WriteLine("专辑: {0}", tag.Album);
                    }
                }
            }
            catch
            {
            }

            if (string.IsNullOrEmpty(nameMusic))
            {
                nameMusic = Path.GetFileNameWithoutExtension(MusicPath.ToVideoName());
            }
            return(nameMusic.GetWebMusicPicture());
        }
Exemplo n.º 3
0
        public static int Main(string[] args)
        {
            if (HelpCommandHelper.CheckForHelpParam(args))
            {
                Console.Write(HelpCommandHelper.GetHelpText());
                return(0);
            }

            Uri inputDir  = InputOutputDirectoriesCommandHelper.GetInputUriFromConsoleArgs(args);
            Uri outputDir = InputOutputDirectoriesCommandHelper.GetOutputUriFromConsoleArgs(args);

            if (!Directory.Exists(inputDir.LocalPath))
            {
                Console.WriteLine("Wrong inputDir");
                return(1);
            }
            if (!Directory.Exists(outputDir.LocalPath))
            {
                Directory.CreateDirectory(outputDir.LocalPath);
            }

            List <string> fileNames =
                Directory.GetFiles(inputDir.LocalPath, "*_*", SearchOption.TopDirectoryOnly)
                .Select(Path.GetFileName).ToList();

            Directory.SetCurrentDirectory(inputDir.LocalPath);

            List <string> exceptions    = new List <string>();
            int           numberOfFiles = fileNames.Count;
            int           currentNumber = 0;

            foreach (string name in fileNames)
            {
                try
                {
                    string newName;
                    using (Id3.Mp3 mp3 = new Id3.Mp3(name))
                    {
                        Id3.Id3Tag tag = mp3.GetAllTags().First();
                        newName = Normalize($"{tag.Artists} - {tag.Title}.mp3");
                    }

                    File.Copy(name, newName);

                    string outPath = Path.Combine(outputDir.LocalPath, newName);
                    if (File.Exists(outPath))
                    {
                        outPath = Path.Combine(outputDir.LocalPath, $"{name}.mp3");
                    }

                    Directory.Move(Path.Combine(inputDir.LocalPath, newName), outPath);

                    Console.Clear();
                    Console.WriteLine($"{++currentNumber} / {numberOfFiles}");
                }
                catch (Exception e)
                {
                    exceptions.Add($"{name} - {e.Message}");
                }
            }

            if (exceptions.Any())
            {
                StringBuilder builder = new StringBuilder("Errors, which has occurred during the work");
                foreach (string exception in exceptions)
                {
                    builder.AppendLine(exception);
                }

                Console.WriteLine(builder.ToString());
            }

            Console.WriteLine("Done.");
            return(0);
        }