From dd4007af263074065f439dc48aa5dfb0c4f2f142 Mon Sep 17 00:00:00 2001 From: Fergal Moran Date: Sun, 12 Nov 2017 20:01:01 +0000 Subject: [PATCH] Fixed yt path error --- docker/nginx/conf.d/podnoms.conf | 10 ++-- server/Controllers/DebugController.cs | 6 ++- server/Dockerfile | 22 +++++--- server/Models/ImageSettings.cs | 4 ++ server/PodNoms.Api.csproj | 2 +- server/Services/Downloader/AudioDownloader.cs | 51 +++++++++++-------- .../Services/Processor/UrlProcessService.cs | 9 ++-- server/Startup.cs | 1 + server/appsettings.json | 3 ++ server/publish.sh | 8 +-- 10 files changed, 69 insertions(+), 47 deletions(-) diff --git a/docker/nginx/conf.d/podnoms.conf b/docker/nginx/conf.d/podnoms.conf index f45927d..07df0ab 100644 --- a/docker/nginx/conf.d/podnoms.conf +++ b/docker/nginx/conf.d/podnoms.conf @@ -14,7 +14,7 @@ server { listen 80; server_name rss.podnoms.com; location / { - proxy_pass http://api:5000/rss/; + proxy_pass http://api/rss/; } } server { @@ -40,7 +40,7 @@ server { } location /rss/ { client_max_body_size 30000M; - proxy_pass http://api:5000/rss/; + proxy_pass http://api/rss/; } location / { try_files $uri$args $uri$args/ /index.html; @@ -50,7 +50,7 @@ server { } location /api/ { client_max_body_size 30000M; - proxy_pass http://api:5000/; + proxy_pass http://api/; } } @@ -71,7 +71,7 @@ server { } location / { - proxy_pass http://api:5000/; + proxy_pass http://api/; proxy_http_version 1.1; proxy_set_header Upgrade $http_upgrade; @@ -95,7 +95,7 @@ server { } location / { - proxy_pass http://api:5000/1466049a-41ba-420e-ac05-25a06bdd1aad/; + proxy_pass http://api/1466049a-41ba-420e-ac05-25a06bdd1aad/; } rewrite ^/1466049a-41ba-420e-ac05-25a06bdd1aad(.*) $1 last; } diff --git a/server/Controllers/DebugController.cs b/server/Controllers/DebugController.cs index 5fde813..596a147 100644 --- a/server/Controllers/DebugController.cs +++ b/server/Controllers/DebugController.cs @@ -21,6 +21,7 @@ namespace PodNoms.Api.Controllers { private readonly StorageSettings _storageSettings; private readonly AudioFileStorageSettings _audioFileStorageSettings; + private readonly ApplicationsSettings _applicationsSettings; private readonly ImageFileStorageSettings _imageFileStorageSettings; private readonly HubLifetimeManager _hubManager; private readonly IUserRepository _userRepository; @@ -29,11 +30,13 @@ namespace PodNoms.Api.Controllers public DebugController(IOptions settings, IOptions appSettings, HubLifetimeManager hubManager, IUserRepository userRepository, + IOptions applicationsSettings, IOptions audioFileStorageSettings, IOptions imageFileStorageSettings) { this._appSettings = appSettings.Value; this._storageSettings = settings.Value; + this._applicationsSettings = applicationsSettings.Value; this._audioFileStorageSettings = audioFileStorageSettings.Value; this._imageFileStorageSettings = imageFileStorageSettings.Value; this._hubManager = hubManager; @@ -49,7 +52,8 @@ namespace PodNoms.Api.Controllers CdnUrl = _storageSettings.CdnUrl, AudioContainer = _audioFileStorageSettings.ContainerName, ImageContainer = _imageFileStorageSettings.ContainerName, - YouTubeDlVersion = AudioDownloader.GetVersion(), + YouTubeDlPath = _applicationsSettings.Downloader, + YouTubeDlVersion = AudioDownloader.GetVersion(_applicationsSettings.Downloader), RssUrl = _appSettings.RssUrl }; return new OkObjectResult(config); diff --git a/server/Dockerfile b/server/Dockerfile index 265fccf..f7229dc 100755 --- a/server/Dockerfile +++ b/server/Dockerfile @@ -1,12 +1,18 @@ -FROM microsoft/aspnetcore:latest +FROM microsoft/aspnetcore-build:2.0 AS build-env WORKDIR /app -COPY out . -RUN apt-get update && apt-get -y upgrade -# RUN pip install --upgrade youtube_dl -RUN curl -L https://yt-dl.org/downloads/latest/youtube-dl -o /usr/local/bin/youtube-dl -RUN chmod a+rx /usr/local/bin/youtube-dl -ENV ASPNETCORE_URLS http://*:5000 -EXPOSE 5000 +# Copy csproj and restore as distinct layers +COPY *.csproj ./ +COPY NuGet.config ./ +RUN dotnet restore +# Copy everything else and build +COPY . ./ +RUN dotnet publish -c Release -o out + +# Build runtime image +FROM fergalmoran/aspnetcore-podnoms +WORKDIR /app + +COPY --from=build-env /app/out . ENTRYPOINT ["dotnet", "PodNoms.Api.dll"] diff --git a/server/Models/ImageSettings.cs b/server/Models/ImageSettings.cs index fa56f86..6c65543 100644 --- a/server/Models/ImageSettings.cs +++ b/server/Models/ImageSettings.cs @@ -22,4 +22,8 @@ namespace PodNoms.Api.Models return AllowedFileTypes.Any(s => s == Path.GetExtension(fileName).ToLower()); } } + public class ApplicationsSettings + { + public string Downloader { get; set; } + } } \ No newline at end of file diff --git a/server/PodNoms.Api.csproj b/server/PodNoms.Api.csproj index 21846be..82b2aa0 100644 --- a/server/PodNoms.Api.csproj +++ b/server/PodNoms.Api.csproj @@ -14,10 +14,10 @@ - + diff --git a/server/Services/Downloader/AudioDownloader.cs b/server/Services/Downloader/AudioDownloader.cs index 7fa692a..e10c95e 100644 --- a/server/Services/Downloader/AudioDownloader.cs +++ b/server/Services/Downloader/AudioDownloader.cs @@ -10,7 +10,8 @@ namespace PodNoms.Api.Services.Downloader { public class AudioDownloader { - private readonly string url; + private readonly string _url; + private readonly string _downloader; public dynamic Properties { get; private set; } protected const string DOWNLOADRATESTRING = "iB/s"; protected const string DOWNLOADSIZESTRING = "iB"; @@ -19,30 +20,38 @@ namespace PodNoms.Api.Services.Downloader public event EventHandler DownloadProgress; public event EventHandler PostProcessing; - public AudioDownloader(string url) + public AudioDownloader(string url, string downloader) { - this.url = url; + this._url = url; + this._downloader = downloader; } - public static string GetVersion() + public static string GetVersion(string downloader) { - var proc = new Process + try { - StartInfo = new ProcessStartInfo + var proc = new Process { - FileName = "youtube-dl", - Arguments = $"--version", - UseShellExecute = false, - RedirectStandardOutput = true, - CreateNoWindow = true + StartInfo = new ProcessStartInfo + { + FileName = downloader, + Arguments = $"--version", + UseShellExecute = false, + RedirectStandardOutput = true, + CreateNoWindow = true + } + }; + var br = new StringBuilder(); + proc.Start(); + while (!proc.StandardOutput.EndOfStream) + { + br.Append(proc.StandardOutput.ReadLine()); } - }; - var br = new StringBuilder(); - proc.Start(); - while (!proc.StandardOutput.EndOfStream) - { - br.Append(proc.StandardOutput.ReadLine()); + return br.ToString(); + } + catch (Exception ex) + { + return $"{{\"Error\": \"{ex.Message}\"}}"; } - return br.ToString(); } public string DownloadAudio(string uid) { @@ -52,8 +61,8 @@ namespace PodNoms.Api.Services.Downloader { StartInfo = new ProcessStartInfo { - FileName = "youtube-dl", - Arguments = $"-o {outputFile} --audio-format mp3 -x \"{this.url}\"", + FileName = this._downloader, + Arguments = $"-o {outputFile} --audio-format mp3 -x \"{this._url}\"", UseShellExecute = false, RedirectStandardOutput = true, CreateNoWindow = true @@ -96,7 +105,7 @@ namespace PodNoms.Api.Services.Downloader StartInfo = new ProcessStartInfo { FileName = "youtube-dl", - Arguments = $"-j {this.url}", + Arguments = $"-j {this._url}", UseShellExecute = false, RedirectStandardOutput = true, CreateNoWindow = true diff --git a/server/Services/Processor/UrlProcessService.cs b/server/Services/Processor/UrlProcessService.cs index d44db0d..cd1a381 100644 --- a/server/Services/Processor/UrlProcessService.cs +++ b/server/Services/Processor/UrlProcessService.cs @@ -24,12 +24,13 @@ namespace PodNoms.Api.Services.Processor private readonly IUnitOfWork _unitOfWork; private readonly IEntryRepository _repository; + public ApplicationsSettings _applicationsSettings { get; } public UrlProcessService(IEntryRepository repository, IUnitOfWork unitOfWork, - IFileUploader fileUploader, IOptions audioStorageSettings, + IFileUploader fileUploader, IOptions applicationsSettings, ILoggerFactory logger, IMapper mapper, IRealTimeUpdater pusher) : base(logger, mapper, pusher) { - ; + this._applicationsSettings = applicationsSettings.Value; this._repository = repository; this._unitOfWork = unitOfWork; } @@ -50,7 +51,7 @@ namespace PodNoms.Api.Services.Processor return false; } - var downloader = new AudioDownloader(entry.SourceUrl); + var downloader = new AudioDownloader(entry.SourceUrl, _applicationsSettings.Downloader); downloader.DownloadInfo(); if (downloader.Properties != null) { @@ -83,7 +84,7 @@ namespace PodNoms.Api.Services.Processor if (entry == null) return false; - var downloader = new AudioDownloader(entry.SourceUrl); + var downloader = new AudioDownloader(entry.SourceUrl, _applicationsSettings.Downloader); var outputFile = Path.Combine(System.IO.Path.GetTempPath(), $"{System.Guid.NewGuid().ToString()}.mp3"); diff --git a/server/Startup.cs b/server/Startup.cs index b107874..c0757fb 100644 --- a/server/Startup.cs +++ b/server/Startup.cs @@ -54,6 +54,7 @@ namespace PodNoms.Api services.AddOptions(); services.Configure(Configuration.GetSection("App")); services.Configure(Configuration.GetSection("Storage")); + services.Configure(Configuration.GetSection("ApplicationsSettings")); services.Configure(Configuration.GetSection("ImageFileStorageSettings")); services.Configure(Configuration.GetSection("AudioFileStorageSettings")); services.Configure(options => diff --git a/server/appsettings.json b/server/appsettings.json index e50e89d..08d2f23 100644 --- a/server/appsettings.json +++ b/server/appsettings.json @@ -27,6 +27,9 @@ //"CdnUrl": "https://podnomscdn.blob.core.windows.net/" "CdnUrl": "https://podnomstempdeleteplease.blob.core.windows.net/" }, + "ApplicationsSettings": { + "Downloader": "/usr/local/bin/youtube-dl" + }, "ImageFileStorageSettings": { "ContainerName": "images", "MaxUploadFileSize": 10485760, diff --git a/server/publish.sh b/server/publish.sh index d2ea3f9..1b21b36 100755 --- a/server/publish.sh +++ b/server/publish.sh @@ -1,11 +1,5 @@ #!/bin/bash unset DOCKER_HOST unset DOCKER_TLS_VERIFY -export ASPNETCORE_ENVIRONMENT=Production -dotnet build -c Release -dotnet ef database update -dotnet publish -c Release -o out -docker build -t fergalmoran/podnoms.api . - -docker push fergalmoran/podnoms.api +docker build --rm -f Dockerfile -t fergalmoran/podnoms.api . \ No newline at end of file