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