refacator songcrawler step 1
Signed-off-by: mbrucedogs <mbrucedogs@gmail.com>
This commit is contained in:
parent
c1d2ecafc5
commit
86ffb58df4
@ -27,6 +27,40 @@ namespace SongCrawler
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Helper methods to eliminate duplication
|
||||||
|
private static FireSharp.FirebaseClient CreateFirebaseClient()
|
||||||
|
{
|
||||||
|
IFirebaseConfig config = new FirebaseConfig
|
||||||
|
{
|
||||||
|
AuthSecret = ConfigurationManager.AppSettings["Firebase.Secret"],
|
||||||
|
BasePath = ConfigurationManager.AppSettings["Firebase.Path"]
|
||||||
|
};
|
||||||
|
return new FireSharp.FirebaseClient(config);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static string GetControllerPath(string controller, string pathType)
|
||||||
|
{
|
||||||
|
return string.Format("controllers/{0}/{1}", controller, pathType);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static List<string> GetAllMusicFiles(string songpath)
|
||||||
|
{
|
||||||
|
List<string> files = new List<string>();
|
||||||
|
files.AddRange(FindFiles("mp4", songpath));
|
||||||
|
files.AddRange(FindFiles("mp3", songpath));
|
||||||
|
files.AddRange(FindFiles("zip", songpath));
|
||||||
|
return files;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void ValidateArgs(string[] args, int expectedLength, string usage)
|
||||||
|
{
|
||||||
|
if (args.Length != expectedLength)
|
||||||
|
{
|
||||||
|
Console.WriteLine(usage);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static void Main(string[] args)
|
static void Main(string[] args)
|
||||||
{
|
{
|
||||||
if (args.Count() == 3)
|
if (args.Count() == 3)
|
||||||
@ -44,22 +78,15 @@ namespace SongCrawler
|
|||||||
//string [] test = { "mbrucedogs", "z://" };
|
//string [] test = { "mbrucedogs", "z://" };
|
||||||
//args = test;
|
//args = test;
|
||||||
var debug = false;
|
var debug = false;
|
||||||
if (args.Length != 2)
|
ValidateArgs(args, 2, "usage: songcrawler partyid songspath");
|
||||||
{
|
if (args.Length != 2) return;
|
||||||
Console.WriteLine("usage: songcrawler partyid songspath");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
string controller = args[0];
|
string controller = args[0];
|
||||||
string songpath = args[1];
|
string songpath = args[1];
|
||||||
IFirebaseConfig config = new FirebaseConfig
|
FireSharp.FirebaseClient client = CreateFirebaseClient();
|
||||||
{
|
string songsPath = GetControllerPath(controller, "songs");
|
||||||
AuthSecret = ConfigurationManager.AppSettings["Firebase.Secret"],
|
string favoritesPath = GetControllerPath(controller, "favorites");
|
||||||
BasePath = ConfigurationManager.AppSettings["Firebase.Path"]
|
string disabledPath = GetControllerPath(controller, "disabled");
|
||||||
};
|
|
||||||
FireSharp.FirebaseClient client = new FireSharp.FirebaseClient(config);
|
|
||||||
string songsPath = string.Format("controllers/{0}/songs", controller);
|
|
||||||
string favoritesPath = string.Format("controllers/{0}/favorites", controller);
|
|
||||||
string disabledPath = string.Format("controllers/{0}/disabled", controller);
|
|
||||||
Console.WriteLine("Loading current library");
|
Console.WriteLine("Loading current library");
|
||||||
|
|
||||||
List<Song> songs = null; //client.Get(songsPath).ResultAs<List<Song>>();
|
List<Song> songs = null; //client.Get(songsPath).ResultAs<List<Song>>();
|
||||||
@ -87,10 +114,7 @@ namespace SongCrawler
|
|||||||
|
|
||||||
client.Set(songsPath, songs);
|
client.Set(songsPath, songs);
|
||||||
|
|
||||||
List<string> files = new List<string>();
|
List<string> files = GetAllMusicFiles(songpath);
|
||||||
files.AddRange(FindFiles("mp4", songpath));
|
|
||||||
files.AddRange(FindFiles("mp3", songpath));
|
|
||||||
files.AddRange(FindFiles("zip", songpath));
|
|
||||||
|
|
||||||
Song song = null;
|
Song song = null;
|
||||||
int i = 0;
|
int i = 0;
|
||||||
@ -185,20 +209,13 @@ namespace SongCrawler
|
|||||||
|
|
||||||
private static void DeleteSongs(string[] args)
|
private static void DeleteSongs(string[] args)
|
||||||
{
|
{
|
||||||
if (args.Length != 3)
|
ValidateArgs(args, 3, "usage: songcrawler partyid songspath delete");
|
||||||
{
|
if (args.Length != 3) return;
|
||||||
Console.WriteLine("usage: songcrawler partyid songspath delete");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
string controller = args[0];
|
string controller = args[0];
|
||||||
string songpath = args[1];
|
string songpath = args[1];
|
||||||
IFirebaseConfig config = new FirebaseConfig
|
FireSharp.FirebaseClient client = CreateFirebaseClient();
|
||||||
{
|
string firepath = GetControllerPath(controller, "songs");
|
||||||
AuthSecret = ConfigurationManager.AppSettings["Firebase.Secret"],
|
|
||||||
BasePath = ConfigurationManager.AppSettings["Firebase.Path"]
|
|
||||||
};
|
|
||||||
FireSharp.FirebaseClient client = new FireSharp.FirebaseClient(config);
|
|
||||||
string firepath = string.Format("controllers/{0}/songs", controller);
|
|
||||||
Console.WriteLine("Deleting Songs ...");
|
Console.WriteLine("Deleting Songs ...");
|
||||||
List<Song> songs = new List<Song>();
|
List<Song> songs = new List<Song>();
|
||||||
client.Set(firepath, songs);
|
client.Set(firepath, songs);
|
||||||
@ -207,8 +224,8 @@ namespace SongCrawler
|
|||||||
|
|
||||||
private static void fixNewSongs(FireSharp.FirebaseClient client, String controller)
|
private static void fixNewSongs(FireSharp.FirebaseClient client, String controller)
|
||||||
{
|
{
|
||||||
string songsPath = string.Format("controllers/{0}/songs", controller);
|
string songsPath = GetControllerPath(controller, "songs");
|
||||||
string newSongsPath = string.Format("controllers/{0}/newSongs", controller);
|
string newSongsPath = GetControllerPath(controller, "newSongs");
|
||||||
|
|
||||||
List<Song> songs = client.Get(songsPath).ResultAs<List<Song>>();
|
List<Song> songs = client.Get(songsPath).ResultAs<List<Song>>();
|
||||||
List<Song> newSongs = client.Get(newSongsPath).ResultAs<List<Song>>();
|
List<Song> newSongs = client.Get(newSongsPath).ResultAs<List<Song>>();
|
||||||
@ -226,14 +243,15 @@ namespace SongCrawler
|
|||||||
|
|
||||||
private static void fixHistory(FireSharp.FirebaseClient client, String controller)
|
private static void fixHistory(FireSharp.FirebaseClient client, String controller)
|
||||||
{
|
{
|
||||||
|
string historyPath = GetControllerPath(controller, "history");
|
||||||
List<History> history = null;
|
List<History> history = null;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
history = client.Get(string.Format("controllers/{0}/history", controller)).ResultAs<List<History>>();
|
history = client.Get(historyPath).ResultAs<List<History>>();
|
||||||
}
|
}
|
||||||
catch
|
catch
|
||||||
{
|
{
|
||||||
dynamic data = JsonConvert.DeserializeObject<dynamic>(client.Get(string.Format("controllers/{0}/history", controller)).Body);
|
dynamic data = JsonConvert.DeserializeObject<dynamic>(client.Get(historyPath).Body);
|
||||||
history = new List<History>();
|
history = new List<History>();
|
||||||
foreach (var itemDynamic in data)
|
foreach (var itemDynamic in data)
|
||||||
{
|
{
|
||||||
@ -242,7 +260,7 @@ namespace SongCrawler
|
|||||||
history.Add(f);
|
history.Add(f);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
client.Set(string.Format("controllers/{0}/history", controller), history);
|
client.Set(historyPath, history);
|
||||||
}
|
}
|
||||||
public class CreatedSong
|
public class CreatedSong
|
||||||
{
|
{
|
||||||
@ -258,27 +276,17 @@ namespace SongCrawler
|
|||||||
|
|
||||||
private static void CrawlNoDupeSongs(string[] args)
|
private static void CrawlNoDupeSongs(string[] args)
|
||||||
{
|
{
|
||||||
if (args.Length != 2)
|
ValidateArgs(args, 2, "usage: songcrawler partyid songspath");
|
||||||
{
|
if (args.Length != 2) return;
|
||||||
Console.WriteLine("usage: songcrawler partyid songspath");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
string controller = args[0];
|
string controller = args[0];
|
||||||
string songpath = args[1];
|
string songpath = args[1];
|
||||||
IFirebaseConfig config = new FirebaseConfig
|
FireSharp.FirebaseClient client = CreateFirebaseClient();
|
||||||
{
|
string firepath = GetControllerPath(controller, "songs");
|
||||||
AuthSecret = ConfigurationManager.AppSettings["Firebase.Secret"],
|
|
||||||
BasePath = ConfigurationManager.AppSettings["Firebase.Path"]
|
|
||||||
};
|
|
||||||
FireSharp.FirebaseClient client = new FireSharp.FirebaseClient(config);
|
|
||||||
string firepath = string.Format("controllers/{0}/songs", controller);
|
|
||||||
Console.WriteLine("Loading current library");
|
Console.WriteLine("Loading current library");
|
||||||
List<Song> songs = new List<Song>();
|
List<Song> songs = new List<Song>();
|
||||||
|
|
||||||
List<string> files = new List<string>();
|
List<string> files = GetAllMusicFiles(songpath);
|
||||||
files.AddRange(FindFiles("mp4", songpath));
|
|
||||||
files.AddRange(FindFiles("mp3", songpath));
|
|
||||||
files.AddRange(FindFiles("zip", songpath));
|
|
||||||
|
|
||||||
Song song = null;
|
Song song = null;
|
||||||
int i = 0;
|
int i = 0;
|
||||||
@ -305,10 +313,7 @@ namespace SongCrawler
|
|||||||
string songpath = @"D:\KaraokeData\Karaoke"; // args[0];
|
string songpath = @"D:\KaraokeData\Karaoke"; // args[0];
|
||||||
List<Song> songs = songs = new List<Song>();
|
List<Song> songs = songs = new List<Song>();
|
||||||
|
|
||||||
List<string> files = new List<string>();
|
List<string> files = GetAllMusicFiles(songpath);
|
||||||
files.AddRange(FindFiles("mp3", songpath));
|
|
||||||
files.AddRange(FindFiles("zip", songpath));
|
|
||||||
files.AddRange(FindFiles("mp4", songpath));
|
|
||||||
|
|
||||||
Song song = null;
|
Song song = null;
|
||||||
int i = 0;
|
int i = 0;
|
||||||
@ -352,19 +357,12 @@ namespace SongCrawler
|
|||||||
}
|
}
|
||||||
private static void DisableDuplicates(string[] args)
|
private static void DisableDuplicates(string[] args)
|
||||||
{
|
{
|
||||||
if (args.Length != 1)
|
ValidateArgs(args, 1, "usage: songcrawler partyid songspath");
|
||||||
{
|
if (args.Length != 1) return;
|
||||||
Console.WriteLine("usage: songcrawler partyid songspath");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
string controller = args[0];
|
string controller = args[0];
|
||||||
IFirebaseConfig config = new FirebaseConfig
|
FireSharp.FirebaseClient client = CreateFirebaseClient();
|
||||||
{
|
string firepath = GetControllerPath(controller, "songs");
|
||||||
AuthSecret = ConfigurationManager.AppSettings["Firebase.Secret"],
|
|
||||||
BasePath = ConfigurationManager.AppSettings["Firebase.Path"]
|
|
||||||
};
|
|
||||||
FireSharp.FirebaseClient client = new FireSharp.FirebaseClient(config);
|
|
||||||
string firepath = string.Format("controllers/{0}/songs", controller);
|
|
||||||
Console.WriteLine("Loading current library");
|
Console.WriteLine("Loading current library");
|
||||||
List<Song> songs = client.Get(firepath).ResultAs<List<Song>>();
|
List<Song> songs = client.Get(firepath).ResultAs<List<Song>>();
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user