Accueil > > > GÉNÉRATEUR DE PLAYLIST M3U
GÉNÉRATEUR DE PLAYLIST M3U
Information sur la source
Description
Cet outils permet de générer des playlist en M3U. On précise un répertoire à scanner, un répertoire de sortie et on lance la génération. Le programme va alors scanner récursivement les dossiers et créer un fichier M3U contenant vos fichier musicaux pour chaque dossier trouvé !
Source
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.Text;
- using System.Windows.Forms;
- using System.Diagnostics;
- using System.Threading;
- using System.IO;
-
-
- namespace GenerateurM3U
- {
- public partial class MainForm : Form
- {
- //thread s'occuppant de la génération
- protected internal Thread threadGenerateur;
- //délégué pour update la progress bar
- protected internal delegate void MaJProgressBar(int pourcentage);
- //event de maj progressbar
- protected internal event MaJProgressBar UpdateProgressBar;
- //format playlist (seul M3U implémenté pour l'instant)
- protected internal static FormatPlaylist Format;
- //répertoire à scanner
- protected internal static string Repertoire_a_Scanner;
- //répertoire de sortie
- protected internal static string Repertoire_Sortie;
-
- //enum formt de playlist
- protected internal enum FormatPlaylist
- {
- M3U, WPL
- }
- //liste contenant les formats
- protected internal List<FormatPlaylist> listeFormat;
-
- //constructeur par défaut
- public MainForm()
- {
- try
- {
- InitializeComponent();
- }
- catch (Exception xcp)
- {
- MessageBox.Show(xcp.Message);
- }
- }
-
- /// <summary>
- /// Appelée lors du clic sur le lbl url dans la status strip
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void toolstriplbl_url_Click(object sender, EventArgs e)
- {
- try
- {
- Process.Start("http://www.corioland.eu");
- }
- catch (Exception xcp)
- {
- MessageBox.Show(xcp.Message);
- }
- }
-
- /// <summary>
- /// affiche le curseur "pointeur" lors du survol de l'url
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void toolstriplbl_url_MouseHover(object sender, EventArgs e)
- {
- try
- {
- this.Cursor = Cursors.Hand;
- }
- catch (Exception xcp)
- {
- MessageBox.Show(xcp.Message);
- }
- }
-
- /// <summary>
- /// affiche le curseur par défaut lorsque la souris sort de la zone de l'url
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void toolstriplbl_url_MouseLeave(object sender, EventArgs e)
- {
- try
- {
- this.Cursor = Cursors.Default;
- }
- catch (Exception xcp)
- {
- MessageBox.Show(xcp.Message);
- }
- }
- /// <summary>
- /// méthode appelée au chargement de la form.
- /// initialise la combo box et le folderBrowser.
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void MainForm_Load(object sender, EventArgs e)
- {
- try
- {
- /* OLD
- Cbo_format.Items.Add("M3U");
- //Cbo_format.Items.Add("WPL");
- Cbo_format.SelectedIndex = 0;*/
-
- /* NEW */
- listeFormat = new List<FormatPlaylist>();
- listeFormat.Add(FormatPlaylist.M3U);
- Cbo_format.DataSource = listeFormat;
-
- folderBrowser = new FolderBrowserDialog();
- }
- catch (Exception xcp)
- {
- MessageBox.Show(xcp.Message);
- }
- }
-
- /// <summary>
- /// chois du dossier su le bouton parcourir pour choisir le dossier à scanner
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void btn_parcourir_Click(object sender, EventArgs e)
- {
- try
- {
- if (folderBrowser.ShowDialog() == DialogResult.OK)
- {
- Tb_dossier.Text = folderBrowser.SelectedPath;
- errorProvider.SetError(Tb_dossier, "");
- }
- }
- catch (Exception xcp)
- {
- MessageBox.Show(xcp.Message);
- }
- }
-
- /// <summary>
- /// méthode appelée lors du clic sur le bouton générer.
- /// Vérifie les infos entrées par l'utilisateur
- /// Lance le thread de génération si les infos sont ok!
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void btn_generer_Click(object sender, EventArgs e)
- {
- try
- {
- /* OLD
- switch (Cbo_format.SelectedText)
- {
- case "M3U": Format = FormatPlaylist.M3U;
- break;
- case "WPL": Format = FormatPlaylist.WPL;
- break;
- } */
-
- /* NEW */
- Format = (FormatPlaylist)Cbo_format.SelectedItem;
- bool test = true;
-
- if (Tb_dossier.Text.Trim().Length == 0)
- {
- test = false;
- errorProvider.SetError(Tb_dossier, "Merci de saisir un chemin de fichier à explorer avant de commencer la génération!");
- }
- if (textBox_chemin_gene.Text.Trim().Length == 0)
- {
- test = false;
- errorProvider.SetError(textBox_chemin_gene, "Merci de saisir un chemin de fichier où générer les playlists!");
- }
-
- if (test)
- {
- toolstriplbl_status.Text = "Génération en cours...";
- toolProgressBar.Minimum = 0;
- toolProgressBar.Maximum = 100;
- errorProvider.SetError(Tb_dossier, "");
- Repertoire_a_Scanner = Tb_dossier.Text;
- Repertoire_Sortie = textBox_chemin_gene.Text;
- UpdateProgressBar += new MaJProgressBar(MainForm_UpdateProgressBar);
- threadGenerateur = new Thread(new ThreadStart(GenerePlaylist));
- threadGenerateur.Start();
- }
- }
- catch (Exception xcp)
- {
- MessageBox.Show(xcp.Message);
- }
- }
-
- /// <summary>
- /// Méthode appelée par le délégué de maj de la progress bar.
- /// </summary>
- /// <param name="pourcentage"></param>
- void MainForm_UpdateProgressBar(int pourcentage)
- {
- try
- {
- if (pourcentage != 100)
- {
- toolProgressBar.Value = pourcentage;
- }
- else
- {
- toolProgressBar.Value = pourcentage;
- toolstriplbl_status.Text = "Génération terminée!";
- }
- }
- catch (Exception xcp)
- {
- MessageBox.Show(xcp.Message);
- }
- }
-
- /// <summary>
- /// Méthode appelée par le thread de génération de la playlist
- /// </summary>
- private void GenerePlaylist()
- {
- try
- {
- switch(Format)
- {
- case FormatPlaylist.M3U:
- string[] directories = Directory.GetDirectories(Repertoire_a_Scanner);
- int nbDirectory = directories.Length;
- int count = 0;
- writeM3U(Repertoire_a_Scanner);
- foreach (string directory in directories)
- {
- writeM3U(directory);
- count++;
- int percent = (count * 100) / nbDirectory;
- object[] param = new object[1];
- param[0] = percent;
- Invoke(UpdateProgressBar, param);
- }
- object[] param2 = new object[1];
- param2[0] = 100;
- Invoke(UpdateProgressBar, param2);
- break;
- }
- }
- catch (Exception xcp)
- {
- MessageBox.Show(xcp.Message);
- }
- }
-
- /// <summary>
- /// Méthode chargé de l'écriture du fichier M3U
- /// </summary>
- /// <param name="directory"></param>
- private void writeM3U(string directory)
- {
- try
- {
- string[] files = Directory.GetFiles(directory);
- string[] directories = Directory.GetDirectories(directory);
-
- if (files.Length > 0)
- {
- bool canWrite = false;
- foreach (string file in files)
- {
- string ext = Path.GetExtension(file).ToUpper();
- if (ext == ".MP3" || ext == ".WMA" || ext == ".WAV" || ext == ".OGG")
- {
- canWrite = true;
- }
- }
-
- if (canWrite)
- {
- string directoryName = Path.GetFileName(directory);
- FileStream fs = new FileStream(Repertoire_Sortie + "\\" + directoryName + ".m3u", FileMode.OpenOrCreate);
- StreamWriter writer = new StreamWriter(fs, Encoding.Default);
- writer.WriteLine("#EXTM3U");
- foreach (string file in files)
- {
- string ext = Path.GetExtension(file).ToUpper();
- if (ext == ".MP3" || ext == ".WMA" || ext == ".WAV" || ext == ".OGG")
- {
- writer.WriteLine("#EXTINF:0," + Path.GetFileName(file));
- writer.WriteLine(Path.GetFullPath(file));
- writer.WriteLine();
- }
- }
- writer.Flush();
- writer.Close();
- fs.Close();
- }
-
- foreach (string rep in directories)
- {
- writeM3U(rep);
- }
-
- }
-
- }
- catch (Exception xcp)
- {
- Console.WriteLine(xcp.Message);
- }
- }
-
- /// <summary>
- /// Méthode appelée lors du clic sur le bouton parcourir pour choisir le dossier de sortie des playlists
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void btn_brows_gene_Click(object sender, EventArgs e)
- {
- try
- {
- if (folderBrowser.ShowDialog() == DialogResult.OK)
- {
- textBox_chemin_gene.Text = folderBrowser.SelectedPath;
- errorProvider.SetError(textBox_chemin_gene, "");
- }
- }
- catch (Exception xcp)
- {
- Console.WriteLine(xcp.Message);
- }
- }
-
-
- }
- }
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Diagnostics;
using System.Threading;
using System.IO;
namespace GenerateurM3U
{
public partial class MainForm : Form
{
//thread s'occuppant de la génération
protected internal Thread threadGenerateur;
//délégué pour update la progress bar
protected internal delegate void MaJProgressBar(int pourcentage);
//event de maj progressbar
protected internal event MaJProgressBar UpdateProgressBar;
//format playlist (seul M3U implémenté pour l'instant)
protected internal static FormatPlaylist Format;
//répertoire à scanner
protected internal static string Repertoire_a_Scanner;
//répertoire de sortie
protected internal static string Repertoire_Sortie;
//enum formt de playlist
protected internal enum FormatPlaylist
{
M3U, WPL
}
//liste contenant les formats
protected internal List<FormatPlaylist> listeFormat;
//constructeur par défaut
public MainForm()
{
try
{
InitializeComponent();
}
catch (Exception xcp)
{
MessageBox.Show(xcp.Message);
}
}
/// <summary>
/// Appelée lors du clic sur le lbl url dans la status strip
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void toolstriplbl_url_Click(object sender, EventArgs e)
{
try
{
Process.Start("http://www.corioland.eu");
}
catch (Exception xcp)
{
MessageBox.Show(xcp.Message);
}
}
/// <summary>
/// affiche le curseur "pointeur" lors du survol de l'url
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void toolstriplbl_url_MouseHover(object sender, EventArgs e)
{
try
{
this.Cursor = Cursors.Hand;
}
catch (Exception xcp)
{
MessageBox.Show(xcp.Message);
}
}
/// <summary>
/// affiche le curseur par défaut lorsque la souris sort de la zone de l'url
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void toolstriplbl_url_MouseLeave(object sender, EventArgs e)
{
try
{
this.Cursor = Cursors.Default;
}
catch (Exception xcp)
{
MessageBox.Show(xcp.Message);
}
}
/// <summary>
/// méthode appelée au chargement de la form.
/// initialise la combo box et le folderBrowser.
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void MainForm_Load(object sender, EventArgs e)
{
try
{
/* OLD
Cbo_format.Items.Add("M3U");
//Cbo_format.Items.Add("WPL");
Cbo_format.SelectedIndex = 0;*/
/* NEW */
listeFormat = new List<FormatPlaylist>();
listeFormat.Add(FormatPlaylist.M3U);
Cbo_format.DataSource = listeFormat;
folderBrowser = new FolderBrowserDialog();
}
catch (Exception xcp)
{
MessageBox.Show(xcp.Message);
}
}
/// <summary>
/// chois du dossier su le bouton parcourir pour choisir le dossier à scanner
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void btn_parcourir_Click(object sender, EventArgs e)
{
try
{
if (folderBrowser.ShowDialog() == DialogResult.OK)
{
Tb_dossier.Text = folderBrowser.SelectedPath;
errorProvider.SetError(Tb_dossier, "");
}
}
catch (Exception xcp)
{
MessageBox.Show(xcp.Message);
}
}
/// <summary>
/// méthode appelée lors du clic sur le bouton générer.
/// Vérifie les infos entrées par l'utilisateur
/// Lance le thread de génération si les infos sont ok!
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void btn_generer_Click(object sender, EventArgs e)
{
try
{
/* OLD
switch (Cbo_format.SelectedText)
{
case "M3U": Format = FormatPlaylist.M3U;
break;
case "WPL": Format = FormatPlaylist.WPL;
break;
} */
/* NEW */
Format = (FormatPlaylist)Cbo_format.SelectedItem;
bool test = true;
if (Tb_dossier.Text.Trim().Length == 0)
{
test = false;
errorProvider.SetError(Tb_dossier, "Merci de saisir un chemin de fichier à explorer avant de commencer la génération!");
}
if (textBox_chemin_gene.Text.Trim().Length == 0)
{
test = false;
errorProvider.SetError(textBox_chemin_gene, "Merci de saisir un chemin de fichier où générer les playlists!");
}
if (test)
{
toolstriplbl_status.Text = "Génération en cours...";
toolProgressBar.Minimum = 0;
toolProgressBar.Maximum = 100;
errorProvider.SetError(Tb_dossier, "");
Repertoire_a_Scanner = Tb_dossier.Text;
Repertoire_Sortie = textBox_chemin_gene.Text;
UpdateProgressBar += new MaJProgressBar(MainForm_UpdateProgressBar);
threadGenerateur = new Thread(new ThreadStart(GenerePlaylist));
threadGenerateur.Start();
}
}
catch (Exception xcp)
{
MessageBox.Show(xcp.Message);
}
}
/// <summary>
/// Méthode appelée par le délégué de maj de la progress bar.
/// </summary>
/// <param name="pourcentage"></param>
void MainForm_UpdateProgressBar(int pourcentage)
{
try
{
if (pourcentage != 100)
{
toolProgressBar.Value = pourcentage;
}
else
{
toolProgressBar.Value = pourcentage;
toolstriplbl_status.Text = "Génération terminée!";
}
}
catch (Exception xcp)
{
MessageBox.Show(xcp.Message);
}
}
/// <summary>
/// Méthode appelée par le thread de génération de la playlist
/// </summary>
private void GenerePlaylist()
{
try
{
switch(Format)
{
case FormatPlaylist.M3U:
string[] directories = Directory.GetDirectories(Repertoire_a_Scanner);
int nbDirectory = directories.Length;
int count = 0;
writeM3U(Repertoire_a_Scanner);
foreach (string directory in directories)
{
writeM3U(directory);
count++;
int percent = (count * 100) / nbDirectory;
object[] param = new object[1];
param[0] = percent;
Invoke(UpdateProgressBar, param);
}
object[] param2 = new object[1];
param2[0] = 100;
Invoke(UpdateProgressBar, param2);
break;
}
}
catch (Exception xcp)
{
MessageBox.Show(xcp.Message);
}
}
/// <summary>
/// Méthode chargé de l'écriture du fichier M3U
/// </summary>
/// <param name="directory"></param>
private void writeM3U(string directory)
{
try
{
string[] files = Directory.GetFiles(directory);
string[] directories = Directory.GetDirectories(directory);
if (files.Length > 0)
{
bool canWrite = false;
foreach (string file in files)
{
string ext = Path.GetExtension(file).ToUpper();
if (ext == ".MP3" || ext == ".WMA" || ext == ".WAV" || ext == ".OGG")
{
canWrite = true;
}
}
if (canWrite)
{
string directoryName = Path.GetFileName(directory);
FileStream fs = new FileStream(Repertoire_Sortie + "\\" + directoryName + ".m3u", FileMode.OpenOrCreate);
StreamWriter writer = new StreamWriter(fs, Encoding.Default);
writer.WriteLine("#EXTM3U");
foreach (string file in files)
{
string ext = Path.GetExtension(file).ToUpper();
if (ext == ".MP3" || ext == ".WMA" || ext == ".WAV" || ext == ".OGG")
{
writer.WriteLine("#EXTINF:0," + Path.GetFileName(file));
writer.WriteLine(Path.GetFullPath(file));
writer.WriteLine();
}
}
writer.Flush();
writer.Close();
fs.Close();
}
foreach (string rep in directories)
{
writeM3U(rep);
}
}
}
catch (Exception xcp)
{
Console.WriteLine(xcp.Message);
}
}
/// <summary>
/// Méthode appelée lors du clic sur le bouton parcourir pour choisir le dossier de sortie des playlists
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void btn_brows_gene_Click(object sender, EventArgs e)
{
try
{
if (folderBrowser.ShowDialog() == DialogResult.OK)
{
textBox_chemin_gene.Text = folderBrowser.SelectedPath;
errorProvider.SetError(textBox_chemin_gene, "");
}
}
catch (Exception xcp)
{
Console.WriteLine(xcp.Message);
}
}
}
}
Conclusion
Bref, un outil sans grand exploit technique, mais pratique pour les fénéant comme moi qui n'ont pas envie de Drag n Drop leurs fichiers pour créer leur playlist une par une !
Historique
- 20 octobre 2007 11:44:59 :
- J'ai juste retiré la ligne suivant qui était totalement inutile :
using System.Linq;
- 26 octobre 2007 19:22:15 :
- Ajout des portées des variables de classe.
Mise en place du DataBinding sur la Cbo_Format.
Sources de la même categorie
Commentaires et avis
Discussions en rapport avec ce code source dans le forum
Management Class Generator [ par Ptlpn ]
Pour mon projet actuel, je cherche a lancer depuis mon application des process independants sur des machines distantes. Pour cela, j ai trouve le Mana
Lecteur Mp3 [ par karimprimo ]
Bonjour a tous je suis un gros débutant en c# et je me trouve devant ce problème: j'aimerai savoir comment est ce qu'on s'y prend pour
MP3 player [ par thebigboss ]
Salut,je suis en train de faire un enieme MP3 player tout ce qu'il y'a de plus basique.J'utilise la dll "QuartzTypeLib.dll" et j'arrive à lire, s
pb de thread et freeze du programme [ par greg76301 ]
bonjour , je developpe un media player et lors du chargement de la playlist j'ai souahité utiliser un thread car selon la taille de la playlist
datagridview MouseDown & CellDoubleClick [ par gabs77 ]
Bonjour,je suis sur un projet multimédia et j'ai un souci :j'ai une listbox avec une playlist et un datagridview avec tous les tracks correspondants a
|
Derniers Blogs
PARUTION DE MON LIVRE SUR WPF 4PARUTION DE MON LIVRE SUR WPF 4 par odewit
La 2e édition de mon livre sur WPF sort aujourd'hui en version numérique et lundi en version papier :-)
L'ouvrage présente de façon approfondie les fonctionnalités de WPF 4 : graphisme 2D et 3D, animation, multimédia, interfaces utilisateur, databind...
Cliquez pour lire la suite de l'article par odewit EDM : COMMENT UTILISER L'HORIZONTAL ENTITY SPLITTINGEDM : COMMENT UTILISER L'HORIZONTAL ENTITY SPLITTING par Matthieu MEZIL
Une des raisons pour lesquelles j'adore l'Entity Framework est la puissance de son mapping. Beaucoup de développeurs pour ne pas dire la plus part n'en n'ont pas conscience. Pour rappel, j'ai réalisé des videos (en anglais) sur le mapping . Certains scena...
Cliquez pour lire la suite de l'article par Matthieu MEZIL [WP7DEV][REACTIVE] RENDRE LES REACTIVE EXTENSIONS PLUS STABLES[WP7DEV][REACTIVE] RENDRE LES REACTIVE EXTENSIONS PLUS STABLES par jay
Lorsque l'on développe des applications .NET, les exceptions non gérées dans des threads ont le désagréable effet de terminer le processus courant.
Dans l'exemple suivant.......(read more) ...
Cliquez pour lire la suite de l'article par jay WINDBG / SOS / PSSCOR2 : FAILED TO LOAD DATA ACCESS DLL (MSCORDACWKS)WINDBG / SOS / PSSCOR2 : FAILED TO LOAD DATA ACCESS DLL (MSCORDACWKS) par coq
Ceux d'entre nous qui analysent des dumps d'applications .NET (notamment ceux créés via WER après un crash) en dehors de l'environnement initial ont probablement tous été confrontés au moins une fois au message suivant, à la saisie d'une commande SOS ...
Cliquez pour lire la suite de l'article par coq
Forum
RE : CRéATION DE MODULERE : CRéATION DE MODULE par The Meteorologist
Cliquez pour lire la suite par The Meteorologist
Logiciels
Microsoft Office (2010)MICROSOFT OFFICE (2010)Microsoft Office 2010 offre de nouveaux moyens flexibles et puissants pour optimiser votre travai... Cliquez pour télécharger Microsoft Office SeaMonkey (2.0.7)SEAMONKEY (2.0.7)Le projet SeaMonkey est issu d'un effort communautaire pour developper une application tout en un... Cliquez pour télécharger SeaMonkey Safari (5.0.2)SAFARI (5.0.2)Le navigateur d'Apple a lui aussi été mis à jour, aussi bien dans sa mouture Windows que celle po... Cliquez pour télécharger Safari Mozilla FireFox (4.0 béta 5)MOZILLA FIREFOX (4.0 BéTA 5)Firefox 4.0 béta 5
L'une des nouveautés visibles les plus attendues réside sans doute dans l'a... Cliquez pour télécharger Mozilla FireFox Mozilla Firefox (3.6.9)MOZILLA FIREFOX (3.6.9)Firefox 3.6.9 corrige les problèmes suivants :
* Introduced support for the X-FRAME-OPTION... Cliquez pour télécharger Mozilla Firefox
|