Пример #1
0
        public static Boolean AssocVideoWithEpisode(VideoFileInfo VidFile, TVEpisode Episode)
        {
            SQLiteCommand cmd = Connection.CreateCommand();
            cmd.CommandText = String.Format(@"INSERT INTO episode2video (episodeId, videoId) VALUES (
                @EpisodeId,
                @VideoId);");
            cmd.Parameters.Add(new SQLiteParameter("@EpisodeId", DbType.Int32) { Value = Episode.Id });
            cmd.Parameters.Add(new SQLiteParameter("@VideoId", DbType.Int32) { Value = VidFile.Id });

            return cmd.ExecuteNonQuery() > 0;
        }
Пример #2
0
        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.
        }
Пример #3
0
        public static VideoFileInfo SaveVideoFile(VideoFileInfo VidFile)
        {
            SQLiteCommand cmd = Connection.CreateCommand();

            if (VidFile.Id == 0)
            {
                VidFile.Id = GetNewGlobalId("videofile");

                cmd.CommandText = String.Format(@"INSERT INTO video_files (id, duration, bitrate, aspectRatio, audioChannels, audioCodec, videoCodec,
            PictureHeight, PictureWidth, videoFrameRate, path, size, fileHash) VALUES (
                @Id,
                @Duration,
                @Bitrate,
                @AspectRatio,
                @AudioChannels,
                @AudioCodec,
                @VideoCodec,
                @PictureHeight,
                @PictureWidth,
                @VideoFrameRate,
                @Path,
                @Size,
                @FileHash);");
            }
            else
            {
                cmd.CommandText = String.Format(@"UPDATE video_files SET
                    duration = @Duration,
                    bitrate = @Bitrate,
                    aspectRatio = @AspectRatio,
                    audioChannels = @AudioChannels,
                    audioCodec = @AudioCodec,
                    videoCodec = @VideoCodec,
                    PictureHeight = @PictureHeight,
                    PictureWidth = @PictureWidth,
                    videoFrameRate = @VideoFrameRate,
                    path = @Path,
                    size = @Size,
                    fileHash = @FileHash
                    WHERE id = @Id;");
            }
            cmd.Parameters.Add(new SQLiteParameter("@Id", DbType.Int32) { Value = VidFile.Id });
            cmd.Parameters.Add(new SQLiteParameter("@Duration", DbType.Int32) { Value = VidFile.Duration });
            cmd.Parameters.Add(new SQLiteParameter("@Bitrate", DbType.Int32) { Value = VidFile.Bitrate });
            cmd.Parameters.Add(new SQLiteParameter("@AspectRatio", DbType.Double) { Value = VidFile.AspectRatio });
            cmd.Parameters.Add(new SQLiteParameter("@AudioChannels", DbType.Double) { Value = VidFile.AudioChannels });
            cmd.Parameters.Add(new SQLiteParameter("@AudioCodec", DbType.String) { Value = VidFile.AudioCodec });
            cmd.Parameters.Add(new SQLiteParameter("@VideoCodec", DbType.String) { Value = VidFile.VideoCodec });
            cmd.Parameters.Add(new SQLiteParameter("@PictureWidth", DbType.String) { Value = VidFile.PictureWidth });
            cmd.Parameters.Add(new SQLiteParameter("@PictureHeight", DbType.String) { Value = VidFile.PictureHeight });
            cmd.Parameters.Add(new SQLiteParameter("@VideoFrameRate", DbType.String) { Value = VidFile.FrameRate });
            cmd.Parameters.Add(new SQLiteParameter("@Path", DbType.String) { Value = VidFile.Path });
            cmd.Parameters.Add(new SQLiteParameter("@Size", DbType.Int32) { Value = VidFile.Size });
            cmd.Parameters.Add(new SQLiteParameter("@FileHash", DbType.String) { Value = VidFile.Hash });

            cmd.ExecuteNonQuery();
            return VidFile;
        }
Пример #4
0
        public static VideoFileInfo GetVideoFile(int FileId)
        {
            SQLiteCommand cmd = Connection.CreateCommand();
            cmd.CommandText = "SELECT * FROM video_files WHERE id = @Id";

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

            SQLiteDataAdapter da = new SQLiteDataAdapter(cmd);
            DataTable VideoFileTable = new DataTable();
            da.Fill(VideoFileTable);

            if (VideoFileTable.Rows.Count == 1)
            {
                DataRow Row = VideoFileTable.Rows[0];

                VideoFileInfo VideoFile = new VideoFileInfo(Row);

                return VideoFile;
            }
            else {
                return null;
            }
        }