diff --git a/YTManager/Migrations/20170901083156_initial.Designer.cs b/YTManager/Migrations/20170902220142_initial.Designer.cs similarity index 95% rename from YTManager/Migrations/20170901083156_initial.Designer.cs rename to YTManager/Migrations/20170902220142_initial.Designer.cs index d1e9242..e46501e 100644 --- a/YTManager/Migrations/20170901083156_initial.Designer.cs +++ b/YTManager/Migrations/20170902220142_initial.Designer.cs @@ -11,7 +11,7 @@ using YTManager; namespace YTManager.Migrations { [DbContext(typeof(MediaDB))] - [Migration("20170901083156_initial")] + [Migration("20170902220142_initial")] partial class initial { protected override void BuildTargetModel(ModelBuilder modelBuilder) @@ -63,6 +63,9 @@ namespace YTManager.Migrations b.Property("Uploaded"); + b.Property("YTChannelID") + .IsRequired(); + b.Property("YTVideoID") .IsRequired(); diff --git a/YTManager/Migrations/20170901083156_initial.cs b/YTManager/Migrations/20170902220142_initial.cs similarity index 97% rename from YTManager/Migrations/20170901083156_initial.cs rename to YTManager/Migrations/20170902220142_initial.cs index d2f5473..f53bec0 100644 --- a/YTManager/Migrations/20170901083156_initial.cs +++ b/YTManager/Migrations/20170902220142_initial.cs @@ -37,6 +37,7 @@ namespace YTManager.Migrations ThumbnailURL = table.Column(type: "text", nullable: false), Title = table.Column(type: "text", nullable: false), Uploaded = table.Column(type: "timestamp", nullable: false), + YTChannelID = table.Column(type: "text", nullable: false), YTVideoID = table.Column(type: "text", nullable: false) }, constraints: table => diff --git a/YTManager/Migrations/MediaDBModelSnapshot.cs b/YTManager/Migrations/MediaDBModelSnapshot.cs index eaae80f..86bcdc6 100644 --- a/YTManager/Migrations/MediaDBModelSnapshot.cs +++ b/YTManager/Migrations/MediaDBModelSnapshot.cs @@ -62,6 +62,9 @@ namespace YTManager.Migrations b.Property("Uploaded"); + b.Property("YTChannelID") + .IsRequired(); + b.Property("YTVideoID") .IsRequired(); diff --git a/YTManager/Models/Video.cs b/YTManager/Models/Video.cs index ddcb71d..5b17d02 100644 --- a/YTManager/Models/Video.cs +++ b/YTManager/Models/Video.cs @@ -22,6 +22,10 @@ namespace YTManager.Models { [Required] public string YTVideoID { get; set; } + // Channel this video belongs to. + [Required] + public string YTChannelID { get; set; } + // Thumbnail link [Required] public string ThumbnailURL { get; set; } diff --git a/YTManager/Tasks/FetchVideos.cs b/YTManager/Tasks/FetchVideos.cs index 1753039..5d90c0f 100644 --- a/YTManager/Tasks/FetchVideos.cs +++ b/YTManager/Tasks/FetchVideos.cs @@ -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(); diff --git a/YTManager/wwwroot/admin.html b/YTManager/wwwroot/admin.html index 4fea10a..49863b2 100644 --- a/YTManager/wwwroot/admin.html +++ b/YTManager/wwwroot/admin.html @@ -9,86 +9,19 @@ -

Dumb YT Manager

-

Youtube banned my account and refuses to say why, taking all my subscribed channels with it. This is a simple scrubscribed channel manager, showing recent releases from each channel and finally proper sub-catagory functionality!

- -
-

Subscribed Channels

- - - - - - - - - - - - - - - -
YT Channel IDTitleDescription
{{entry.ytChannelID}}{{entry.title}}{{entry.description}}
- -
-
-
-
- -
-
- - -
-

Add new Channel

-
-
- Title - -
-
-
- Channel - -
-
-
- Description - -
-
- -
- -
-
-
+ +
+

Subscribed Channels

+
+
+

Videos in DB

- - - - - - - - - - - - - - - - - -
TitleDescriptionYoutube Video IDID
{{video.title}}{{video.description}}{{video.ytVideoID}}{{video.videoId}}
+
diff --git a/YTManager/wwwroot/admin.js b/YTManager/wwwroot/admin.js index 73a69cd..5d3d684 100644 --- a/YTManager/wwwroot/admin.js +++ b/YTManager/wwwroot/admin.js @@ -16,6 +16,45 @@ var addchanel0 = new Vue({ fail: false, expanded: false }, + template: ` +
+
+
+
+ +
+
+ + +
+

Add new Channel

+
+
+ Title + +
+
+
+ Channel + +
+
+
+ Description + +
+
+ +
+ +
+
+
+
+ `, methods: { submit: function (event) { // Send the channel to our API and request tables be updated. @@ -78,10 +117,30 @@ var addchanel0 = new Vue({ // Bind to our table of entries. var tbody0 = new Vue({ - el: '#tbody-0', + el: '#subbedchannelstable-0', data: { entries: [""] }, + template: ` + + + + + + + + + + + + + + + + + +
YT Channel IDTitleDescriptionID
{{entry.ytChannelID}}{{entry.title}}{{entry.description}}{{entry.channelId}}
+ `, methods: { retrieve: function (event) { axios.get('/api/Channels') @@ -106,10 +165,32 @@ var tbody0 = new Vue({ // Grid if images. var videostb = new Vue({ - el: '#videostb-0', + el: '#videosindbtable-0', data: { Videos: [] }, + template: ` + + + + + + + + + + + + + + + + + + + +
TitleDescriptionYoutube Video IDUploadedID
{{video.title}}{{video.description}}{{video.ytVideoID}}{{video.uploaded}}{{video.videoId}}
+ `, methods: { // Get new videos from the web api. retrieve: function (event) { diff --git a/YTManager/wwwroot/index.css b/YTManager/wwwroot/index.css index 8275ecd..d4c0f23 100644 --- a/YTManager/wwwroot/index.css +++ b/YTManager/wwwroot/index.css @@ -1,12 +1,17 @@ body { - max-width: 1280px; - margin: auto; + margin-left: 5%; + margin-right: 5%; line-height: 1.6; font-size: 18px; color: #444; background-color: #F8F8F8; } +.pageheader { + max-width: 1280px; + margin: auto; +} + .error { background-color: red; } @@ -16,10 +21,6 @@ margin: auto; } -#vidholder-0 { - -} - .tinytext10px{ font-size: 10px; } .tinytext12px{ font-size: 12px; } .tinytext14px{ font-size: 14px; } @@ -34,6 +35,6 @@ transition: opacity 0.75s; } -.fade-enter, .fade-leave-to /* .fade-leave-active below version 2.1.8 */ { +.fade-enter, .fade-leave-to { opacity: 0; } diff --git a/YTManager/wwwroot/index.html b/YTManager/wwwroot/index.html index a17bb9f..73d8a30 100644 --- a/YTManager/wwwroot/index.html +++ b/YTManager/wwwroot/index.html @@ -9,24 +9,14 @@ -

Dumb YT Manager

-

Youtube banned my account and refuses to say why, taking all my subscribed channels with it. This is a simple scrubscribed channel manager, showing recent releases from each channel and finally proper sub-catagory functionality!

- + +

Most Recent Videos

-
-
-
-
-
{{video.title}}
-
- -
-

{{video.description}}

-
-
-
-
+
diff --git a/YTManager/wwwroot/index.js b/YTManager/wwwroot/index.js index 3b5403c..2441537 100644 --- a/YTManager/wwwroot/index.js +++ b/YTManager/wwwroot/index.js @@ -7,36 +7,32 @@ var maxcharsdescriptionfield = 100; var vidholder = new Vue({ el: '#vidholder-0', data: { - Videos: { - Rows: [ - /*{ - Columns: [ - { - "title": "0", - "description": "", - "yTVideoID": "", - "thumbnailURL": "", - "uploaded": "", - "yTChannelID": "" - } - ] - }*/ - ] - } + Videos: [] }, + // Template has wrapping div because v-for can't be in root it seems. + template: ` +
+
+
+
+
{{ video.title }}
+
+ +
+

{{ video.description }}

+
+
+
+
+ `, methods: { // Get new videos from the web api. retrieve: function (event) { // Wipe out all old entries. - this.Videos.Rows = []; + this.Videos = []; axios.get('/api/Videos') .then(function (response) { - // Dimension counters and limits. - var maxcols = 4; - var colcounter = 0; - var rowcounter = 0; - // And fill it with all the retrieved entries. response.data.forEach(function (x) { // Trim description if needed. @@ -44,21 +40,11 @@ var vidholder = new Vue({ x.description = x.description.substring(0, maxcharsdescriptionfield) + " ..."; } - // Handle creation of a new row. - if (colcounter == 0) { - Vue.set(this.Videos.Rows, rowcounter, []); - Vue.set(this.Videos.Rows[rowcounter], 'Columns', []); - } + // Generate a new URL by adding the YT ID. + x.url = "https://www.youtube.com/watch?v=" + x.ytVideoID // Add it to our array - this.Videos.Rows[rowcounter].Columns.push(x); - - // So we get it all in groups of maxcols. - colcounter = colcounter + 1; - if (colcounter == maxcols) { - colcounter = 0; - rowcounter = rowcounter + 1; - } + this.Videos.push(x); }.bind(this)); }.bind(this)) .catch(function (error) {