Preparing the api for watch calls.

This commit is contained in:
Zoe Roux 2019-09-02 23:17:57 +02:00
parent 8d063489d9
commit db6deddbd2
10 changed files with 54 additions and 18 deletions

View File

@ -13,8 +13,8 @@ import { StreamResolverService } from "./services/stream-resolver.service";
const routes: Routes = [
{ path: "browse", component: BrowseComponent, pathMatch: "full", resolve: { shows: LibraryResolverService } },
{ path: "browse/:library-slug", component: BrowseComponent, resolve: { shows: LibraryResolverService } },
{ path: "shows/:show-slug", component: ShowDetailsComponent, resolve: { show: ShowResolverService } },
{ path: "watch/:show-slug/s:season-number/e:episode-number", component: PlayerComponent, resolve: { show: StreamResolverService } },
{ path: "show/:show-slug", component: ShowDetailsComponent, resolve: { show: ShowResolverService } },
{ path: "watch/:item", component: PlayerComponent, resolve: { show: StreamResolverService } },
{ path: "**", component: NotFoundComponent }
];

View File

@ -1,4 +1,4 @@
<header style="height: 68px;">
<header id="nav" style="height: 68px;">
<div class="fixed-top">
<nav id="toolbar" class="navbar navbar-dark bg-secondary">
<a class="navbar-brand nav-item ml-3" routerLink="/">

View File

@ -1,5 +1,5 @@
<div class="container justify-content-center">
<a class="show" *ngFor="let show of this.shows" routerLink="/shows/{{show.slug}}">
<a class="show" *ngFor="let show of this.shows" routerLink="/show/{{show.slug}}">
<img [style.background-image]="getThumb(show.slug)"/>
<p class="title">{{show.title}}</p>
<p class="date" *ngIf="show.endYear; else elseBlock">{{show.startYear}} - {{show.endYear}}</p>

View File

@ -2,7 +2,7 @@
<div class="episodes" id="episodes">
<div class="episode" *ngFor="let episode of this.episodes" id="el-{{episode.episodeNumber}}">
<div class="img" [style.background-image]="sanitize(episode.thumb, true)">
<button mat-icon-button class="playBtn" ><i class="material-icons playIcon">play_circle_outline</i></button>
<button mat-icon-button class="playBtn" routerLink="/watch/{{this.showSlug}}-s{{episode.seasonNumber}}e{{episode.episodeNumber}}"><i class="material-icons playIcon">play_circle_outline</i></button>
</div>
<h6 *ngIf="episode.seasonNumber != 0; else elseBlock;" class="title">S{{episode.seasonNumber}}:E{{episode.episodeNumber}} - {{episode.title}}</h6>
<ng-template #elseBlock><h6 class="title">{{episode.title}}</h6></ng-template>

View File

@ -10,6 +10,7 @@ import { DomSanitizer } from "@angular/platform-browser";
export class EpisodesListComponent implements OnInit
{
@Input() episodes: Episode[];
@Input() showSlug: string;
private root: HTMLElement;
constructor(private sanitizer: DomSanitizer) { }

View File

@ -9,7 +9,13 @@ export class PlayerComponent implements OnInit {
constructor() { }
ngOnInit() {
ngOnInit()
{
document.getElementById("nav").classList.add("d-none");
}
ngOnDestroy()
{
document.getElementById("nav").classList.remove("d-none");
}
}

View File

@ -14,15 +14,13 @@ export class StreamResolverService implements Resolve<Show>
resolve(route: ActivatedRouteSnapshot): Show | Observable<Show> | Promise<Show>
{
let slug: string = route.paramMap.get("show-slug");
let season: number = parseInt(route.paramMap.get("season-number"));
let episode: number = parseInt(route.paramMap.get("episode-number"));
return this.http.get<Show>("api/watch/" + slug + "/s" + season + "/e" + episode).pipe(catchError((error: HttpErrorResponse) =>
let item: string = route.paramMap.get("item");
return this.http.get<Show>("api/watch/" + item).pipe(catchError((error: HttpErrorResponse) =>
{
console.log(error.status + " - " + error.message);
if (error.status == 404)
{
this.snackBar.open("Can't find this episode \"" + slug + "S" + season + ":E" + episode + "\" not found.", null, { horizontalPosition: "left", panelClass: ['snackError'], duration: 2500 });
this.snackBar.open("Episode \"" + item + "\" not found.", null, { horizontalPosition: "left", panelClass: ['snackError'], duration: 2500 });
}
else
{

View File

@ -73,7 +73,7 @@
</mat-select>
</mat-form-field>
</div>
<app-episodes-list [episodes]="episodes"></app-episodes-list>
<app-episodes-list [showSlug]="this.show.slug" [episodes]="episodes"></app-episodes-list>
<div class="container-fluid mt-5">
<h3>Staff</h3>

View File

@ -1,11 +1,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Kyoo.InternalAPI;
using Kyoo.InternalAPI;
using Kyoo.Models;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using System.Collections.Generic;
namespace Kyoo.Controllers
{

View File

@ -0,0 +1,35 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Threading.Tasks;
using Kyoo.InternalAPI;
using Kyoo.Models;
using Microsoft.AspNetCore.Mvc;
// For more information on enabling MVC for empty projects, visit https://go.microsoft.com/fwlink/?LinkID=397860
namespace Kyoo.Controllers
{
[Route("api/[controller]")]
public class WatchController : Controller
{
private readonly ILibraryManager libraryManager;
public WatchController(ILibraryManager libraryManager)
{
this.libraryManager = libraryManager;
}
[HttpGet("{showSlug}-s{seasonNumber}e{episodeNumber}")]
public IActionResult Index(string showSlug, long seasonNumber, long episodeNumber)
{
Debug.WriteLine("&Trying to watch " + showSlug + " season " + seasonNumber + " episode " + episodeNumber);
Episode episode = libraryManager.GetEpisode(showSlug, seasonNumber, episodeNumber);
return NotFound();
}
}
}