コード例 #1
0
ファイル: FileSystemScanner.cs プロジェクト: spol/Splice
        private void UpdateShow(TVShow Show)
        {
            Reporting.Log("Updating show: " + Show.Title);

            string[] VideoPaths = Directory.GetFiles(Show.Location, "*.*", SearchOption.AllDirectories);

            List<VideoFileInfo> Videos = new List<VideoFileInfo>();
            foreach (string VidPath in VideoPaths)
            {
                if (!ConfigurationManager.CurrentConfiguration.VideoExtensions.Contains(new FileInfo(VidPath).Extension.Trim('.')))
                {
                    continue;
                }

                Reporting.Log(VidPath);
                VideoFileInfo VidFile = new VideoFileInfo(VidPath);

                VideoFileInfo CurrentFile = DataAccess.GetVideoFileFromHash(VidFile.Hash);
                Reporting.Log(VidFile.Hash);

                if (CurrentFile != null)
                {
                    // File has been seen before.
                    Reporting.Log("Already seen");

                    if (CurrentFile.Path != VidFile.Path)
                    {
                        Reporting.Log("Updating location.");
                        // Update video file location.
                        CurrentFile.Path = VidFile.Path;
                        DataAccess.SaveVideoFile(CurrentFile);
                    }
                }
                else
                {
                    // new file.

                    // Save filesize
                    FileInfo Info = new FileInfo(VidFile.Path);
                    VidFile.Size = Info.Length;
                    string RelativePath = VidPath.Replace(Show.Location, "");

                    int SeasonNumber = -1;
                    int EpisodeNumber = -1;
                    foreach (string Regex in ConfigurationManager.CurrentConfiguration.TVRegexes)
                    {
                        Regex R = new Regex(Regex);
                        Match M = R.Match(RelativePath);
                        if (M.Success)
                        {
                            if (M.Groups.Count < 1)
                            {
                                continue;
                            }
                            else if (M.Groups.Count == 2)
                            {
                                EpisodeNumber = Convert.ToInt32(M.Groups[1].Value);
                            }
                            else
                            {
                                SeasonNumber = Convert.ToInt32(M.Groups[1].Value);
                                EpisodeNumber = Convert.ToInt32(M.Groups[2].Value);
                            }
                            break;
                        }
                    }

                    if (EpisodeNumber == 0)
                    {
                        Reporting.Log(RelativePath + " does not match any TV regexes in config file.");
                        return;
                    }

                    // check for presence of season
                    TVSeason Season = DataAccess.GetTVSeason(Show, SeasonNumber);

                    if (Season == null)
                    {
                        // insert season if not present.
                        Season = new TVSeason()
                        {
                            SeasonNumber = SeasonNumber,
                            ShowId = Show.Id
                        };
                        Season = DataAccess.SaveSeason(Season);

                        TvdbDownloader Downloader = new TvdbDownloader(TvdbApiKey);

                        List<TvdbBanner> Banners = Downloader.DownloadBanners(Show.TvdbId);
                        List<TvdbSeasonBanner> SeasonBanners = new List<TvdbSeasonBanner>();

                        foreach (TvdbBanner Banner in Banners)
                        {
                            if (Banner.GetType() == typeof(TvdbSeasonBanner))
                            {
                                TvdbSeasonBanner SeasonBanner = (TvdbSeasonBanner)Banner;
                                if (SeasonBanner.Season == SeasonNumber)
                                {
                                    SeasonBanners.Add(SeasonBanner);
                                }
                            }
                        }

                        Season.Art = CacheManager.SaveArtwork(Season.Id, SeasonBanners[0].BannerPath, ArtworkType.Poster);

                        Season = DataAccess.SaveSeason(Season);
                    }

                    // check for presence of episode
                    TVEpisode Episode = DataAccess.GetTVEpisode(Show, Season, EpisodeNumber);

                    // insert ep if not present
                    if (Episode == null)
                    {
                        TvdbEpisode TvdbEp = LookupEpisode(Show, Season, EpisodeNumber);

                        if (TvdbEp == null)
                        {
                            Reporting.Log(String.Format("Episode not found: {0} - {1}x{2} ({3})", Show.Title, Season.SeasonNumber, EpisodeNumber, VidFile.Path));
                            continue;
                        }
                        Episode = new TVEpisode() {
                            EpisodeNumber = EpisodeNumber,
                            SeasonId = Season.Id,
                            AirDate = TvdbEp.FirstAired,
                            Rating = TvdbEp.Rating,
                            Summary = TvdbEp.Overview,
                            Title = TvdbEp.EpisodeName,
                            TvdbId = TvdbEp.Id,
                        };
                        Episode = DataAccess.SaveEpisode(Episode);

                        Episode.Thumb = CacheManager.SaveArtwork(Episode.Id, TvdbEp.BannerPath, ArtworkType.Banner);
                        DataAccess.SaveEpisode(Episode);
                    }

                    // save video file
                    VidFile.LoadMetaDataFromFile();
                    VidFile = DataAccess.SaveVideoFile(VidFile);

                    // add video file to episode.
                    DataAccess.AssocVideoWithEpisode(VidFile, Episode);
                }

            }

            // TODO: Clean up missing files.
        }
