public Form1() { InitializeComponent(); client = new TMDbClient("c6b31d1cdad6a56a23f0c913e2482a31", true); dBVM = new DBVM(); shouldSave = false; }
public Form1() { InitializeComponent(); TMDbClient = new TMDbClient("c6b31d1cdad6a56a23f0c913e2482a31", true); ApiLib = new ApiLib("k_f1ykeqs7"); dBVM = new DBVM(); shouldSave = false; }
private DBVM FetchDB(FileInfo DB) { tb.AppendLine("DB file: " + DB.FullName + ", Exists: " + DB.Exists); dBVM.Movies = new List <Movie>(); dBVM.Collections = new List <Collection>(); dBVM.Locations = new List <Location>(); if (DB.Exists) { tb.AppendLine("Using stored DB"); string json = File.ReadAllText(DB.FullName, Encoding.UTF8); dBVM = JsonConvert.DeserializeObject <DBVM>(json); } else { tb.AppendLine("Creating new DB"); } return(dBVM); }
private async Task Db(string directory) { FileInfo DB = new FileInfo("DB.json"); button1.Enabled = false; checkBox1_poster.Enabled = false; checkBox1_backdrop.Enabled = false; try { dBVM = FetchDB(DB); //Fill Model from DataBase if Exist await FetchConfig(client); string[] extensions = new[] { ".MP4", ".MKV", ".TS" }; var listOfFiles = GetAllFilesByType(directory, extensions); tb.AppendLine(""); tb.AppendLine("found " + listOfFiles.Count.ToString() + " movie in \"" + directory + "\""); tb.AppendLine("---------------------------------------------------------------------------"); foreach (var _movie in listOfFiles) { try { results = new SearchContainer <SearchMovie>(); tb.AppendLine("Searched for movies: '" + Path.GetFileNameWithoutExtension(_movie) + "'"); results = await GetMovieByNameAsync(_movie); if (results.Results.Count > 0) { tb.AppendText(", found " + results.TotalResults + " results in " + results.TotalPages + " pages"); SearchMovie searchMovie = results.Results.FirstOrDefault(); PrintResult(searchMovie); Movie movie = await GetMovieByIdAsync(searchMovie.Id, _movie); if (checkBox1_poster.Checked) { await DownloadDataAsync(movie.PosterPath, client.Config.Images.PosterSizes.ElementAtOrDefault(client.Config.Images.PosterSizes.Count - 2), _movie); } if (checkBox1_backdrop.Checked) { await DownloadDataAsync(movie.BackdropPath, client.Config.Images.BackdropSizes.ElementAtOrDefault(client.Config.Images.BackdropSizes.Count - 2), _movie); } } else { tb.AppendText(", No results found"); } tb.AppendLine(""); tb.AppendLine(""); tb.AppendLine("-----------------------"); } catch (Exception ex) { tb.AppendError(ex.Message); continue; } } } catch (Exception ex) { tb.AppendError(ex.Message, ex.ToString()); } finally { if (shouldSave) { tb.AppendLine("Save Changes"); string json = JsonConvert.SerializeObject(dBVM); File.WriteAllText(DB.FullName, json, Encoding.UTF8); } File.WriteAllText("Log.txt", tb.Text, Encoding.UTF8); MessageBox.Show("Done."); button1.Enabled = true; checkBox1_poster.Enabled = true; checkBox1_backdrop.Enabled = true; } }