Finishing the database creation of episodes and starting the creation of the web app.

This commit is contained in:
Zoe Roux 2019-08-10 00:13:38 +02:00
parent 9200c2b00e
commit b821679fa8
9 changed files with 22 additions and 143 deletions

View File

@ -1,10 +1,8 @@
<div class='container-fluid'> <nav class="navbar navbar-expand-lg navbar-dark bg-dark">
<div class='row'> <a class="navbar-brand" href="#">
<div class='col-sm-3'> <img src="/docs/4.3/assets/brand/bootstrap-solid.svg" width="30" height="30" alt="">
<app-nav-menu></app-nav-menu> </a>
</div> </nav>
<div class='col-sm-9 body-content'>
<router-outlet></router-outlet>
</div> <router-outlet></router-outlet>
</div>
</div>

View File

@ -5,7 +5,6 @@ import { HttpClientModule } from '@angular/common/http';
import { RouterModule } from '@angular/router'; import { RouterModule } from '@angular/router';
import { AppComponent } from './app.component'; import { AppComponent } from './app.component';
import { NavMenuComponent } from './nav-menu/nav-menu.component';
import { HomeComponent } from './home/home.component'; import { HomeComponent } from './home/home.component';
import { CounterComponent } from './counter/counter.component'; import { CounterComponent } from './counter/counter.component';
import { FetchDataComponent } from './fetch-data/fetch-data.component'; import { FetchDataComponent } from './fetch-data/fetch-data.component';
@ -13,7 +12,6 @@ import { FetchDataComponent } from './fetch-data/fetch-data.component';
@NgModule({ @NgModule({
declarations: [ declarations: [
AppComponent, AppComponent,
NavMenuComponent,
HomeComponent, HomeComponent,
CounterComponent, CounterComponent,
FetchDataComponent FetchDataComponent

View File

@ -1,59 +0,0 @@
li .glyphicon {
margin-right: 10px;
}
/* Highlighting rules for nav menu items */
li.link-active a,
li.link-active a:hover,
li.link-active a:focus {
background-color: #4189C7;
color: white;
}
/* Keep the nav menu independent of scrolling and on top of other items */
.main-nav {
position: fixed;
top: 0;
left: 0;
right: 0;
z-index: 1;
}
@media (min-width: 768px) {
/* On small screens, convert the nav menu to a vertical sidebar */
.main-nav {
height: 100%;
width: calc(25% - 20px);
}
.navbar {
border-radius: 0px;
border-width: 0px;
height: 100%;
}
.navbar-header {
float: none;
}
.navbar-collapse {
border-top: 1px solid #444;
padding: 0px;
}
.navbar ul {
float: none;
}
.navbar li {
float: none;
font-size: 15px;
margin: 6px;
}
.navbar li a {
padding: 10px 16px;
border-radius: 4px;
}
.navbar a {
/* If a menu item's text is too long, truncate it */
width: 100%;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
}
}

View File

@ -1,33 +0,0 @@
<div class='main-nav'>
<div class='navbar navbar-inverse'>
<div class='navbar-header'>
<button type='button' class='navbar-toggle' data-toggle='collapse' data-target='.navbar-collapse' [attr.aria-expanded]='isExpanded' (click)='toggle()'>
<span class='sr-only'>Toggle navigation</span>
<span class='icon-bar'></span>
<span class='icon-bar'></span>
<span class='icon-bar'></span>
</button>
<a class='navbar-brand' [routerLink]='["/"]'>Kyoo</a>
</div>
<div class='clearfix'></div>
<div class='navbar-collapse collapse' [ngClass]='{ "in": isExpanded }'>
<ul class='nav navbar-nav'>
<li [routerLinkActive]='["link-active"]' [routerLinkActiveOptions]='{ exact: true }'>
<a [routerLink]='["/"]' (click)='collapse()'>
<span class='glyphicon glyphicon-home'></span> Home
</a>
</li>
<li [routerLinkActive]='["link-active"]'>
<a [routerLink]='["/counter"]' (click)='collapse()'>
<span class='glyphicon glyphicon-education'></span> Counter
</a>
</li>
<li [routerLinkActive]='["link-active"]'>
<a [routerLink]='["/fetch-data"]' (click)='collapse()'>
<span class='glyphicon glyphicon-th-list'></span> Fetch data
</a>
</li>
</ul>
</div>
</div>
</div>

View File

@ -1,18 +0,0 @@
import { Component } from '@angular/core';
@Component({
selector: 'app-nav-menu',
templateUrl: './nav-menu.component.html',
styleUrls: ['./nav-menu.component.css']
})
export class NavMenuComponent {
isExpanded = false;
collapse() {
this.isExpanded = false;
}
toggle() {
this.isExpanded = !this.isExpanded;
}
}

View File

@ -48,8 +48,6 @@ namespace Kyoo.InternalAPI
{ {
if(IsVideo(file) && !libraryManager.IsEpisodeRegistered(file)) if(IsVideo(file) && !libraryManager.IsEpisodeRegistered(file))
{ {
Debug.WriteLine("&Should insert this: " + file);
string patern = config.GetValue<string>("regex"); string patern = config.GetValue<string>("regex");
Regex regex = new Regex(patern, RegexOptions.IgnoreCase); Regex regex = new Regex(patern, RegexOptions.IgnoreCase);
Match match = regex.Match(file); Match match = regex.Match(file);
@ -59,12 +57,9 @@ namespace Kyoo.InternalAPI
bool seasonSuccess = long.TryParse(match.Groups["Season"].Value, out long seasonNumber); bool seasonSuccess = long.TryParse(match.Groups["Season"].Value, out long seasonNumber);
bool episodeSucess = long.TryParse(match.Groups["Episode"].Value, out long episodeNumber); bool episodeSucess = long.TryParse(match.Groups["Episode"].Value, out long episodeNumber);
Debug.WriteLine("&ShowPath: " + showPath + " Show: " + showName + " season: " + seasonNumber + " episode: " + episodeNumber);
string showProviderIDs; string showProviderIDs;
if (!libraryManager.IsShowRegistered(showPath, out long showID)) if (!libraryManager.IsShowRegistered(showPath, out long showID))
{ {
Debug.WriteLine("&Should register show: " + showName);
Show show = await metadataProvider.GetShowFromName(showName, showPath); Show show = await metadataProvider.GetShowFromName(showName, showPath);
showProviderIDs = show.ExternalIDs; showProviderIDs = show.ExternalIDs;
showID = libraryManager.RegisterShow(show); showID = libraryManager.RegisterShow(show);
@ -72,18 +67,13 @@ namespace Kyoo.InternalAPI
else else
showProviderIDs = libraryManager.GetShowExternalIDs(showID); showProviderIDs = libraryManager.GetShowExternalIDs(showID);
Debug.WriteLine("&Show ID: " + showID);
if(!libraryManager.IsSeasonRegistered(showID, seasonNumber, out long seasonID)) if(!libraryManager.IsSeasonRegistered(showID, seasonNumber, out long seasonID))
{ {
Debug.WriteLine("&Should register season: " + showName + " - " + seasonNumber);
Season season = await metadataProvider.GetSeason(showName, seasonNumber); Season season = await metadataProvider.GetSeason(showName, seasonNumber);
season.ShowID = showID; season.ShowID = showID;
showID = libraryManager.RegisterSeason(season); seasonID = libraryManager.RegisterSeason(season);
} }
Debug.WriteLine("&Season ID: " + seasonID);
Episode episode = await metadataProvider.GetEpisode(showProviderIDs, seasonNumber, episodeNumber); Episode episode = await metadataProvider.GetEpisode(showProviderIDs, seasonNumber, episodeNumber);
episode.ShowID = showID; episode.ShowID = showID;
episode.SeasonID = seasonID; episode.SeasonID = seasonID;

View File

@ -261,7 +261,6 @@ namespace Kyoo.InternalAPI
public long RegisterShow(Show show) public long RegisterShow(Show show)
{ {
string query = "INSERT INTO shows (slug, title, aliases, path, overview, genres, startYear, endYear, imgPrimary, imgThumb, imgLogo, imgBackdrop, externalIDs) VALUES($slug, $title, $aliases, $path, $overview, $genres, $startYear, $endYear, $imgPrimary, $imgThumb, $imgLogo, $imgBackdrop, $externalIDs);"; string query = "INSERT INTO shows (slug, title, aliases, path, overview, genres, startYear, endYear, imgPrimary, imgThumb, imgLogo, imgBackdrop, externalIDs) VALUES($slug, $title, $aliases, $path, $overview, $genres, $startYear, $endYear, $imgPrimary, $imgThumb, $imgLogo, $imgBackdrop, $externalIDs);";
Debug.WriteLine("&SQL QUERY:: " + query);
using (SQLiteCommand cmd = new SQLiteCommand(query, sqlConnection)) using (SQLiteCommand cmd = new SQLiteCommand(query, sqlConnection))
{ {
cmd.Parameters.AddWithValue("slug", show.Slug); cmd.Parameters.AddWithValue("slug", show.Slug);
@ -288,7 +287,6 @@ namespace Kyoo.InternalAPI
public long RegisterSeason(Season season) public long RegisterSeason(Season season)
{ {
string query = "INSERT INTO seasons (showID, seasonNumber, title, overview, year, imgPrimary, externalIDs) VALUES($showID, $seasonNumber, $title, $overview, $year, $imgPrimary, $externalIDs);"; string query = "INSERT INTO seasons (showID, seasonNumber, title, overview, year, imgPrimary, externalIDs) VALUES($showID, $seasonNumber, $title, $overview, $year, $imgPrimary, $externalIDs);";
Debug.WriteLine("&SQL QUERY:: " + query);
using (SQLiteCommand cmd = new SQLiteCommand(query, sqlConnection)) using (SQLiteCommand cmd = new SQLiteCommand(query, sqlConnection))
{ {
cmd.Parameters.AddWithValue("$showID", season.ShowID); cmd.Parameters.AddWithValue("$showID", season.ShowID);
@ -308,7 +306,6 @@ namespace Kyoo.InternalAPI
public long RegisterEpisode(Episode episode) public long RegisterEpisode(Episode episode)
{ {
string query = "INSERT INTO episodes (showID, seasonID, episodeNumber, title, overview, releaseDate, runtime, imgPrimary, externalIDs) VALUES($showID, $seasonID, $episodeNumber, $title, $overview, $releaseDate, $runtime, $imgPrimary, $externalIDs);"; string query = "INSERT INTO episodes (showID, seasonID, episodeNumber, title, overview, releaseDate, runtime, imgPrimary, externalIDs) VALUES($showID, $seasonID, $episodeNumber, $title, $overview, $releaseDate, $runtime, $imgPrimary, $externalIDs);";
Debug.WriteLine("&SQL QUERY:: " + query);
using (SQLiteCommand cmd = new SQLiteCommand(query, sqlConnection)) using (SQLiteCommand cmd = new SQLiteCommand(query, sqlConnection))
{ {
cmd.Parameters.AddWithValue("$showID", episode.ShowID); cmd.Parameters.AddWithValue("$showID", episode.ShowID);

View File

@ -4,6 +4,7 @@ using Newtonsoft.Json;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Diagnostics; using System.Diagnostics;
using System.Globalization;
using System.IO; using System.IO;
using System.Linq; using System.Linq;
using System.Net; using System.Net;
@ -122,7 +123,7 @@ namespace Kyoo.InternalAPI.MetadataProvider
GetYear(data.firstAired), GetYear(data.firstAired),
null, //endYear null, //endYear
string.Format("{0}={1}|", Provider, data.id)); string.Format("{0}={1}|", Provider, data.id));
return await GetShowByID(GetID(show.ExternalIDs)) ?? show; return (await GetShowByID(GetID(show.ExternalIDs))).Set(show.Slug, show.Path) ?? show;
} }
} }
else else
@ -268,8 +269,6 @@ namespace Kyoo.InternalAPI.MetadataProvider
return null; return null;
} }
public async Task<Episode> GetEpisode(string externalIDs, long seasonNumber, long episodeNumber) public async Task<Episode> GetEpisode(string externalIDs, long seasonNumber, long episodeNumber)
{ {
string id = GetID(externalIDs); string id = GetID(externalIDs);
@ -282,8 +281,8 @@ namespace Kyoo.InternalAPI.MetadataProvider
if (token == null) if (token == null)
return null; return null;
long page = episodeNumber / 100 + 1; int page = (int)episodeNumber / 100 + 1;
long index = episodeNumber % 100; int index = (int)episodeNumber % 100;
WebRequest request = WebRequest.Create("https://api.thetvdb.com/series/" + id + "/episodes?page=" + page); WebRequest request = WebRequest.Create("https://api.thetvdb.com/series/" + id + "/episodes?page=" + page);
request.Method = "GET"; request.Method = "GET";
@ -307,8 +306,8 @@ namespace Kyoo.InternalAPI.MetadataProvider
dynamic data = JsonConvert.DeserializeObject(content); dynamic data = JsonConvert.DeserializeObject(content);
dynamic episode = data.data[index]; dynamic episode = data.data[index];
Debug.WriteLine("&Date: " + (string)episode.firstAired); DateTime dateTime = DateTime.ParseExact((string)episode.firstAired, "yyyy-MM-dd", CultureInfo.InvariantCulture);
return new Episode(episodeNumber, episode.episodeName, episode.overview, DateTime.Parse(episode.firstAired), -1, "https://www.thetvdb.com/banners/" + episode.filename, string.Format("TvDB={0}|", episode.id)); return new Episode(episodeNumber, (string)episode.episodeName, (string)episode.overview, dateTime, -1, "https://www.thetvdb.com/banners/" + episode.filename, string.Format("TvDB={0}|", episode.id));
} }
} }
else else

View File

@ -91,6 +91,13 @@ namespace Kyoo.Models
reader["imgBackdrop"] as string, reader["imgBackdrop"] as string,
reader["externalIDs"] as string); reader["externalIDs"] as string);
} }
public Show Set(string slug, string path)
{
Slug = slug;
Path = path;
return this;
}
} }
public enum Status { Finished, Airing } public enum Status { Finished, Airing }