Lots and lots of cleanup!
This commit is contained in:
@ -11,8 +11,6 @@ namespace YTManager.Tasks
|
||||
{
|
||||
public static void run()
|
||||
{
|
||||
Console.WriteLine("Startnig job ...");
|
||||
|
||||
// YT API access key
|
||||
var youtubeService = new YouTubeService(new Google.Apis.Services.BaseClientService.Initializer()
|
||||
{
|
||||
@ -29,20 +27,23 @@ namespace YTManager.Tasks
|
||||
// Get all the most recent videos for each channel.
|
||||
channels.ForEach(ch => {
|
||||
// Get channel videos from youtube.
|
||||
var query = youtubeService.Activities.List("snippet");
|
||||
var query = youtubeService.Search.List("snippet");
|
||||
query.ChannelId = ch.YTChannelID;
|
||||
query.MaxResults = 50;
|
||||
var response = query.Execute();
|
||||
|
||||
// Get all videos which aren't already in the DB.
|
||||
var notindb = response.Items
|
||||
.Where(i => !dbcontext.Videos.Any(dbvid => dbvid.YTVideoID != i.Id))
|
||||
.Where(i => i.Id.Kind == "youtube#video")
|
||||
.Where(i => !dbcontext.Videos.Any(dbvid => dbvid.YTVideoID != i.Id.VideoId))
|
||||
.Select(newvid =>
|
||||
new Models.Video {
|
||||
Title = newvid.Snippet.Title,
|
||||
Description = newvid.Snippet.Description,
|
||||
YTVideoID = newvid.Id,
|
||||
YTVideoID = newvid.Id.VideoId,
|
||||
Uploaded = newvid.Snippet.PublishedAt.GetValueOrDefault(),
|
||||
AddedtoDB = DateTime.Now,
|
||||
YTChannelID = newvid.Snippet.ChannelId,
|
||||
Channel = ch,
|
||||
ThumbnailURL = newvid.Snippet.Thumbnails.Medium.Url
|
||||
}).ToList();
|
||||
|
Reference in New Issue
Block a user