コード例 #2
0
ファイル: FileSystemScanner.cs プロジェクト: spol/Splice
        private TvdbEpisode LookupEpisode(TVShow Show, TVSeason Season, Int32 EpisodeNumber)
        {
            TvdbHandler Handler = new TvdbHandler(TvdbApiKey);

            return Handler.GetEpisode(Show.TvdbId, Season.SeasonNumber, EpisodeNumber, TvdbEpisode.EpisodeOrdering.DefaultOrder, TvdbLanguage.DefaultLanguage);
        }
コード例 #3
0
ファイル: FileSystemScanner.cs プロジェクト: spol/Splice
        private void ScanTVCollection(VideoCollection Collection)
        {
            foreach (String Path in Collection.Locations)
            {
                DirectoryInfo dirInfo = new DirectoryInfo(Path);

                if (!dirInfo.Exists)
                {
                    throw new IOException(String.Format("Collection location doesn't exist. ({0})", Path));
                }

                DirectoryInfo[] showDirectories = dirInfo.GetDirectories();

                foreach (DirectoryInfo showDir in showDirectories)
                {
                    TVShow show = DataAccess.GetTVShowFromPath(showDir.FullName);
                    if (show == null)
                    {
                        // New Show.
                        TvdbSeries series = LookupShow(showDir.Name);
                        Reporting.Log("Matched: " + series.SeriesName);
                        show = new TVShow();
                        show.Collection = Collection.Id;
                        show.ContentRating = series.ContentRating;
                        show.Duration = Convert.ToInt32(series.Runtime);
                        show.LastUpdated = DateTime.Now.Timestamp();
                        show.LeafCount = 0;
                        show.Location = showDir.FullName;
                        show.AirDate = series.FirstAired;
                        show.Rating = series.Rating;
                        show.Studio = series.Network;
                        show.Summary = series.Overview;
                        show.Title = series.SeriesName;
                        show.ViewedLeafCount = 0;
                        show.TvdbId = series.Id;

                        show = DataAccess.SaveTVShow(show);

                        show.Thumb = CacheManager.SaveArtwork(show.Id, series.PosterPath, ArtworkType.Poster);
                        show.Art = CacheManager.SaveArtwork(show.Id, series.FanartPath, ArtworkType.Fanart);
                        show.Banner = CacheManager.SaveArtwork(show.Id, series.BannerPath, ArtworkType.Banner);

                        // resave with Artwork
                        show = DataAccess.SaveTVShow(show);
                    }
                    else
                    {
                        // TODO: Check for updates/artwork.
                    }

                    // Show already in DB
                    UpdateShow(show);
                }
            }
        }
コード例 #4
0
ファイル: FileSystemScanner.cs プロジェクト: spol/Splice
        private TVSeason UpdateSeason(DirectoryInfo Dir, TVShow Show, int SeasonNumber)
        {
            TVSeason Season = DataAccess.GetTVSeason(Show, SeasonNumber);

            if (Season != null)
            {
                return Season;
            }
            else
            {
                Season = new TVSeason()
                {
                    SeasonNumber = SeasonNumber,
                    ShowId = Show.Id,
                    Art = ""
                };
                return DataAccess.SaveSeason(Season);
            }
        }
