mirror of
https://github.com/mxpv/podsync.git
synced 2024-05-11 05:55:04 +00:00
Implement download controller
This commit is contained in:
@@ -0,0 +1,35 @@
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Podsync.Services.Links;
|
||||
using Podsync.Services.Resolver;
|
||||
|
||||
namespace Podsync.Controllers
|
||||
{
|
||||
[Route("download")]
|
||||
public class DownloadController : Controller
|
||||
{
|
||||
private readonly IResolverService _resolverService;
|
||||
private readonly ILinkService _linkService;
|
||||
|
||||
public DownloadController(IResolverService resolverService, ILinkService linkService)
|
||||
{
|
||||
_resolverService = resolverService;
|
||||
_linkService = linkService;
|
||||
}
|
||||
|
||||
[Route("{provider}/{videoId}.mp4")]
|
||||
public async Task<IActionResult> Download(Provider provider, string videoId)
|
||||
{
|
||||
var url = _linkService.Make(new LinkInfo
|
||||
{
|
||||
Provider = provider,
|
||||
LinkType = LinkType.Video,
|
||||
Id = videoId
|
||||
});
|
||||
|
||||
var redirectUrl = await _resolverService.Resolve(url);
|
||||
|
||||
return Redirect(redirectUrl.ToString());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -50,9 +50,9 @@ namespace Podsync.Services.Resolver
|
||||
switch (resolveType)
|
||||
{
|
||||
case ResolveType.VideoHigh:
|
||||
return "bestvideo";
|
||||
return "best";
|
||||
case ResolveType.VideoLow:
|
||||
return "worstvideo";
|
||||
return "worst";
|
||||
case ResolveType.AudioHigh:
|
||||
return "bestaudio";
|
||||
case ResolveType.AudioLow:
|
||||
|
||||
@@ -5,6 +5,7 @@ using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Podsync.Services;
|
||||
using Podsync.Services.Links;
|
||||
using Podsync.Services.Resolver;
|
||||
using Podsync.Services.Videos.YouTube;
|
||||
|
||||
namespace Podsync
|
||||
@@ -15,8 +16,8 @@ namespace Podsync
|
||||
{
|
||||
var builder = new ConfigurationBuilder()
|
||||
.SetBasePath(env.ContentRootPath)
|
||||
.AddJsonFile("appsettings.json", optional: true, reloadOnChange: true)
|
||||
.AddJsonFile($"appsettings.{env.EnvironmentName}.json", optional: true)
|
||||
.AddJsonFile("appsettings.json", true, true)
|
||||
.AddJsonFile($"appsettings.{env.EnvironmentName}.json", true)
|
||||
.AddEnvironmentVariables();
|
||||
|
||||
if (env.IsDevelopment())
|
||||
@@ -37,6 +38,7 @@ namespace Podsync
|
||||
// Register core services
|
||||
services.AddSingleton<ILinkService, LinkService>();
|
||||
services.AddSingleton<IYouTubeClient, YouTubeClient>();
|
||||
services.AddSingleton<IResolverService, YtdlWrapper>();
|
||||
|
||||
// Add framework services.
|
||||
services.AddMvc();
|
||||
|
||||
Reference in New Issue
Block a user