Added API for managing job of updating videos
This commit is contained in:
@ -9,7 +9,7 @@ namespace YTManager.Tasks
|
||||
{
|
||||
public class FetchVideos
|
||||
{
|
||||
public static void run()
|
||||
public static void run(string youtubechannelIDstr = "")
|
||||
{
|
||||
// YT API access key
|
||||
var youtubeService = new YouTubeService(new Google.Apis.Services.BaseClientService.Initializer()
|
||||
@ -22,7 +22,12 @@ namespace YTManager.Tasks
|
||||
var ops = new DbContextOptionsBuilder<MediaDB>();
|
||||
ops.UseNpgsql(YTManager.Startup.dbstr);
|
||||
using (var dbcontext = new MediaDB(ops.Options)) {
|
||||
var channels = dbcontext.Channels.ToList();
|
||||
// Get all the potential relevant channels.
|
||||
List<Models.Channel> channels;
|
||||
if (youtubechannelIDstr == "")
|
||||
channels = dbcontext.Channels.ToList();
|
||||
else
|
||||
channels = dbcontext.Channels.Where(c => c.YTChannelID == youtubechannelIDstr).ToList();
|
||||
|
||||
// Get all the most recent videos for each channel.
|
||||
channels.ForEach(ch => {
|
||||
@ -35,7 +40,7 @@ namespace YTManager.Tasks
|
||||
// Get all videos which aren't already in the DB.
|
||||
var notindb = response.Items
|
||||
.Where(i => i.Id.Kind == "youtube#video")
|
||||
.Where(i => !dbcontext.Videos.Any(dbvid => dbvid.YTVideoID != i.Id.VideoId))
|
||||
.Where(i => !dbcontext.Videos.Any(dbvid => dbvid.YTVideoID == i.Id.VideoId))
|
||||
.Select(newvid =>
|
||||
new Models.Video {
|
||||
Title = newvid.Snippet.Title,
|
||||
|
Reference in New Issue
Block a user