Ejemplo n.º 1
0
        /// <summary>
        /// Handles the DoWork event of the bgw control.
        /// </summary>
        /// <param name="sender">
        /// The source of the event.
        /// </param>
        /// <param name="e">
        /// The <see cref="System.ComponentModel.DoWorkEventArgs"/> instance containing the event data.
        /// </param>
        private static void bgwSaveMovieDBWork_DoWork(object sender, DoWorkEventArgs e)
        {
            string path = Get.FileSystemPaths.PathDatabases + OutputName.MovieDb + Path.DirectorySeparatorChar;

            var movieModel = e.Argument as MovieModel;

            string title = FileNaming.RemoveIllegalChars(movieModel.Title);

            string writePath = path + title + ".movie";

            bool writeText   = false;
            bool writeImages = false;

            if (!movieModel.DatabaseSaved)
            {
                writeImages = true;
            }

            if (!movieModel.DatabaseSaved || movieModel.ChangedText)
            {
                writeText = true;
            }

            if (writeText)
            {
                movieModel.DatabaseSaved = true;
                string json = JsonConvert.SerializeObject(movieModel);
                Gzip.CompressString(json, writePath + ".gz");
            }

            var posterPath = path + title + ".poster.jpg";
            var fanartPath = path + title + ".fanart.jpg";

            if (movieModel.SmallPoster != null && (movieModel.ChangedPoster || writeImages))
            {
                movieModel.SmallPoster.Save(posterPath);
            }

            if (movieModel.SmallFanart != null && (movieModel.ChangedFanart || writeImages))
            {
                movieModel.SmallFanart.Save(fanartPath);
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Loads the TV DB db
        /// </summary>
        private static void LoadTvDB()
        {
            string path = Get.FileSystemPaths.PathDatabases + OutputName.TvDb + Path.DirectorySeparatorChar;

            Directory.CreateDirectory(path);

            var files = FileHelper.GetFilesRecursive(path, "*.Series.gz");

            TvDBFactory.TvDatabase.Clear();

            foreach (var file in files)
            {
                string json = Gzip.Decompress(file);

                var series = JsonConvert.DeserializeObject(json, typeof(Series)) as Series;

                string title = FileNaming.RemoveIllegalChars(series.SeriesName);

                string poster = path + title + ".poster.jpg";
                string fanart = path + title + ".fanart.jpg";
                string banner = path + title + ".banner.jpg";

                if (File.Exists(poster))
                {
                    series.SmallPoster = ImageHandler.LoadImage(poster);
                }

                if (File.Exists(fanart))
                {
                    series.SmallFanart = ImageHandler.LoadImage(fanart);
                }

                if (File.Exists(banner))
                {
                    series.SmallBanner = ImageHandler.LoadImage(banner);
                }

                TvDBFactory.TvDatabase.Add(series.SeriesName, series);
            }

            TvDBFactory.GeneratePictureGallery();
            TvDBFactory.GenerateMasterSeriesList();
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Handles the DoWork event of the bgw control.
        /// </summary>
        /// <param name="sender">
        /// The source of the event.
        /// </param>
        /// <param name="e">
        /// The <see cref="System.ComponentModel.DoWorkEventArgs"/> instance containing the event data.
        /// </param>
        private static void bgw_DoWork(object sender, DoWorkEventArgs e)
        {
            string path = Get.FileSystemPaths.PathDatabases + OutputName.MovieDb + Path.DirectorySeparatorChar;

            var movieModel = e.Argument as MovieModel;

            string title = FileNaming.RemoveIllegalChars(movieModel.Title);

            string writePath = path + title + ".movie";
            string json      = JsonConvert.SerializeObject(movieModel);

            Gzip.CompressString(json, writePath + ".gz");

            if (movieModel.SmallPoster != null)
            {
                movieModel.SmallPoster.Save(path + title + ".poster.jpg");
            }

            if (movieModel.SmallFanart != null)
            {
                movieModel.SmallFanart.Save(path + title + ".fanart.jpg");
            }
        }
Ejemplo n.º 4
0
        private static void SaveMovies(BindingList <MovieModel> database)
        {
            int max = database.Count;

            if (max == 0)
            {
                return;
            }

            SavingMovieMax += database.Count - 1;
            var parallelOptions = new ParallelOptions {
                MaxDegreeOfParallelism = 6
            };

            Parallel.ForEach(
                database,
                parallelOptions,
                movie =>
            {
                SavingCount++;

                var path = Get.FileSystemPaths.PathDatabases + OutputName.MovieDb + Path.DirectorySeparatorChar;

                var title = FileNaming.RemoveIllegalChars(movie.Title);

                string writePath;

                if (movie.Hidden)
                {
                    writePath = path + title + ".hiddenmovie";
                }
                else
                {
                    writePath = path + title + ".movie";
                }

                movie.DatabaseSaved = true;
                var json            = JsonConvert.SerializeObject(movie);
                Gzip.CompressString(json, writePath + ".gz");

                var posterPath = path + title + ".poster.jpg";
                var fanartPath = path + title + ".fanart.jpg";

                if (movie.SmallPoster != null)
                {
                    movie.SmallPoster.Save(posterPath);
                }

                if (movie.SmallFanart != null)
                {
                    movie.SmallFanart.Save(fanartPath);
                }

                Application.DoEvents();

                SavingMovieValue++;
            });

            frmSavingDB.MovieDBFinished();

            SavingMovieDB = false;
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Loads the TV DB db
        /// </summary>
        private static void LoadTvDB()
        {
            string path = Get.FileSystemPaths.PathDatabases + OutputName.TvDb + Path.DirectorySeparatorChar;

            Directory.CreateDirectory(path);

            List <string> files = FileHelper.GetFilesRecursive(path, "*.Series.gz");

            TvDBFactory.TvDatabase.Clear();

            var hidden = path + "hidden.hiddenSeries.gz";

            if (File.Exists(hidden))
            {
                var json = Gzip.Decompress(hidden);
                TvDBFactory.HiddenTvDatabase =
                    JsonConvert.DeserializeObject(json, typeof(BindingList <Series>)) as BindingList <Series>;
            }

            var parallelOptions = new ParallelOptions {
                MaxDegreeOfParallelism = 6
            };

            Parallel.ForEach(
                files,
                parallelOptions,
                file =>
            {
                var json = Gzip.Decompress(file);

                var series = JsonConvert.DeserializeObject(json, typeof(Series)) as Series;

                string title = FileNaming.RemoveIllegalChars(series.SeriesName);

                string poster = path + title + ".poster.jpg";
                string fanart = path + title + ".fanart.jpg";
                string banner = path + title + ".banner.jpg";

                if (File.Exists(poster))
                {
                    series.SmallPoster = ImageHandler.LoadImage(poster);
                }

                if (File.Exists(fanart))
                {
                    series.SmallFanart = ImageHandler.LoadImage(fanart);
                }

                if (File.Exists(banner))
                {
                    series.SmallBanner = ImageHandler.LoadImage(banner);
                }

                foreach (var season in series.Seasons)
                {
                    for (int index = 0; index < season.Value.Episodes.Count; index++)
                    {
                        var episode = season.Value.Episodes[index];
                        if (episode.FilePath.PathAndFilename != string.Empty &&
                            !File.Exists(episode.FilePath.PathAndFilename))
                        {
                            Log.WriteToLog(
                                LogSeverity.Info,
                                LoggerName.GeneralLog,
                                "Internal > DatabaseIOFactory > LoadTvDB",
                                string.Format(
                                    "Deleting {0}. Episode not found on the filesystem",
                                    episode.FilePath.PathAndFilename));
                            // We should check for network path and make sure the file has actually been deleted or removed
                            File.Delete(file);
                            series.Seasons[season.Key].Episodes.Remove(episode);
                        }
                    }
                }

                lock (TvDBFactory.TvDatabase)
                {
                    TvDBFactory.TvDatabase.Add(series.SeriesName, series);
                }
            });

            TvDBFactory.GeneratePictureGallery();
            TvDBFactory.GenerateMasterSeriesList();
        }
Ejemplo n.º 6
0
        private static void LoadMovies(string path, string[] files, BindingList <MovieModel> database)
        {
            var parallelOptions = new ParallelOptions {
                MaxDegreeOfParallelism = 6
            };

            Parallel.ForEach(
                files,
                parallelOptions,
                file =>
            {
                string json = Gzip.Decompress(file);

                var movieModel = JsonConvert.DeserializeObject(json, typeof(MovieModel)) as MovieModel;

                if (json.Contains(@"ChangedText"":false"))
                {
                    movieModel.ChangedText = false;
                }

                if (json.Contains(@"ChangedPoster"":false"))
                {
                    movieModel.ChangedPoster = false;
                }

                if (json.Contains(@"ChangedFanart"":false"))
                {
                    movieModel.ChangedFanart = false;
                }

                movieModel.DatabaseSaved = true;

                if (movieModel.AssociatedFiles.GetMediaCollection().Count > 0)
                {
                    if (!File.Exists(movieModel.AssociatedFiles.GetMediaCollection()[0].PathAndFilename))
                    {
                        Log.WriteToLog(
                            LogSeverity.Info,
                            LoggerName.GeneralLog,
                            "Internal > DatabaseIOFactory > LoadMovieDB",
                            string.Format(
                                "Deleting {0}. Movie not found on the filesystem",
                                movieModel.AssociatedFiles.GetMediaCollection()[0].FileName));
                        // We should check for network path and make sure the file has actually been deleted or removed
                        File.Delete(file);
                    }
                }

                if (movieModel != null)
                {
                    lock (database)
                    {
                        database.Add(movieModel);
                    }
                }

                string title = FileNaming.RemoveIllegalChars(movieModel.Title);

                string poster = path + title + ".poster.jpg";
                string fanart = path + title + ".fanart.jpg";

                if (File.Exists(poster))
                {
                    movieModel.SmallPoster = ImageHandler.LoadImage(poster);
                }

                if (File.Exists(fanart))
                {
                    movieModel.SmallFanart = ImageHandler.LoadImage(fanart);
                }
            });
        }