mirror of
https://github.com/zoriya/Kyoo.git
synced 2025-05-30 19:54:16 -04:00
Cleaning up
This commit is contained in:
parent
c8e3e92491
commit
7530d239d9
@ -10,6 +10,7 @@ namespace Kyoo.Controllers
|
|||||||
Library GetLibrary(string librarySlug);
|
Library GetLibrary(string librarySlug);
|
||||||
Collection GetCollection(string slug);
|
Collection GetCollection(string slug);
|
||||||
Show GetShow(string slug);
|
Show GetShow(string slug);
|
||||||
|
Season GetSeason(string showSlug, long seasonNumber);
|
||||||
Episode GetEpisode(string showSlug, long seasonNumber, long episodeNumber);
|
Episode GetEpisode(string showSlug, long seasonNumber, long episodeNumber);
|
||||||
Episode GetMovieEpisode(string movieSlug);
|
Episode GetMovieEpisode(string movieSlug);
|
||||||
Genre GetGenre(string slug);
|
Genre GetGenre(string slug);
|
||||||
@ -18,9 +19,12 @@ namespace Kyoo.Controllers
|
|||||||
|
|
||||||
// Get all
|
// Get all
|
||||||
IEnumerable<Library> GetLibraries();
|
IEnumerable<Library> GetLibraries();
|
||||||
|
IEnumerable<Collection> GetCollections();
|
||||||
IEnumerable<Show> GetShows();
|
IEnumerable<Show> GetShows();
|
||||||
IEnumerable<Episode> GetEpisodes();
|
IEnumerable<Episode> GetEpisodes();
|
||||||
|
IEnumerable<Track> GetTracks();
|
||||||
IEnumerable<Studio> GetStudios();
|
IEnumerable<Studio> GetStudios();
|
||||||
|
IEnumerable<People> GetPeoples();
|
||||||
IEnumerable<Genre> GetGenres();
|
IEnumerable<Genre> GetGenres();
|
||||||
|
|
||||||
// Search
|
// Search
|
||||||
|
@ -33,7 +33,12 @@ namespace Kyoo.Controllers
|
|||||||
{
|
{
|
||||||
return _database.Shows.FirstOrDefault(show => show.Slug == slug);
|
return _database.Shows.FirstOrDefault(show => show.Slug == slug);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Season GetSeason(string showSlug, long seasonNumber)
|
||||||
|
{
|
||||||
|
return _database.Seasons.FirstOrDefault(x => x.Show.Slug == showSlug && x.SeasonNumber == seasonNumber);
|
||||||
|
}
|
||||||
|
|
||||||
public Episode GetEpisode(string showSlug, long seasonNumber, long episodeNumber)
|
public Episode GetEpisode(string showSlug, long seasonNumber, long episodeNumber)
|
||||||
{
|
{
|
||||||
return _database.Episodes.FirstOrDefault(x => x.EpisodeNumber == episodeNumber
|
return _database.Episodes.FirstOrDefault(x => x.EpisodeNumber == episodeNumber
|
||||||
@ -67,10 +72,15 @@ namespace Kyoo.Controllers
|
|||||||
{
|
{
|
||||||
return _database.Libraries;
|
return _database.Libraries;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public IEnumerable<Collection> GetCollections()
|
||||||
|
{
|
||||||
|
return _database.Collections;
|
||||||
|
}
|
||||||
|
|
||||||
public IEnumerable<Show> GetShows()
|
public IEnumerable<Show> GetShows()
|
||||||
{
|
{
|
||||||
return _database.LibraryLinks.AsEnumerable().Select(x => x.Show ?? x.Collection.AsShow());
|
return _database.Shows;
|
||||||
}
|
}
|
||||||
|
|
||||||
public IEnumerable<Episode> GetEpisodes()
|
public IEnumerable<Episode> GetEpisodes()
|
||||||
@ -87,6 +97,17 @@ namespace Kyoo.Controllers
|
|||||||
{
|
{
|
||||||
return _database.Studios;
|
return _database.Studios;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public IEnumerable<People> GetPeoples()
|
||||||
|
{
|
||||||
|
return _database.Peoples;
|
||||||
|
}
|
||||||
|
|
||||||
|
public IEnumerable<Track> GetTracks()
|
||||||
|
{
|
||||||
|
return _database.Tracks;
|
||||||
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region GetHelper
|
#region GetHelper
|
||||||
|
@ -37,7 +37,7 @@ namespace Kyoo.Api
|
|||||||
[Authorize(Policy="Read")]
|
[Authorize(Policy="Read")]
|
||||||
public IEnumerable<Show> GetShows()
|
public IEnumerable<Show> GetShows()
|
||||||
{
|
{
|
||||||
return _libraryManager.GetShows();
|
return _database.LibraryLinks.AsEnumerable().Select(x => x.Show ?? x.Collection.AsShow());
|
||||||
}
|
}
|
||||||
|
|
||||||
[HttpGet("{slug}")]
|
[HttpGet("{slug}")]
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
using System;
|
using Kyoo.Models;
|
||||||
using Kyoo.Models;
|
|
||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
|
using System.Linq;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Kyoo.Controllers;
|
using Kyoo.Controllers;
|
||||||
using Microsoft.AspNetCore.Authorization;
|
using Microsoft.AspNetCore.Authorization;
|
||||||
@ -31,22 +31,21 @@ namespace Kyoo.Api
|
|||||||
Track subtitle = null;
|
Track subtitle = null;
|
||||||
|
|
||||||
if (languageTag != null)
|
if (languageTag != null)
|
||||||
subtitle = _libraryManager.GetSubtitle(showSlug, seasonNumber, episodeNumber, languageTag, forced);
|
subtitle = _libraryManager.GetEpisode(showSlug, seasonNumber, episodeNumber)?.Tracks
|
||||||
|
.FirstOrDefault(x => x.Language == languageTag && x.IsForced == forced);
|
||||||
|
|
||||||
if (subtitle == null)
|
if (subtitle == null)
|
||||||
{
|
{
|
||||||
string idString = identifier.IndexOf('-') != -1 ? identifier.Substring(0, identifier.IndexOf('-')) : identifier;
|
string idString = identifier.IndexOf('-') != -1 ? identifier.Substring(0, identifier.IndexOf('-')) : identifier;
|
||||||
long.TryParse(idString, out long id);
|
long.TryParse(idString, out long id);
|
||||||
subtitle = _libraryManager.GetSubtitleById(id);
|
subtitle = _libraryManager.GetTracks().FirstOrDefault(x => x.ID == id);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (subtitle == null)
|
if (subtitle == null)
|
||||||
return NotFound();
|
return NotFound();
|
||||||
|
|
||||||
if (subtitle.Codec == "subrip" && extension == "vtt") //The request wants a WebVTT from a Subrip subtitle, convert it on the fly and send it.
|
if (subtitle.Codec == "subrip" && extension == "vtt")
|
||||||
{
|
|
||||||
return new ConvertSubripToVtt(subtitle.Path);
|
return new ConvertSubripToVtt(subtitle.Path);
|
||||||
}
|
|
||||||
|
|
||||||
string mime;
|
string mime;
|
||||||
if (subtitle.Codec == "ass")
|
if (subtitle.Codec == "ass")
|
||||||
@ -54,7 +53,7 @@ namespace Kyoo.Api
|
|||||||
else
|
else
|
||||||
mime = "application/x-subrip";
|
mime = "application/x-subrip";
|
||||||
|
|
||||||
//Should use appropriate mime type here
|
// TODO Should use appropriate mime type here
|
||||||
return PhysicalFile(subtitle.Path, mime);
|
return PhysicalFile(subtitle.Path, mime);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -63,15 +62,15 @@ namespace Kyoo.Api
|
|||||||
public async Task<string> ExtractSubtitle(string showSlug, long seasonNumber, long episodeNumber)
|
public async Task<string> ExtractSubtitle(string showSlug, long seasonNumber, long episodeNumber)
|
||||||
{
|
{
|
||||||
Episode episode = _libraryManager.GetEpisode(showSlug, seasonNumber, episodeNumber);
|
Episode episode = _libraryManager.GetEpisode(showSlug, seasonNumber, episodeNumber);
|
||||||
_libraryManager.ClearSubtitles(episode.ID);
|
episode.Tracks = null;
|
||||||
|
|
||||||
Track[] tracks = await _transcoder.ExtractSubtitles(episode.Path);
|
Track[] tracks = await _transcoder.ExtractSubtitles(episode.Path);
|
||||||
foreach (Track track in tracks)
|
foreach (Track track in tracks)
|
||||||
{
|
{
|
||||||
track.EpisodeID = episode.ID;
|
track.EpisodeID = episode.ID;
|
||||||
_libraryManager.RegisterTrack(track);
|
_libraryManager.Register(track);
|
||||||
}
|
}
|
||||||
|
await _libraryManager.SaveChanges();
|
||||||
return "Done. " + tracks.Length + " track(s) extracted.";
|
return "Done. " + tracks.Length + " track(s) extracted.";
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -79,17 +78,18 @@ namespace Kyoo.Api
|
|||||||
[Authorize(Policy="Admin")]
|
[Authorize(Policy="Admin")]
|
||||||
public async Task<string> ExtractSubtitle(string showSlug)
|
public async Task<string> ExtractSubtitle(string showSlug)
|
||||||
{
|
{
|
||||||
IEnumerable<Episode> episodes = _libraryManager.GetEpisodes(showSlug);
|
IEnumerable<Episode> episodes = _libraryManager.GetShow(showSlug).Episodes;
|
||||||
foreach (Episode episode in episodes)
|
foreach (Episode episode in episodes)
|
||||||
{
|
{
|
||||||
_libraryManager.ClearSubtitles(episode.ID);
|
episode.Tracks = null;
|
||||||
|
|
||||||
Track[] tracks = await _transcoder.ExtractSubtitles(episode.Path);
|
Track[] tracks = await _transcoder.ExtractSubtitles(episode.Path);
|
||||||
foreach (Track track in tracks)
|
foreach (Track track in tracks)
|
||||||
{
|
{
|
||||||
track.EpisodeID = episode.ID;
|
track.EpisodeID = episode.ID;
|
||||||
_libraryManager.RegisterTrack(track);
|
_libraryManager.Register(track);
|
||||||
}
|
}
|
||||||
|
await _libraryManager.SaveChanges();
|
||||||
}
|
}
|
||||||
|
|
||||||
return "Done.";
|
return "Done.";
|
||||||
|
Loading…
x
Reference in New Issue
Block a user