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
integré savefiledialog et openfiledialog [ par dragstere42 ]
bonjour je viens de faire un lecteur audio et je voudrai serialiser et deserialiser la playlist j'ai fait 2 codes affin de serialiser en .txt et l'au
|
Derniers Blogs
MBA : POURQUOI FAIRE ET COMMENT LE CHOISIR ?MBA : POURQUOI FAIRE ET COMMENT LE CHOISIR ? par ROMELARD Fabrice
Formation initiale Durant la formation, le découpage classique est le suivant (je donnerai les équivalences Suisse lorsque je les connaîtrais) : Ecole primaire jusqu'au Collège : Formation générale permettant d'obtenir les méthodes...
Cliquez pour lire la suite de l'article par ROMELARD Fabrice Y'A DES ERREURS QUI PEUVENT RENDRE LE DéVELOPPEUR VIOLENTY'A DES ERREURS QUI PEUVENT RENDRE LE DéVELOPPEUR VIOLENT par Aleks
Quand on a ce genre d'erreur sans log :
Et bas on a juste envie de choper le gas de Microsoft qu'a développé ça et lui foutre des baffes de Coboye ! ...
Cliquez pour lire la suite de l'article par Aleks [HYPER-V 3] PRéSENTATION DES COMMANDLETS POWERSHELL[HYPER-V 3] PRéSENTATION DES COMMANDLETS POWERSHELL par Pierrick CATRO-BROUILLET
Avec la sortie prochaine de la Beta Consumer Preview de Windows 8, j'avais envie de revenir sur une des fonctionnalités que j'attends le plus et que, en bon geek que je suis, j'utilise déjà : Hyper-V 3 ainsi son module PowerShell.
Il y a déjà pléthor...
Cliquez pour lire la suite de l'article par Pierrick CATRO-BROUILLET IIS7 - COMPRESSION GZIPIIS7 - COMPRESSION GZIP par cyril
La compression GZIP permet d'améliorer les performances de navigation en compressant ce qu'envoie le serveur à un client. Pour comprendre comment cela fonctionne, regardons ce qu'il se passe au niveau HTTP lorsqu'un client tente d'accéder à une ress...
Cliquez pour lire la suite de l'article par cyril SHAREPOINT 15 TECHNICAL PREVIEW MANAGED OBJECT MODEL SOFTWARE DEVELOPMENT KITSHAREPOINT 15 TECHNICAL PREVIEW MANAGED OBJECT MODEL SOFTWARE DEVELOPMENT KIT par Matthew
http://www.microsoft.com/download/en/details.aspx?id=28768&utm_source=feedburner&utm_medium=feed&utm_campaign=Feed%3A+MicrosoftDownloadCenter+(Microsoft+Download+Center) ...
Cliquez pour lire la suite de l'article par Matthew
Logiciels
Easy-Planning (1.0.0.1)EASY-PLANNING (1.0.0.1)Basé sur les mêmes principes que MyPlanning, Easy-Planning permet de créer des plannings sous la ... Cliquez pour télécharger Easy-Planning Academy System (17.1.3.0)ACADEMY SYSTEM (17.1.3.0)Logiciel de gestion des établissements.
- élèves/étudiants (inscription, dossier, absence...)
-... Cliquez pour télécharger Academy System COLLECTOR PLUS (3.00B)COLLECTOR PLUS (3.00B)COLLECTOR PLUS version 3.00B est un logiciel utilisant une base de données alimentée par :
- L... Cliquez pour télécharger COLLECTOR PLUS PONAMEDIA PREMIUM - HELLLOOO FLASH DEMO (V7.4)PONAMEDIA PREMIUM - HELLLOOO FLASH DEMO (V7.4)PONAMEDIA TV DEVIENS HELLLOOO FLASH
LA TV SUR VOTRE ORDINATEUR.
Toute une plateforme Multi... Cliquez pour télécharger PONAMEDIA PREMIUM - HELLLOOO FLASH DEMO LettresFaciles 2011 (8.0.0.1)LETTRESFACILES 2011 (8.0.0.1)LettresFaciles est un logiciel facilitant la création et la rédaction de lettres types.
Son inte... Cliquez pour télécharger LettresFaciles 2011
|