Lots and lots of cleanup!

This commit is contained in:
hak8or 2017-09-02 21:05:50 -04:00
parent 6f326320cc
commit caf2bde6c4
10 changed files with 145 additions and 142 deletions

View File

@ -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<DateTime>("Uploaded");
b.Property<string>("YTChannelID")
.IsRequired();
b.Property<string>("YTVideoID")
.IsRequired();

View File

@ -37,6 +37,7 @@ namespace YTManager.Migrations
ThumbnailURL = table.Column<string>(type: "text", nullable: false),
Title = table.Column<string>(type: "text", nullable: false),
Uploaded = table.Column<DateTime>(type: "timestamp", nullable: false),
YTChannelID = table.Column<string>(type: "text", nullable: false),
YTVideoID = table.Column<string>(type: "text", nullable: false)
},
constraints: table =>

View File

@ -62,6 +62,9 @@ namespace YTManager.Migrations
b.Property<DateTime>("Uploaded");
b.Property<string>("YTChannelID")
.IsRequired();
b.Property<string>("YTVideoID")
.IsRequired();

View File

@ -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; }

View File

@ -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();

View File

@ -9,86 +9,19 @@
<link rel="stylesheet" type="text/css" href="index.css">
</head>
<body>
<h1>Dumb YT Manager</h1>
<p>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!</p>
<hr />
<h2>Subscribed Channels</h2>
<table id="tbody-0">
<thead>
<tr>
<th>YT Channel ID</th>
<th>Title</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr v-cloak v-for="entry in entries">
<td class="tinytext12px">{{entry.ytChannelID}}</td>
<td class="tinytext12px">{{entry.title}}</td>
<td class="tinytext12px">{{entry.description}}</td>
</tr>
</tbody>
</table>
<div id="addchanel-0">
<div class="grid-x">
<div class="medium-11 cell"></div>
<div class="medium-1 cell">
<button type="button" class="button input-group" v-on:click='expanded = !expanded'>
<i class="fa fa-plus" aria-hidden="true"></i> Add
</button>
</div>
</div>
<transition name="fade">
<form v-cloak v-if="expanded">
<h2>Add new Channel</h2>
<div class="grid-x">
<div class="input-group medium-6 cell">
<span class="input-group-label">Title</span>
<input class="input-group-field" type="text" placeholder="Title of Entry" v-model="entry.title">
</div>
<div class="input-group medium-1 cell"></div>
<div class="input-group medium-5 cell">
<span class="input-group-label">Channel</span>
<input class="input-group-field" v-bind:class="{ error: fail }" type="text"
@blur="newurl" placeholder="URL of Entry" v-model="entry.yTChannelID">
</div>
</div>
<div class="input-group">
<span class="input-group-label">Description</span>
<input class="input-group-field" type="text" placeholder="Description of Entry" v-model="entry.description">
</div>
<div class="grid-x">
<img class="small-4 cell" :src="entry.thumbnailURL" />
<div class="small-7"></div>
<button type="button" style="max-height:50px" class="button input-group small-1 cell" @click="submit">Submit</button>
</div>
</form>
</transition>
<div class="pageheader">
<h1>Dumb YT Manager</h1>
<p>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!</p>
</div>
<hr />
<h2>Subscribed Channels</h2>
<div id="subbedchannelstable-0"></div>
<div id="addchanel-0"></div>
<hr />
<h2>Videos in DB</h2>
<table id="videostb-0">
<thead>
<tr>
<th>Title</th>
<th>Description</th>
<th>Youtube Video ID</th>
<th>ID</th>
</tr>
</thead>
<tbody>
<tr v-cloak v-for="video in Videos">
<td class="tinytext12px">{{video.title}}</td>
<td class="tinytext12px">{{video.description}}</td>
<td class="tinytext12px">{{video.ytVideoID}}</td>
<td class="tinytext12px">{{video.videoId}}</td>
</tr>
</tbody>
</table>
<div id="videosindbtable-0"></div>
<!-- Compressed JavaScript -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>

View File

