Implement download controller

This commit is contained in:
Maksym Pavlenko
2016-11-08 14:45:18 -08:00
parent c39dd14cc3
commit d9dd677329
3 changed files with 41 additions and 4 deletions
@@ -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());
}
}
}
+2 -2
View File
@@ -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:
+4 -2
View File
@@ -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();