Skip to content

Commit

Permalink
Merge pull request #1 from HugoDoyon/master
Browse files Browse the repository at this point in the history
Add option UseCurrentFolderAsPlaylistName to generate playlist name automaticly
  • Loading branch information
sybaris authored Jul 30, 2018
2 parents 75235b4 + cab21a5 commit a1120b7
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 29 deletions.
9 changes: 4 additions & 5 deletions CommandLineArguments.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
using CommandLine;
using CommandLine.Text;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace PlayListGenerator
{
Expand All @@ -26,7 +22,7 @@ internal enum FormatEnum { m3u, xspf }

[Value(0, HelpText = "[drive:][path][filename_or_mask]", Required = true)]
public string PathAndMask { get; set; }
[Value(1, HelpText = "[filename]", Required = true)]
[Value(1, HelpText = "[filename]", Required = false)]
public string PlayListFilename { get; set; }
[Option('S', "SubDirectories", HelpText = "Include subdirectories (recursive)")]
public bool Recursive { get; set; }
Expand All @@ -38,6 +34,9 @@ internal enum FormatEnum { m3u, xspf }
[Option('O', "OnePlaylistByFolder", HelpText = "Create 1 playlist by folder of the current folder")]
public bool OnePlaylistByFolder { get; set; }

[Option('U', "UseCurrentFolderAsPlaylistName", HelpText = "If OnePlaylistByFolder(O) and SubDirectories(S) options selected, then combine this option to use the current folder as PlayListFilename. Usefull to avoid using the same PlayListFilename for all playlist generated")]
public bool UseCurrentFolderAsPlaylistName { get; set; }

[Usage()]
public static IEnumerable<Example> Examples
{
Expand Down
17 changes: 12 additions & 5 deletions GeneratePlaylistBase.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
using System;
using System.Collections.Generic;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace PlayListGenerator
{
Expand All @@ -12,6 +9,16 @@ namespace PlayListGenerator
/// </summary>
internal abstract class GeneratePlaylistBase
{

/// <summary>
/// Return the file extension for the playlist.
/// </summary>
/// <returns></returns>
public abstract string FileExtension
{
get;
}

/// <summary>
/// Method that will be called to generate the playlist file
/// </summary>
Expand All @@ -33,7 +40,7 @@ public virtual void GeneratePlayList(string aPlayListFileName, IEnumerable<strin
fileContent.Append(GetFooter());

// Generate the playlist file
File.WriteAllText(aPlayListFileName, fileContent.ToString());
File.WriteAllText(aPlayListFileName, fileContent.ToString(), Encoding.UTF8);
}

/// <summary>
Expand Down
12 changes: 8 additions & 4 deletions Generate_m3u.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace PlayListGenerator
{
Expand All @@ -12,6 +8,14 @@ namespace PlayListGenerator
class Generate_m3u : GeneratePlaylistBase
{

public override string FileExtension
{
get
{
return "m3u";
}
}

protected override string GetHeader()
{
return "#EXTM3U"+Environment.NewLine;
Expand Down
11 changes: 7 additions & 4 deletions Generate_xspf.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace PlayListGenerator
{
Expand All @@ -11,6 +7,13 @@ namespace PlayListGenerator
/// </summary>
internal class Generate_xspf : GeneratePlaylistBase
{
public override string FileExtension
{
get
{
return "xspf";
}
}

protected override string GetHeader()
{
Expand Down
3 changes: 0 additions & 3 deletions PathHelper.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;

namespace PlayListGenerator
{
Expand Down
22 changes: 14 additions & 8 deletions Program.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
using System;
using CommandLine;
using CommandLine.Text;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using CommandLine;
using System.Diagnostics;
using CommandLine.Text;
using System.IO;
using System.Text.RegularExpressions;
using System.Linq;

namespace PlayListGenerator
{
Expand Down Expand Up @@ -83,7 +80,8 @@ private static SearchOption ConvertToSearchOption(bool aRecursive)
/// </summary>
/// <param name="args"></param>
private static void Run(CommandLineArguments args)
{
{

// Create the file generator
GeneratePlaylistBase playlistGenerator;
switch (args.Format)
Expand All @@ -98,6 +96,8 @@ private static void Run(CommandLineArguments args)
throw new Exception("Unkown playlist format");
}

args.PlayListFilename = string.IsNullOrEmpty(args.PlayListFilename) ? $"default.{playlistGenerator.FileExtension}" : args.PlayListFilename;

// Separate directory and file mask
var dirAndMask = PathHelper.ExtractDirectoryandMask(args.PathAndMask);
string directory = dirAndMask.Item1;
Expand All @@ -120,6 +120,12 @@ private static void Run(CommandLineArguments args)
List<string> directories = new List<string>(Directory.EnumerateDirectories(directory));
foreach (var dir in directories)
{

if (args.UseCurrentFolderAsPlaylistName)
{
args.PlayListFilename = Path.Combine(dir, $"{dir.Split(Path.DirectorySeparatorChar).Last()}.{playlistGenerator.FileExtension}");
}

// Generate playlist of the folder
Run(playlistGenerator, dir, mask, Path.Combine(dir, args.PlayListFilename), args.RelativePath, args.Recursive);
}
Expand Down

0 comments on commit a1120b7

Please sign in to comment.