@ -16,6 +16,45 @@ var addchanel0 = new Vue({
fail: false,
expanded: false
},
template: `
<div>
<div class="grid-x">
<div class="medium-11 cell"></div>
<div class="medium-1 cell">
<button type="button" class="button input-group" v-on:click='expanded = !expanded'>
<i class="fa fa-plus" aria-hidden="true"></i> Add
</button>
</div>
</div>
<transition name="fade">
<form v-cloak v-if="expanded">
<h2>Add new Channel</h2>
<div class="grid-x">
<div class="input-group medium-6 cell">
<span class="input-group-label">Title</span>
<input class="input-group-field" type="text" placeholder="Title of Entry" v-model="entry.title">
</div>
<div class="input-group medium-1 cell"></div>
<div class="input-group medium-5 cell">
<span class="input-group-label">Channel</span>
<input class="input-group-field" v-bind:class="{ error: fail }" type="text"
@blur="newurl" placeholder="URL of Entry" v-model="entry.yTChannelID">
</div>
</div>
<div class="input-group">
<span class="input-group-label">Description</span>
<input class="input-group-field" type="text" placeholder="Description of Entry" v-model="entry.description">
</div>
<div class="grid-x">
<img class="small-4 cell" :src="entry.thumbnailURL" />
<div class="small-7"></div>
<button type="button" style="max-height:50px" class="button input-group small-1 cell" @click="submit">Submit</button>
</div>
</form>
</transition>
</div>
`,
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: `
<table>
<thead>
<tr>
<th>YT Channel ID</th>
<th>Title</th>
<th>Description</th>
<th>ID</th>
</tr>
</thead>
<tbody>
<tr v-cloak v-for="entry in entries">
<td class="tinytext12px">{{entry.ytChannelID}}</td>
<td class="tinytext12px">{{entry.title}}</td>
<td class="tinytext12px">{{entry.description}}</td>
<td class="tinytext12px">{{entry.channelId}}</td>
</tr>
</tbody>
</table>
`,
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: `
<table>
<thead>
<tr>
<th>Title</th>
<th>Description</th>
<th>Youtube Video ID</th>
<th>Uploaded</th>
<th>ID</th>
</tr>
</thead>
<tbody>
<tr v-cloak v-for="video in Videos">
<td class="tinytext12px">{{video.title}}</td>
<td class="tinytext12px">{{video.description}}</td>
<td class="tinytext12px">{{video.ytVideoID}}</td>
<td class="tinytext12px">{{video.uploaded}}</td>
<td class="tinytext12px">{{video.videoId}}</td>
</tr>
</tbody>
</table>
`,
methods: {
// Get new videos from the web api.
retrieve: function (event) {

View File

@ -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;
}

View File

@ -9,24 +9,14 @@
<link rel="stylesheet" type="text/css" href="index.css">
</head>
<body>
<h1>Dumb YT Manager</h1>
<p>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!</p>
<div class="pageheader">
<h1>Dumb YT Manager</h1>
<p>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!</p>
</div>
<hr />
<h2>Most Recent Videos</h2>
<div v-cloak id="vidholder-0">
<div class="grid-x grid-margin-x imgrow" v-for="row in Videos.Rows">
<div class="card medium-2 large-1 cell" v-for="video in row.Columns">
<div class="card-divider">
<h6>{{video.title}}</h6>
</div>
<img :src="video.thumbnailURL">
<div class="card-section">
<p class="tinytext14px">{{video.description}}</p>
</div>
</div>
</div>
</div>
<div v-cloak id="vidholder-0"></div>
<!-- Compressed JavaScript -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>

View File

@ -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: `
<div>
<div class="grid-x grid-margin-x large-up-6">
<div v-for="video in Videos" class="cell"><div class="card">
<div class="card-divider">
<h6>{{ video.title }}</h6>
</div>
<a :href="video.url"><img :src="video.thumbnailURL"></a>
<div class="card-section">
<p class="tinytext14px">{{ video.description }}</p>
</div>
</div></div>
</div >
</div>
`,
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) {