Esempio n. 1
0
        private static async Task CheckForVideoFile(string item, string title, string setName, dynamic obj)
        {
            var file = new FileInfo(item);

            if (obj != null && obj.data?.filelen != file.Length)
            {
                Logger.Warn($"file {title} {setName} reuploading");
                await Cloud.DeleteFile(BucketName, $"/{title}/{setName}.mp4");

                await Cloud.SliceUploadFile(BucketName, $"/{title}/{setName}.mp4", item);

                using (var context = new AnimateDatabaseContext())
                    using (var ctx = new CheckContext())
                    {
                        var id = context.AnimateList.FirstOrDefault(anime => anime.EnUs == title).Id;
                        if (id != -1)
                        {
                            if (ctx.CheckList.Count(check => check.ID == id && check.SetName == setName) == 0)
                            {
                                ctx.CheckList.Add(new CheckModel {
                                    ItemID = id, Name = title, SetName = setName
                                });
                            }
                            if (ShareToWeibo && ctx.WeiboList.Count(check => check.ID == id && check.SetName == setName) == 0)
                            {
                                ctx.WeiboList.Add(new WeiboModel {
                                    ItemID = id, Name = title, SetName = setName, ZhTW = ""
                                });
                            }
                            ctx.SaveChanges();
                        }
                    }
                Logger.Info($"reupload {title} {setName} complete");
            }
        }
Esempio n. 2
0
 public HomeController(AnimateDatabaseContext context)
 {
     Context = context;
 }
Esempio n. 3
0
 public DetailController(AnimateDatabaseContext context)
 {
     _context = context;
 }
Esempio n. 4
0
 private static bool CheckForVideoQuality(string title, string setName, dynamic obj)
 {
     using (var context = new AnimateDatabaseContext())
     {
         var id = context.AnimateList.FirstOrDefault(anime => anime.EnUs == title).Id;
         if (id != -1)
         {
             var set = context.SetDetail.FirstOrDefault(anime => anime.Id == id && anime.SetName == double.Parse(setName));
             if (set != null)
             {
                 if (string.IsNullOrEmpty(set.FileThumb) && !string.IsNullOrEmpty((string)obj.data?.video_cover))
                 {
                     if (EnableAdvLogging)
                     {
                         Logger.Info("add file thumb");
                     }
                     set.FileThumb = obj.data.video_cover;
                 }
                 if (string.IsNullOrEmpty(set.LowQuality) && !string.IsNullOrEmpty((string)obj.data?.video_play_url?.f10))
                 {
                     if (EnableAdvLogging)
                     {
                         Logger.Info("add LowQuality");
                     }
                     set.LowQuality = obj.data.video_play_url.f10;
                 }
                 if (string.IsNullOrEmpty(set.MediumQuality) && !string.IsNullOrEmpty((string)obj.data?.video_play_url?.f20))
                 {
                     if (EnableAdvLogging)
                     {
                         Logger.Info("add MediumQuality");
                     }
                     set.MediumQuality = obj.data.video_play_url.f20;
                 }
                 if (string.IsNullOrEmpty(set.HighQuality) && !string.IsNullOrEmpty((string)obj.data?.video_play_url?.f30))
                 {
                     if (EnableAdvLogging)
                     {
                         Logger.Info("add HighQuality");
                     }
                     set.HighQuality = obj.data.video_play_url.f30;
                 }
                 if (string.IsNullOrEmpty(set.OriginalQuality) && !string.IsNullOrEmpty((string)obj.data?.video_play_url?.f0))
                 {
                     if (EnableAdvLogging)
                     {
                         Logger.Info("add OriginalQuality");
                     }
                     set.OriginalQuality = obj.data.video_play_url.f0;
                 }
                 context.Entry(set).State = EntityState.Modified;
                 context.SaveChanges();
                 if (!string.IsNullOrEmpty(set.FileThumb) && !string.IsNullOrEmpty(set.LowQuality) && !string.IsNullOrEmpty(set.MediumQuality) && !string.IsNullOrEmpty(set.HighQuality) && !string.IsNullOrEmpty(set.OriginalQuality))
                 {
                     return(true);
                 }
             }
         }
     }
     return(false);
 }
