Skip to content

Commit

Permalink
Fix up audio processing
Browse files Browse the repository at this point in the history
  • Loading branch information
fergalmoran committed Nov 12, 2024
1 parent ecc607c commit 802c5c1
Show file tree
Hide file tree
Showing 17 changed files with 1,251 additions and 56 deletions.
4 changes: 3 additions & 1 deletion mixyboos-api/Controllers/AccountController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,9 @@ public async Task<IActionResult> Register([FromBody] RegisterDTO model) {
UserName = model.UserName,
Email = model.UserName,
DisplayName = model.DisplayName,
Title = faker.Name.JobTitle()
Title = faker.Name.JobTitle(),
ProfileImage = faker.Person.Avatar,
HeaderImage = faker.Image.PicsumUrl()
};
var result = await _userManager.CreateAsync(user, model.Password);

Expand Down
14 changes: 10 additions & 4 deletions mixyboos-api/Controllers/MixController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -124,15 +124,21 @@ public async Task<ActionResult<List<MixDTO>>> GetFeed() {
public async Task<ActionResult<MixDTO>> Post([FromBody] MixDTO mix) {
try {
var entity = mix.Adapt<Mix>();
var existing = await _context.Mixes
.AsNoTracking()
.FirstOrDefaultAsync(m => m.Id.Equals(Guid.Parse(mix.Id)));
if (existing is not null) {
//we have a proxy mix from waveform generation
//that completed before the form was submitted
entity.IsProcessed = existing.IsProcessed;
entity.Duration = existing.Duration;
}

var faker = new Faker();
var user = await _userManager.FindByNameAsync(User.Identity.Name);
entity.User = user;
entity.Image = entity.Image ?? faker.Image.LoremFlickrUrl();

//check if the file has been processed
entity.IsProcessed = System.IO.File.Exists(
Path.Combine(_config["AudioProcessing:OutputDir"], entity.Id.ToString(), $"{entity.Id}.m3u8"));

await _context.AddOrUpdate(entity);
await _context.SaveChangesAsync();

Expand Down
7 changes: 6 additions & 1 deletion mixyboos-api/Controllers/UploadController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,11 @@ await scheduler.TriggerJob(
[RequestSizeLimit(AudioFileSizeLimit)] //2Gb
[DisableFormValueModelBinding]
public async Task<IActionResult> UploadAudio([FromRoute] string id, IFormFile file) {
var user = await _userManager.FindByNameAsync(User.Identity.Name);
if (user is null) {
return Unauthorized();
}

var (response, localFile) = await _preProcessUpload(id, file);

if (string.IsNullOrEmpty(localFile)) {
Expand All @@ -106,7 +111,7 @@ public async Task<IActionResult> UploadAudio([FromRoute] string id, IFormFile fi
var jobData = new Dictionary<string, string> {
{"Id", id},
{"FileLocation", localFile},
{"UserId", User.Identity.Name}
{"UserId", user.Id.ToString()}
};
var scheduler = await _schedulerFactory.GetScheduler();
await scheduler.TriggerJob(
Expand Down
4 changes: 4 additions & 0 deletions mixyboos-api/Data/DTO/MixDTO.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ public class MixDTO {
public int PlayCount { get; set; }
public int ShareCount { get; set; }
public int DownloadCount { get; set; }
public long Duration { get; set; }

public string AudioUrl { get; set; }
public string PcmUrl { get; set; }

public string[] Tags { get; set; }
}
22 changes: 8 additions & 14 deletions mixyboos-api/Data/Models/Mix.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#nullable enable

using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using Microsoft.EntityFrameworkCore;
Expand All @@ -9,28 +10,21 @@ namespace MixyBoos.Api.Data.Models;

[Index(nameof(Slug), IsUnique = true)]
public class Mix : BaseEntity, ISluggedEntity {
public Mix() {
Tags = new List<Tag>();
Likes = new List<MixLike>();
Plays = new List<MixPlay>();
Shares = new List<MixShare>();
Downloads = new List<MixDownload>();
}

[Required] public string? Title { get; set; }
[Required] public string? Description { get; set; }
public string? Image { get; set; }
public string? AudioUrl { get; set; }
public bool IsProcessed { get; set; } = false;


public TimeSpan Duration { get; set; }
[Required] public virtual MixyBoosUser? User { get; set; }

public ICollection<MixPlay>? Plays { get; set; }
public ICollection<MixLike>? Likes { get; set; }
public ICollection<MixShare>? Shares { get; set; }
public ICollection<MixDownload>? Downloads { get; set; }
public ICollection<MixPlay>? Plays { get; set; } = new List<MixPlay>();
public ICollection<MixLike>? Likes { get; set; } = new List<MixLike>();
public ICollection<MixShare>? Shares { get; set; } = new List<MixShare>();
public ICollection<MixDownload>? Downloads { get; set; } = new List<MixDownload>();

public ICollection<Tag> Tags { get; }
public ICollection<Tag> Tags { get; } = new List<Tag>();

[SlugField(SourceField = "Title")] public string? Slug { get; set; }
}
5 changes: 4 additions & 1 deletion mixyboos-api/Data/Utils/ImageCacher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,18 @@
using System.Threading.Tasks;
using Bogus;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Logging;
using MixyBoos.Api.Data.Models;
using MixyBoos.Api.Services.Helpers;

namespace MixyBoos.Api.Data.Utils;

public class ImageCacher {
private readonly ILogger<ImageCacher> _logger;
private readonly ImageHelper _imageHelper;

public ImageCacher(ImageHelper imageHelper) {
public ImageCacher(ILogger<ImageCacher> logger, ImageHelper imageHelper) {
_logger = logger;
_imageHelper = imageHelper;
}

Expand Down
Loading

0 comments on commit 802c5c1

Please sign in to comment.