using System; using System.Text; using System.IO; using System.Windows.Forms; namespace ConvertM3U { class Program { static void Main( string[] args ) { if( args.Length < 1 ) { return; } string path = args[0]; if( File.Exists( path ) ) { string title = "ConvertM3U.exe"; string ext = Path.GetExtension( path ); { if( ext.ToLower() != ".m3u" ) { if( MessageBox.Show( "拡張子が .m3u でないファイルが渡されました。\r\n続行しますか?", title, MessageBoxButtons.OKCancel ) != DialogResult.OK ) { return; } } } string newFilePath; { string dir = Path.GetDirectoryName( path ); string fileName = Path.GetFileNameWithoutExtension( path ); newFilePath = dir + "\\" + fileName + "_" + ext; } string name = Path.GetFileName( path ); string newName = Path.GetFileName( newFilePath ); if( File.Exists( newFilePath ) ) { StringBuilder sb = new StringBuilder(); sb.AppendLine( "ファイルの変換 :" ); sb.Append( name ); sb.Append( " -> " ); sb.AppendLine( newName ); sb.Append( "すでに \"" ); sb.Append( newName ); sb.Append( "\" というファイルが存在しますが、上書きしてよろしいですか?" ); if( MessageBox.Show( sb.ToString(), title, MessageBoxButtons.OKCancel ) != DialogResult.OK ) { return; } } try { Convert( path, newFilePath ); MessageBox.Show( "ファイルの変換完了 : \r\n" + name + " -> " + newName, title ); } catch( Exception ex ) { MessageBox.Show( ex.Message ); } } } internal static void Convert( string path, string newFilePath ) { System.Text.Encoding enc = System.Text.Encoding.Default; string source; using( StreamReader sr = new StreamReader( path, enc ) ) { source = sr.ReadToEnd(); sr.Close(); } using( StreamWriter sw = new StreamWriter( newFilePath, false, enc ) ) { StringReader sr = new StringReader( source ); { M3UConverter.ConvertM3uToS9Format( sr, sw ); } sw.Close(); } } } public static class M3UConverter { public static void ConvertM3uToS9Format( TextReader source, TextWriter output ) { output.WriteLine( "#EXTM3U" ); string line; while( (line = source.ReadLine()) != null ) { if( string.IsNullOrEmpty( line ) ) { continue; } output.WriteLine( "#EXTINF:" ); output.WriteLine( line ); } } } }