Readding the image redownloader & adding a sub extract button

This commit is contained in:
Zoe Roux 2021-02-05 14:50:36 +01:00
parent 0594104153
commit 79b0e57b82
3 changed files with 65 additions and 50 deletions

View File

@ -46,7 +46,8 @@
<mat-menu #showMenu="matMenu"> <mat-menu #showMenu="matMenu">
<button mat-menu-item (click)="editMetadata()">Edit metadata</button> <button mat-menu-item (click)="editMetadata()">Edit metadata</button>
<button mat-menu-item (click)="redownloadImages()">Redownload images</button> <button mat-menu-item (click)="redownloadImages()">Re-download images</button>
<button mat-menu-item (click)="extractSubs()">Re-extract subtitles</button>
</mat-menu> </mat-menu>
<div class="row pt-3 d-md-none"> <div class="row pt-3 d-md-none">

View File

@ -1,27 +1,28 @@
import { AfterViewInit, Component } from "@angular/core"; import { AfterViewInit, Component, OnDestroy } from "@angular/core";
import { MatSnackBar } from "@angular/material/snack-bar"; import { MatSnackBar } from "@angular/material/snack-bar";
import { DomSanitizer, Title } from "@angular/platform-browser"; import { DomSanitizer, SafeStyle, Title } from "@angular/platform-browser";
import {ActivatedRoute, Router} from '@angular/router'; import { ActivatedRoute, Router } from "@angular/router";
import { Episode } from "../../models/resources/episode"; import { Episode } from "../../models/resources/episode";
import { Show } from "../../models/resources/show"; import { Show } from "../../models/resources/show";
import {MatDialog} from "@angular/material/dialog"; import { MatDialog } from "@angular/material/dialog";
import {TrailerDialogComponent} from "../trailer-dialog/trailer-dialog.component"; import { TrailerDialogComponent } from "../trailer-dialog/trailer-dialog.component";
import {MetadataEditComponent} from "../metadata-edit/metadata-edit.component"; import { MetadataEditComponent } from "../metadata-edit/metadata-edit.component";
import {Season} from "../../models/resources/season"; import { Season } from "../../models/resources/season";
import {EpisodeService, PeopleService, SeasonService} from "../../services/api.service"; import { EpisodeService, PeopleService, SeasonService } from "../../services/api.service";
import {Page} from "../../models/page"; import { Page } from "../../models/page";
import {People} from "../../models/resources/people"; import { People } from "../../models/resources/people";
import { HttpClient } from "@angular/common/http";
@Component({ @Component({
selector: 'app-show-details', selector: "app-show-details",
templateUrl: './show-details.component.html', templateUrl: "./show-details.component.html",
styleUrls: ['./show-details.component.scss'] styleUrls: ["./show-details.component.scss"]
}) })
export class ShowDetailsComponent implements AfterViewInit export class ShowDetailsComponent implements AfterViewInit, OnDestroy
{ {
show: Show; show: Show;
seasons: Season[]; seasons: Season[];
season: number = 1; season = 1;
episodes: Page<Episode>[] = []; episodes: Page<Episode>[] = [];
people: Page<People>; people: Page<People>;
@ -35,13 +36,14 @@ export class ShowDetailsComponent implements AfterViewInit
private title: Title, private title: Title,
private router: Router, private router: Router,
private dialog: MatDialog, private dialog: MatDialog,
private http: HttpClient,
private seasonService: SeasonService, private seasonService: SeasonService,
private episodeService: EpisodeService, private episodeService: EpisodeService,
private peopleService: PeopleService) private peopleService: PeopleService)
{ {
this.route.queryParams.subscribe(params => this.route.queryParams.subscribe(params =>
{ {
this.season = params["season"] ?? 1; this.season = params.season ?? 1;
}); });
this.route.data.subscribe(data => this.route.data.subscribe(data =>
@ -51,22 +53,23 @@ export class ShowDetailsComponent implements AfterViewInit
this.peopleService.getFromShow(this.show.slug).subscribe(x => this.people = x); this.peopleService.getFromShow(this.show.slug).subscribe(x => this.people = x);
if (this.show.isMovie) if (this.show.isMovie) {
return; return;
}
this.seasonService.getForShow(this.show.slug, {limit: 0}).subscribe(x => this.seasonService.getForShow(this.show.slug, {limit: 0}).subscribe(x =>
{ {
this.seasons = x.items; this.seasons = x.items;
if (x.items.find(x => x.seasonNumber == this.season) == null) if (x.items.find(y => y.seasonNumber === this.season) == null)
{ {
this.season = 1; this.season = 1;
this.getEpisodes(1); this.getEpisodes(1);
} }
}); });
this.getEpisodes(this.season);}); this.getEpisodes(this.season); });
} }
ngAfterViewInit() ngAfterViewInit(): void
{ {
this.scrollZone = document.getElementById("main"); this.scrollZone = document.getElementById("main");
this.toolbar = document.getElementById("toolbar"); this.toolbar = document.getElementById("toolbar");
@ -77,7 +80,7 @@ export class ShowDetailsComponent implements AfterViewInit
this.scrollZone.addEventListener("scroll", () => this.scroll()); this.scrollZone.addEventListener("scroll", () => this.scroll());
} }
ngOnDestroy() ngOnDestroy(): void
{ {
this.title.setTitle("Kyoo"); this.title.setTitle("Kyoo");
this.toolbar.setAttribute("style", `background-color: #000000 !important`); this.toolbar.setAttribute("style", `background-color: #000000 !important`);
@ -86,31 +89,30 @@ export class ShowDetailsComponent implements AfterViewInit
this.scrollZone.removeEventListener("scroll", () => this.scroll()); this.scrollZone.removeEventListener("scroll", () => this.scroll());
} }
scroll() scroll(): void
{ {
let opacity: number = 2 * this.scrollZone.scrollTop / this.backdrop.clientHeight; const opacity: number = 2 * this.scrollZone.scrollTop / this.backdrop.clientHeight;
this.toolbar.setAttribute("style", `background-color: rgba(0, 0, 0, ${opacity}) !important`); this.toolbar.setAttribute("style", `background-color: rgba(0, 0, 0, ${opacity}) !important`);
}; }
getThumb(slug: string) getThumb(slug: string): SafeStyle
{ {
return this.sanitizer.bypassSecurityTrustStyle("url(/poster/" + slug + ")"); return this.sanitizer.bypassSecurityTrustStyle("url(/poster/" + slug + ")");
} }
playClicked() playClicked(): void
{ {
if (this.show.isMovie) if (this.show.isMovie) {
this.router.navigate(["/watch/" + this.show.slug]); this.router.navigate(["/watch/" + this.show.slug]);
else }
else {
this.router.navigate(["/watch/" + this.show.slug + "-s1e1"]); this.router.navigate(["/watch/" + this.show.slug + "-s1e1"]);
} }
}
getEpisodes(season: number) getEpisodes(season: number): void
{ {
if (season < 0) if (season < 0 || this.episodes[season])
return;
if (this.episodes[season] != undefined)
return; return;
this.episodeService.getFromSeasonNumber(this.show.slug, this.season).subscribe(x => this.episodeService.getFromSeasonNumber(this.show.slug, this.season).subscribe(x =>
@ -119,26 +121,44 @@ export class ShowDetailsComponent implements AfterViewInit
}); });
} }
openTrailer() openTrailer(): void
{ {
this.dialog.open(TrailerDialogComponent, {width: "80%", height: "45vw", data: this.show.trailerUrl, panelClass: "panel"}); this.dialog.open(TrailerDialogComponent, {width: "80%", height: "45vw", data: this.show.trailerUrl, panelClass: "panel"});
} }
editMetadata() editMetadata(): void
{ {
this.dialog.open(MetadataEditComponent, {width: "80%", data: this.show}).afterClosed().subscribe((result: Show) => this.dialog.open(MetadataEditComponent, {width: "80%", data: this.show}).afterClosed().subscribe((result: Show) =>
{ {
if (result) if (result) {
this.show = result; this.show = result;
}
}); });
} }
redownloadImages() redownloadImages(): void
{ {
// this.http.post("api/show/download-images/" + this.show.slug, undefined).subscribe(() => { }, error => this.http.put(`api/task/extract/show/${this.show.slug}/thumbnails`, undefined).subscribe(() => { }, error =>
// { {
// console.log(error.status + " - " + error.message); console.log(error.status + " - " + error.message);
// this.snackBar.open("An unknown error occured while re-downloading images.", null, { horizontalPosition: "left", panelClass: ['snackError'], duration: 2500 }); this.snackBar.open("An unknown error occurred while re-downloading images.", null, {
// }); horizontalPosition: "left",
panelClass: ["snackError"],
duration: 2500
});
});
}
extractSubs(): void
{
this.http.put(`api/task/extract/show/${this.show.slug}/subs`, undefined).subscribe(() => { }, error =>
{
console.log(error.status + " - " + error.message);
this.snackBar.open("An unknown error occurred while re-downloading images.", null, {
horizontalPosition: "left",
panelClass: ["snackError"],
duration: 2500
});
});
} }
} }

View File

@ -12,17 +12,11 @@
}, },
"array-type": false, "array-type": false,
"arrow-return-shorthand": true, "arrow-return-shorthand": true,
"curly": true,
"deprecation": { "deprecation": {
"severity": "warning" "severity": "warning"
}, },
"eofline": true, "eofline": true,
"import-spacing": true, "import-spacing": true,
"indent": {
"options": [
"tabs"
]
},
"max-classes-per-file": false, "max-classes-per-file": false,
"max-line-length": [ "max-line-length": [
true, true,