Ejemplo n.º 1
0
        static void Main(string[] args)
        {
            string caminhoPath = @"C:\Users\anogueira\Downloads\Lista\";

            string[] files = Directory.GetFiles(caminhoPath, "*.m3u");


            IList <M3UFile> m3uFiles = new List <M3UFile>();

            foreach (string file in files)
            {
                M3UFile m3u = new M3UFile(file);
                m3uFiles.Add(m3u);
                Console.WriteLine($"Arquivo: {file} Total da lista: {m3u.Count}");
            }

            if (m3uFiles.Count > 0)
            {
                int count = 0;
                foreach (var m3u in m3uFiles)
                {
                    m3u.Save(caminhoPath + count + ".m3u");
                    count++;
                }
            }

            Console.ReadKey();
        }
Ejemplo n.º 2
0
        /// <summary>
        /// load a playlist from a M3U file
        /// </summary>
        private void LoadPlaylistFromFile()
        {
            string lblAudioFileType = rm.GetString("plAudioFilterType");

            using (var ofd = new OpenFileDialog {
                Filter = lblAudioFileType + " (*.m3u)|*.m3u", Title = rm.GetString("openPlDlgTitle")
            })
            {
                if (ofd.ShowDialog() == DialogResult.OK)
                {
                    _m3uFile = null;

                    try
                    {
                        _m3uFile = new M3UFile();
                        _m3uFile.Load(ofd.FileName);
                        //parent.IsPlaylistRunning = true;
                    }
                    catch (Exception)
                    {
                        //parent.IsPlaylistRunning = false;
                        MessageBox.Show("Error loading playlist from file", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }

                    PopulateEntries();
                    if (l.Items.Count > 0)
                    {
                        parent.IsPlaylistRunning = true;
                        lastFileIdx = -1;

                        lblPlistInfo.Text = string.Format("{0} files.",
                                                          l.Items.Count);
                        lblPlistInfo.Visible  = true;
                        this.btnClear.Enabled = true;
                        this.btnSave.Enabled  = true;

                        //PlaylistLoaded(this, null);
                        //lblPlistInfo.Text += string.Format(", Total Time: {0}:{1}",
                        //    (int)totPlaylistTime / 60, (int)totPlaylistTime % 60);
                        //StartPlaying(l.Items[0].Text, 0);
                    }
                    else
                    {
                        lblPlistInfo.Text = string.Format("{0} files.", 0);
                    }
                    PlaylistLoaded(this, null);
                }
            }
        }
Ejemplo n.º 3
0
        public static IEnumerable <IWebSong> Parse(string m3uPlaylistPath)
        {
            if (File.Exists(m3uPlaylistPath))
            {
                var m3uFile       = new M3UFile(new FileInfo(m3uPlaylistPath));
                var m3uMediaItems = m3uFile.Files;

                List <IWebSong> songs = new List <IWebSong>();
                foreach (var item in m3uMediaItems)
                {
                    var lastSong = ParseMediaItem(item);
                    lastSong.Number = songs.Count + 1;
                    songs.Add(lastSong);
                }
                return(songs);
            }
            else
            {
                throw new FileNotFoundException("Указанный m3u - плейлист не существует!");
            }
        }
Ejemplo n.º 4
0
        /// <summary>
        /// save current playlist as a M3U file
        /// </summary>
        private void SaveCurrentPlToFile()
        {
            string lblAudioFileType = rm.GetString("plAudioFilterType");

            using (var sfd = new SaveFileDialog {
                Filter = lblAudioFileType + " (*.m3u)|*.m3u", Title = rm.GetString("savePlDlgTitle")
            })
            {
                sfd.InitialDirectory = "";
                sfd.OverwritePrompt  = true;
                sfd.RestoreDirectory = true;
                if (sfd.ShowDialog() == DialogResult.OK)
                {
                    _m3uFile = null;

                    try
                    {
                        _m3uFile = new M3UFile();
                        foreach (ListViewItem lvItem in l.Items)
                        {
                            /*AudioFileInfo afInfo = new AudioFileInfo(
                             *  Path.GetFileName(lvItem.SubItems[2].Text), lvItem.SubItems[2].Text);
                             * afInfo.SetDuration();*/

                            M3UEntry _m3uEntry = new M3UEntry(TimeSpan.Zero,
                                                              lvItem.SubItems[0].Text,
                                                              new Uri(lvItem.SubItems[2].Text));
                            _m3uFile.Add(_m3uEntry);
                        }
                        // save files into playlist file
                        _m3uFile.Save(sfd.FileName);
                    }
                    catch (Exception)
                    {
                        MessageBox.Show("Error saving playlist to file", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                }
            }
        }
Ejemplo n.º 5
0
        private void btnBrowse_Click(object sender, EventArgs e)
        {
            using (var ofd = new OpenFileDialog {
                Filter = "M3U File (*.m3u)|*.m3u", Title = "Open Playlist"
            })
            {
                if (ofd.ShowDialog() == DialogResult.OK)
                {
                    _m3uFile = null;

                    try
                    {
                        _m3uFile = new M3UFile();
                        _m3uFile.Load(ofd.FileName);
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }

                    PopulateEntries();
                }
            }
        }
Ejemplo n.º 6
0
        static void Main(string[] args)
        {
            //Console.WriteLine("Hello World!");
            string inputFolder  = @"C:\Users\d.egorychev\Music\unsorted";
            string outputFolder = @"C:\Users\d.egorychev\Music\sorted";

            if (args.Length == 2)
            {
                inputFolder  = args[0];
                outputFolder = args[1];
            }
            string[] allfolders = Directory.GetDirectories(inputFolder);
            foreach (string folder in allfolders)
            {
                M3UFile  playlist = new M3UFile(new FileInfo(outputFolder + "\\" + folder.Substring(folder.LastIndexOf('\\')) + ".m3u"));
                string[] AllFiles = Directory.GetFiles(folder, "*.flac", SearchOption.AllDirectories);
                foreach (string filename in AllFiles)
                {
                    var    tfile  = TagLib.File.Create(filename);
                    string artist = "noname_author";
                    if ((tfile.Tag.AlbumArtists[0] != null) || (tfile.Tag.AlbumArtists[0] != ""))
                    {
                        artist = String.Join('-', tfile.Tag.AlbumArtists);
                    }
                    string album = "noname_album";
                    if ((tfile.Tag.Album != null) || (tfile.Tag.Album != ""))
                    {
                        album = tfile.Tag.Album;
                    }

                    string PathDeb = artist + "\\" + album + filename.Substring(filename.LastIndexOf('\\'));
                    foreach (var ch in "~#%&*{}:<>?+|\"")
                    {
                        PathDeb = PathDeb.Replace(ch, '�');
                    }
                    foreach (var ch in new string[] { "...", ".." })
                    {
                        PathDeb = PathDeb.Replace(ch, "�");
                    }
                    FileInfo newPath = new FileInfo(outputFolder + "\\" + PathDeb);

                    Directory.CreateDirectory(newPath.DirectoryName);
                    File.Copy(filename, newPath.FullName, true);

                    MediaItem MI = new MediaItem {
                        Location = PathDeb
                    };
                    playlist.Files.Add(MI);

                    Console.WriteLine(newPath);
                }
                playlist.Save();
            }

            //var tfile = TagLib.File.Create(@"C:\Users\d.egorychev\Music\Nathan Dawe - Flowers (feat. Jaykae).flac");
            //string title = tfile.Tag.Title;
            //TimeSpan duration = tfile.Properties.Duration;
            //Console.WriteLine("Title: {0}, duration: {1}", title, duration);
            Console.WriteLine("Done!");
            Console.ReadLine();
        }