Esempio n. 5
0
        private static async Task AddSet(string item, string title, string setName)
        {
            if (EnableAdvLogging)
            {
                Logger.Info($"adding {title} {setName} into database");
            }
            using (var context = new AnimateDatabaseContext())
            {
                if (!context.AnimateList.Any(anime => anime.EnUs == title))
                {
                    if (EnableAdvLogging)
                    {
                        Logger.Info("cannot find id, create new");
                    }
                    context.AnimateList.Add(new AnimateList {
                        EnUs = title, Updated_At = DateTime.Now
                    });
                    context.SaveChanges();
                }
                var id = context.AnimateList.FirstOrDefault(anime => anime.EnUs == title).Id;
                if (id != -1)
                {
                    if (EnableAdvLogging)
                    {
                        Logger.Info($"checking for file data...");
                    }
                    dynamic obj = await AutoRetry(Cloud.GetFileStat(BucketName, $"/{title}/{setName}.mp4"));

                    if (obj != null && obj.code == 0)
                    {
                        if (obj.data.access_url != null)
                        {
                            if (context.SetDetail.Any(anime => anime.Id == id && anime.SetName == double.Parse(setName)))
                            {
                                if (EnableAdvLogging)
                                {
                                    Logger.Info("existed,add check");
                                }
                                var animeItem = context.AnimateList.FirstOrDefault(anime => anime.Id == id);
                                using (var ctx = new CheckContext())
                                {
                                    if (!ctx.CheckList.Any(check => check.ID == id && check.SetName == setName))
                                    {
                                        ctx.CheckList.Add(new CheckModel {
                                            ItemID = id, Name = title, SetName = setName
                                        });
                                    }
                                    if (ShareToWeibo && !ctx.WeiboList.Any(check => check.ID == id && check.SetName == setName))
                                    {
                                        ctx.WeiboList.Add(new WeiboModel {
                                            ItemID = id, Name = title, SetName = setName, ZhTW = animeItem.ZhTw
                                        });
                                    }
                                    ctx.SaveChanges();
                                }
                            }
                            else
                            {
                                if (EnableAdvLogging)
                                {
                                    Logger.Info("adding set...");
                                }
                                context.SetDetail.Add(new SetDetail {
                                    Id = id, SetName = double.Parse(setName), FilePath = obj.data.access_url, ClickCount = 0, Created_At = DateTime.Now
                                });
                                var animeItem = context.AnimateList.FirstOrDefault(anime => anime.Id == id);
                                animeItem.Updated_At = DateTime.Now;
                                animeItem            = await GetAnimeTitle(title, animeItem);

                                context.Entry(animeItem).State = EntityState.Modified;
                                context.SaveChanges();
                                using (var ctx = new CheckContext())
                                {
                                    if (ctx.CheckList.Count(check => check.ID == id && check.SetName == setName) == 0)
                                    {
                                        ctx.CheckList.Add(new CheckModel {
                                            ItemID = id, Name = title, SetName = setName
                                        });
                                    }
                                    if (ShareToWeibo && ctx.WeiboList.Count(check => check.ID == id && check.SetName == setName) == 0)
                                    {
                                        ctx.WeiboList.Add(new WeiboModel {
                                            ItemID = id, Name = title, SetName = setName, ZhTW = animeItem.ZhTw
                                        });
                                    }
                                    ctx.SaveChanges();
                                }
                                if (EnableAdvLogging)
                                {
                                    Logger.Info("add set complete");
                                }
                            }
                        }
                    }
                }
            }
        }
Esempio n. 6
0
 public ApiController(AnimateDatabaseContext context)
 {
     _context = context;
 }
Esempio n. 7
0
 public WatchController(AnimateDatabaseContext context)
 {
     _context = context;
 }