Go suck it

This commit is contained in:
Fergal Moran
2018-03-15 20:04:25 +00:00
parent b2931886aa
commit 740824256d
10 changed files with 100 additions and 35 deletions

1
.gitignore vendored
View File

@@ -5,3 +5,4 @@ promotion
.working .working
extension extension
client/tags client/tags
NYoutubeDL

View File

@@ -28,6 +28,10 @@
<div class="block-content"> <div class="block-content">
<button class="btn btn-primary" <button class="btn btn-primary"
(click)="processOrphans()">Process Orphans</button> (click)="processOrphans()">Process Orphans</button>
<button class="btn btn-primary"
(click)="processPlaylists()">Process Playlists</button>
<button class="btn btn-primary"
(click)="updateYouTubeDl()">Update Youtube Downloader</button>
</div> </div>
</div> </div>
</div> </div>

View File

@@ -1,14 +1,14 @@
import { Observable } from 'rxjs/Observable'; import { Observable } from "rxjs/Observable";
import { SignalRService } from 'app/services/signalr.service'; import { SignalRService } from "app/services/signalr.service";
import { Component, OnInit } from '@angular/core'; import { Component, OnInit } from "@angular/core";
import { DebugService } from 'app/services/debug.service'; import { DebugService } from "app/services/debug.service";
import { environment } from 'environments/environment'; import { environment } from "environments/environment";
import { JobsService } from 'app/services/jobs.service'; import { JobsService } from "app/services/jobs.service";
@Component({ @Component({
selector: 'app-debug', selector: "app-debug",
templateUrl: './debug.component.html', templateUrl: "./debug.component.html",
styleUrls: ['./debug.component.css'] styleUrls: ["./debug.component.css"]
}) })
export class DebugComponent implements OnInit { export class DebugComponent implements OnInit {
realtimeMessage: string; realtimeMessage: string;
@@ -17,35 +17,59 @@ export class DebugComponent implements OnInit {
debugInfo$: Observable<string>; debugInfo$: Observable<string>;
apiHost = environment.API_HOST; apiHost = environment.API_HOST;
signalrHost = environment.SIGNALR_HOST; signalrHost = environment.SIGNALR_HOST;
pingPong = ''; pingPong = "";
constructor(private _debugService: DebugService, private _jobsService: JobsService, constructor(
private _signalrService: SignalRService) {} private _debugService: DebugService,
private _jobsService: JobsService,
private _signalrService: SignalRService
) {}
ngOnInit() { ngOnInit() {
this._signalrService this._signalrService
.init(`${environment.SIGNALR_HOST}hubs/debug`) .init(`${environment.SIGNALR_HOST}hubs/debug`)
.then(() => { .then(() => {
this._signalrService.connection.on('Send', data => { this._signalrService.connection.on("Send", data => {
console.log('DebugService', 'signalr', data); console.log("DebugService", "signalr", data);
this.messagesReceived.push(data); this.messagesReceived.push(data);
this.realtimeMessage = ''; this.realtimeMessage = "";
}); });
this.debugInfo$ = this._debugService.getDebugInfo(); this.debugInfo$ = this._debugService.getDebugInfo();
}) })
.catch(err => console.error('debug.component.ts', '_signalrService.init', err)); .catch(err =>
console.error("debug.component.ts", "_signalrService.init", err)
);
this._debugService.ping().subscribe(r => (this.pingPong = r)); this._debugService.ping().subscribe(r => (this.pingPong = r));
} }
sendMessage() { sendMessage() {
this._debugService.sendRealtime(this.realtimeMessage).subscribe(r => console.log(r)); this._debugService
.sendRealtime(this.realtimeMessage)
.subscribe(r => console.log(r));
} }
doSomething() { doSomething() {
alert('doSomething was did'); alert("doSomething was did");
} }
processOrphans(){ processOrphans() {
this._jobsService.processOrphans() this._jobsService
.subscribe(e => console.log('debug.component.ts', 'processOrphans', e)); .processOrphans()
.subscribe(e =>
console.log("debug.component.ts", "processOrphans", e)
);
}
processPlaylists() {
this._jobsService
.processPlaylists()
.subscribe(e =>
console.log("debug.component.ts", "processPlaylists", e)
);
}
updateYouTubeDl() {
this._jobsService
.updateYouTubeDl()
.subscribe(e =>
console.log("debug.component.ts", "updateYouTubeDl", e)
);
} }
} }

View File

@@ -6,9 +6,16 @@ import { environment } from 'environments/environment';
@Injectable() @Injectable()
export class JobsService { export class JobsService {
constructor(private _http: AuthHttp) {} constructor(private _http: AuthHttp) { }
processOrphans(): Observable<Response> { processOrphans(): Observable<Response> {
return this._http.get(environment.API_HOST + '/job/processorphans'); return this._http.get(environment.API_HOST + '/job/processorphans');
} }
processPlaylists(): Observable<Response> {
return this._http.get(environment.API_HOST + '/job/processplaylists');
}
updateYouTubeDl(): Observable<Response> {
return this._http.get(environment.API_HOST + '/job/updateyoutubedl');
}
} }

View File

@@ -4,18 +4,25 @@ using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using PodNoms.Api.Services.Jobs; using PodNoms.Api.Services.Jobs;
namespace PodNoms.Api.Controllers namespace PodNoms.Api.Controllers {
{
[Authorize] [Authorize]
[Route("[controller]")] [Route("[controller]")]
[ApiExplorerSettings(IgnoreApi = true)] [ApiExplorerSettings(IgnoreApi = true)]
public class JobController : Controller public class JobController : Controller {
{
[HttpGet("processorphans")] [HttpGet("processorphans")]
public IActionResult ProcessOrphans() public IActionResult ProcessOrphans() {
{
var infoJobId = BackgroundJob.Enqueue<ClearOrphanAudioJob>(service => service.Execute()); var infoJobId = BackgroundJob.Enqueue<ClearOrphanAudioJob>(service => service.Execute());
return Ok(); return Ok();
} }
[HttpGet("processplaylists")]
public IActionResult ProcessPlaylists() {
var infoJobId = BackgroundJob.Enqueue<ProcessPlaylistsJob>(service => service.Execute());
return Ok();
}
[HttpGet("updateyoutubedl")]
public IActionResult UpdateYouTubeDl() {
var infoJobId = BackgroundJob.Enqueue<UpdateYouTubeDlJob>(service => service.Execute());
return Ok();
}
} }
} }

View File

@@ -16,7 +16,7 @@
<PackageReference Include="AutoMapper" Version="6.2.2" /> <PackageReference Include="AutoMapper" Version="6.2.2" />
<PackageReference Include="AutoMapper.Extensions.Microsoft.DependencyInjection" Version="3.2.0" /> <PackageReference Include="AutoMapper.Extensions.Microsoft.DependencyInjection" Version="3.2.0" />
<PackageReference Include="Handlebars.NetStandard" Version="1.8.1" /> <PackageReference Include="Handlebars.NetStandard" Version="1.8.1" />
<PackageReference Include="NYoutubeDl" Version="0.6.3" /> <PackageReference Include="NYouTubeDl" Version="0.6.3" />
<PackageReference Include="Polly" Version="5.2.0" /> <PackageReference Include="Polly" Version="5.2.0" />
<PackageReference Include="RestSharp" Version="106.1.0" /> <PackageReference Include="RestSharp" Version="106.1.0" />
<PackageReference Include="ImageSharp" Version="1.0.0-*" /> <PackageReference Include="ImageSharp" Version="1.0.0-*" />

View File

@@ -16,7 +16,11 @@ namespace PodNoms.Api.Services.Downloader {
private readonly string _url; private readonly string _url;
private readonly string _downloader; private readonly string _downloader;
public VideoDownloadInfo Properties { get; private set; }
private DownloadInfo _properties;
public VideoDownloadInfo Properties => _properties is VideoDownloadInfo ? (VideoDownloadInfo)_properties : null;
public DownloadInfo RawProperties => _properties;
protected const string DOWNLOADRATESTRING = "iB/s"; protected const string DOWNLOADRATESTRING = "iB/s";
protected const string DOWNLOADSIZESTRING = "iB"; protected const string DOWNLOADSIZESTRING = "iB";
protected const string ETASTRING = "ETA"; protected const string ETASTRING = "ETA";
@@ -55,15 +59,15 @@ namespace PodNoms.Api.Services.Downloader {
await Task.Run(() => { await Task.Run(() => {
var youtubeDl = new YoutubeDL(); var youtubeDl = new YoutubeDL();
youtubeDl.VideoUrl = this._url; youtubeDl.VideoUrl = this._url;
DownloadInfo info = youtubeDl.GetDownloadInfo(); var info = youtubeDl.GetDownloadInfo();
if (info != null && if (info != null &&
(info.Errors.Count == 0 || info.VideoSize != null)) { (info.Errors.Count == 0 || info.VideoSize != null)) {
if (info is PlaylistDownloadInfo) { this._properties = info;
if (info is PlaylistDownloadInfo && ((PlaylistDownloadInfo)info).Videos.Count > 0) {
ret = AudioType.Playlist; ret = AudioType.Playlist;
} else if (info is VideoDownloadInfo) { } else if (info is VideoDownloadInfo) {
ret = AudioType.Valid; ret = AudioType.Valid;
this.Properties = (VideoDownloadInfo)info;
} }
} }
}); });

View File

@@ -27,8 +27,8 @@ namespace PodNoms.Api.Services.Jobs {
var downloader = new AudioDownloader(playlist.SourceUrl, _applicationsSettings.Downloader); var downloader = new AudioDownloader(playlist.SourceUrl, _applicationsSettings.Downloader);
var info = await downloader.GetInfo(); var info = await downloader.GetInfo();
if (info == AudioType.Playlist){ if (info == AudioType.Playlist){
var //var
for (var item in downloader.Properties.) //for (var item in downloader.Properties.)
} }
} }
} }

View File

@@ -0,0 +1,15 @@
using System.Threading.Tasks;
using NYoutubeDL;
using PodNoms.Api.Services.Jobs;
namespace PodNoms.Api.Services.Jobs {
public class UpdateYouTubeDlJob : IJob {
public async Task Execute() {
await Task.Run(() => {
var yt = new YoutubeDL();
yt.Options.GeneralOptions.Update = true;
yt.Download("https://www.youtube.com/watch?v=OJ2wOKDzKyI");
});
}
}
}

3
server/commands Normal file
View File

@@ -0,0 +1,3 @@
get-info
youtube-dl --flat-playlist -i -J -s <url>