コード例 #5
0
ファイル: DataAccess.cs プロジェクト: spol/Splice
        public static TVShow SaveTVShow(TVShow Show)
        {
            SQLiteCommand cmd = Connection.CreateCommand();

            if (Show.Id == 0)
            {
                Show.Id = GetNewGlobalId("show");

                cmd.CommandText = String.Format(@"INSERT INTO tv_shows (id, title, tvdbId, collection, studio, contentRating, summary, rating, year, thumb, art, banner,
            duration, originallyAvailableAt, lastUpdated, location) VALUES (
                @Id,
                @Title,
                @TvdbId,
                @Collection,
                @Studio,
                @ContentRating,
                @Summary,
                @Rating,
                @Year,
                @Thumb,
                @Art,
                @Banner,
                @Duration,
                @AirDate,
                @LastUpdated,
                @Location);");
            }
            else
            {
                cmd.CommandText = String.Format(@"UPDATE tv_shows SET
                    title = @Title,
                    tvdbId = @TvdbId,
                    collection = @Collection,
                    studio = @Studio,
                    contentRating = @ContentRating,
                    summary = @Summary,
                    rating = @Rating,
                    year = @Year,
                    thumb = @Thumb,
                    art = @Art,
                    banner = @Banner,
                    duration = @Duration,
                    originallyAvailableAt = @AirDate,
                    lastUpdated = @LastUpdated,
                    location = @Location
                    WHERE id = @Id;");
            }
            cmd.Parameters.Add(new SQLiteParameter("@Id", DbType.Int32) { Value = Show.Id });
            cmd.Parameters.Add(new SQLiteParameter("@Title", DbType.String) { Value = Show.Title });
            cmd.Parameters.Add(new SQLiteParameter("@TvdbId", DbType.Int32) { Value = Show.TvdbId });
            cmd.Parameters.Add(new SQLiteParameter("@Collection", DbType.Int32) { Value = Show.Collection });
            cmd.Parameters.Add(new SQLiteParameter("@Studio", DbType.String) { Value = Show.Studio });
            cmd.Parameters.Add(new SQLiteParameter("@ContentRating", DbType.String) { Value = Show.ContentRating });
            cmd.Parameters.Add(new SQLiteParameter("@Summary", DbType.String) { Value = Show.Summary });
            cmd.Parameters.Add(new SQLiteParameter("@Rating", DbType.Double) { Value = Show.Rating });
            cmd.Parameters.Add(new SQLiteParameter("@Year", DbType.Int32) { Value = Show.Year });
            cmd.Parameters.Add(new SQLiteParameter("@Thumb", DbType.String) { Value = Show.Thumb });
            cmd.Parameters.Add(new SQLiteParameter("@Art", DbType.String) { Value = Show.Art });
            cmd.Parameters.Add(new SQLiteParameter("@Banner", DbType.String) { Value = Show.Banner });
            cmd.Parameters.Add(new SQLiteParameter("@Duration", DbType.Int32) { Value = Show.Duration });
            cmd.Parameters.Add(new SQLiteParameter("@AirDate", DbType.DateTime) { Value = Show.AirDate });
            cmd.Parameters.Add(new SQLiteParameter("@LastUpdated", DbType.Int32) { Value = Show.LastUpdated });
            cmd.Parameters.Add(new SQLiteParameter("@Location", DbType.String) { Value = Show.Location });

            cmd.ExecuteNonQuery();
            return Show;
        }
コード例 #6
0
ファイル: DataAccess.cs プロジェクト: spol/Splice
        public static List<TVShow> GetTVShows(int collectionId, Filter filter)
        {
            List<TVShow> shows = new List<TVShow>();

            using (SQLiteCommand cmd = Connection.CreateCommand())
            {
                cmd.CommandText = String.Format(filter.Query, collectionId);

                SQLiteDataAdapter da = new SQLiteDataAdapter(cmd);

                DataTable showsTable = new DataTable();
                da.Fill(showsTable);

                foreach (DataRow showRow in showsTable.Rows)
                {
                    TVShow show = new TVShow();

                    show.Id = Convert.ToInt32(showRow["id"]);
                    show.Title = Convert.ToString(showRow["title"]);
                    show.Banner = Convert.ToString(showRow["banner"] == DBNull.Value ? "" : showRow["banner"]);
                    show.Art = Convert.ToString(showRow["art"] == DBNull.Value ? "" : showRow["art"]);
                    show.Thumb = Convert.ToString(showRow["thumb"] == DBNull.Value ? "" : showRow["thumb"]);
                    show.LastUpdated = Convert.ToInt32(showRow["lastUpdated"]);
                    show.Collection = Convert.ToInt32(showRow["collection"]);
                    show.ContentRating = showRow["contentRating"].ToString();
                    show.Duration = Convert.ToInt32(showRow["duration"]);
                    show.LastUpdated = Convert.ToInt32(showRow["lastUpdated"]);
                    // TODO: Get LeafCount.
                    show.LeafCount = 0;
                    show.AirDate = Convert.ToDateTime(showRow["originallyAvailableAt"]);
                    show.Rating = Convert.ToSingle(showRow["rating"]);
                    show.Studio = showRow["studio"].ToString();
                    show.Summary = showRow["summary"].ToString();
                    // TODO: Need to track views first.
                    show.ViewedLeafCount = 0;
                    shows.Add(show);
                }
            }

            return shows;
        }
コード例 #7
0
ファイル: DataAccess.cs プロジェクト: spol/Splice
        public static List<TVSeason> GetTVSeasons(TVShow Show)
        {
            SQLiteCommand cmd = Connection.CreateCommand();
            cmd.CommandText = "SELECT * FROM tv_seasons WHERE showId = @Id ORDER BY seasonNumber > 0 DESC, seasonNumber ASC";

            cmd.Parameters.Add(new SQLiteParameter("@Id", DbType.Int32) { Value = Show.Id });

            SQLiteDataAdapter da = new SQLiteDataAdapter(cmd);

            DataTable SeasonsTable = new DataTable();
            da.Fill(SeasonsTable);

            List<TVSeason> Seasons = new List<TVSeason>();
            foreach (DataRow Row in SeasonsTable.Rows)
            {
                Seasons.Add(new TVSeason(Row));
            }
            return Seasons;
        }
コード例 #8
0
ファイル: DataAccess.cs プロジェクト: spol/Splice
        public static TVSeason GetTVSeason(TVShow Show, int SeasonNumber)
        {
            SQLiteCommand cmd = Connection.CreateCommand();
            cmd.CommandText = "SELECT * FROM tv_seasons WHERE seasonNumber = @SeasonNumber AND showId = @ShowId";

            cmd.Parameters.Add(new SQLiteParameter("@SeasonNumber", DbType.Int32) { Value = SeasonNumber });
            cmd.Parameters.Add(new SQLiteParameter("@ShowId", DbType.Int32) { Value = Show.Id });

            SQLiteDataAdapter da = new SQLiteDataAdapter(cmd);

            DataTable SeasonsTable = new DataTable();
            da.Fill(SeasonsTable);

            if (SeasonsTable.Rows.Count == 1)
            {
                DataRow SeasonRow = SeasonsTable.Rows[0];
                TVSeason Season = new TVSeason();
                Season.Id = Convert.ToInt32(SeasonRow["id"]);
                Season.SeasonNumber = Convert.ToInt32(SeasonRow["seasonNumber"]);
                Season.ShowId = Convert.ToInt32(SeasonRow["showId"]);
                //Season.Art = Convert.ToString(showRow["art"] == DBNull.Value ? "" : showRow["art"]);

                return Season;
            }
            else
            {
                return null;
            }
        }
コード例 #9
0
ファイル: DataAccess.cs プロジェクト: spol/Splice
        public static TVEpisode GetTVEpisode(TVShow Show, TVSeason Season, int EpisodeNumber)
        {
            SQLiteCommand cmd = Connection.CreateCommand();
            cmd.CommandText = "SELECT * FROM tv_episodes WHERE episodeNumber = @EpisodeNumber AND seasonId = @SeasonId";

            cmd.Parameters.Add(new SQLiteParameter("@EpisodeNumber", DbType.Int32) { Value = EpisodeNumber });
            cmd.Parameters.Add(new SQLiteParameter("@SeasonId", DbType.Int32) { Value = Season.Id });

            SQLiteDataAdapter da = new SQLiteDataAdapter(cmd);

            DataTable EpisodeTable = new DataTable();
            da.Fill(EpisodeTable);

            if (EpisodeTable.Rows.Count >= 1)
            {
                DataRow Row = EpisodeTable.Rows[0];
                TVEpisode Episode = new TVEpisode(Row);

                return Episode;
            }

            return null;
        }