Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add playlist media options #421

Merged
merged 2 commits into from
Dec 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 45 additions & 4 deletions ClassTranscribeServer/Controllers/MediaController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,10 @@ public async Task<ActionResult<MediaDTO>> GetMedia(string id)

return new ChallengeResult();
}

var playlist = await _context.Playlists.FindAsync(media.PlaylistId);
//unused var v = await _context.Videos.FindAsync(media.VideoId);
var user = await _userUtils.GetUser(User);

var restrict = (bool?) playlist.getOptionsAsJson()[ "restrictRoomStream"] ?? false;
var mediaDTO = new MediaDTO
{
Id = media.Id,
Expand All @@ -71,6 +71,7 @@ public async Task<ActionResult<MediaDTO>> GetMedia(string id)
SourceType = media.SourceType,
Duration = media.Video.Duration,
PublishStatus = media.PublishStatus,
Options = media.getOptionsAsJson(),
Transcriptions = media.Video.Transcriptions
.Select(t => new TranscriptionDTO
{
Expand All @@ -84,7 +85,7 @@ public async Task<ActionResult<MediaDTO>> GetMedia(string id)
{
Id = media.Video.Id,
Video1Path = media.Video.ProcessedVideo1?.Path != null ? media.Video.ProcessedVideo1.Path : media.Video.Video1?.Path,
Video2Path = media.Video.ProcessedVideo2?.Path != null ? media.Video.ProcessedVideo2.Path : media.Video.Video2?.Path,
Video2Path = restrict ? null: media.Video.ProcessedVideo2?.Path != null ? media.Video.ProcessedVideo2.Path : media.Video.Video2?.Path,
ASLPath = media.Video.ASLVideo?.Path,
TaskLog = media.Video.TaskLog
},
Expand Down Expand Up @@ -158,6 +159,44 @@ public async Task<IActionResult> PutJsonMetaData(JObject jsonMetaData, string id
return NoContent();
}

// PUT: api/Media/5
[HttpPut("Option/{id}/{option}/{type}/{value}")]
[Authorize]
public async Task<IActionResult> PutMediaOption(string id, string option, string type,string value)
{
if(id == null) return BadRequest("id not specified");
if(type == null || ! "|int|bool|string|".Contains($"|{type}|")) {
return BadRequest("type must be int|bool|string");
}
if(value == null) return BadRequest("value not specified");

Media media = await _context.Medias.FindAsync(id);
JObject theOptions = media.getOptionsAsJson();
if (media == null)
{
return NotFound();
}
if(type == "int") {
try {
theOptions[option] = Int32.Parse(value);
} catch (FormatException) {
return BadRequest($"Unable to parse '{value}' as int");
}
} else if(type == "bool") {
try {
theOptions[option] = Boolean.Parse(value);
} catch (FormatException) {
return BadRequest($"Unable to parse '{value}' as bool");
}
} else if(type == "string") {
theOptions[option] = value;
} else {
return BadRequest("Invalid type");// should never happen
}
media.setOptionsAsJson(theOptions);
await _context.SaveChangesAsync();
return NoContent();
}

// POST: api/ASLVideo
[DisableRequestSizeLimit]
Expand Down Expand Up @@ -200,7 +239,9 @@ public async Task<ActionResult<Media>> PostASLVideo(IFormFile aSLVideo, [FromFor
var subdir = CommonUtils.ToCourseOfferingSubDirectory(_context, media);

var filerecord = await FileRecord.GetNewFileRecordAsync(filePath, Path.GetExtension(filePath), subdir);
video.ASLVideo = filerecord;
await _context.FileRecords.AddAsync(filerecord);
await _context.SaveChangesAsync();
video.ASLVideoId = filerecord.Id;
await _context.SaveChangesAsync();
return Ok();
}
Expand Down
31 changes: 17 additions & 14 deletions ClassTranscribeServer/Controllers/PlaylistsController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -131,11 +131,18 @@ public async Task<ActionResult<IEnumerable<PlaylistDTO>>> GetPlaylists2(string o
{
return Unauthorized(new { Reason = "Insufficient Permission", AccessType = offering.AccessType });
}
var temp = await _context.Playlists

var playLists = await _context.Playlists
.Where(p => p.OfferingId == offeringId)
.OrderBy(p => p.Index)
.ThenBy(p => p.CreatedAt).ToListAsync();
var playlists = temp.Select(p => new PlaylistDTO

var hideRoomVideos = new Dictionary<string,bool>();
foreach (var p in playLists) {
var restrict = (bool?) p.getOptionsAsJson()[ "restrictRoomStream"] ?? false;
hideRoomVideos.Add(p.Id, restrict);
};
var playlistDTOs = playLists.Select(p => new PlaylistDTO
{
Id = p.Id,
CreatedAt = p.CreatedAt,
Expand Down Expand Up @@ -165,7 +172,7 @@ public async Task<ActionResult<IEnumerable<PlaylistDTO>>> GetPlaylists2(string o
{
Id = m.Video.Id,
Video1Path = m.Video.ProcessedVideo1?.Path != null ? m.Video.ProcessedVideo1.Path : m.Video.Video1?.Path,
Video2Path = m.Video.ProcessedVideo2?.Path != null ? m.Video.ProcessedVideo2.Path : m.Video.Video2?.Path,
Video2Path = hideRoomVideos[p.Id] ? null : ( m.Video.ProcessedVideo2?.Path != null ? m.Video.ProcessedVideo2.Path : m.Video.Video2?.Path),
ASLPath = m.Video.ProcessedASLVideo?.Path != null ? m.Video.ProcessedASLVideo.Path : m.Video.ASLVideo?.Path,
TaskLog = m.Video.TaskLog
},
Expand All @@ -182,7 +189,7 @@ public async Task<ActionResult<IEnumerable<PlaylistDTO>>> GetPlaylists2(string o
}).ToList()
}).ToList()
}).ToList();
return playlists;
return playlistDTOs;
}

[HttpGet("SearchForMedia/{offeringId}/{query}")]
Expand Down Expand Up @@ -233,13 +240,9 @@ public async Task<ActionResult<PlaylistDTO>> GetPlaylist(string id)
var partialWatchHistories = user !=null ? await _context.WatchHistories.Where(w => w.ApplicationUserId == user.Id && mediaIds.Contains(w.MediaId)).ToListAsync() : null;
// In memory transformation into DTO resut

var ignore = new MediaDTO()
{

};



var hideRoomVideos = new Dictionary<string,bool>();
var restrict = (bool?) p.getOptionsAsJson()[ "restrictRoomStream"] ?? false;

List<MediaDTO> mediasDTO = mediaList.Select(m => new MediaDTO
{
Id = m.Id,
Expand All @@ -255,10 +258,10 @@ public async Task<ActionResult<PlaylistDTO>> GetPlaylist(string id)
SceneDetectReady = m.Video != null && m.Video.HasSceneObjectData(),
Ready = m.Video == null ? false : "NoError" == m.Video.TranscriptionStatus ,
Video = m.Video == null ? null : new VideoDTO
{
{
Id = m.Video.Id,
Video1Path = m.Video.Video1?.Path,
Video2Path = m.Video.Video2?.Path,
Video1Path = m.Video.ProcessedVideo1?.Path != null ? m.Video.ProcessedVideo1.Path : m.Video.Video1?.Path,
Video2Path = restrict ? null : ( m.Video.ProcessedVideo2?.Path != null ? m.Video.ProcessedVideo2.Path : m.Video.Video2?.Path),
ASLPath = m.Video.ProcessedASLVideo?.Path != null ? m.Video.ProcessedASLVideo.Path : m.Video.ASLVideo?.Path,
TaskLog = m.Video.TaskLog
},
Expand Down
21 changes: 18 additions & 3 deletions TaskEngine/Tasks/DownloadMediaTask.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using System.Diagnostics.CodeAnalysis;
using System.IO;
using System.Linq;
using System.Linq.Expressions;
using System.Threading.Tasks;
using static ClassTranscribeDatabase.CommonUtils;

Expand Down Expand Up @@ -145,9 +146,23 @@ protected override async Task OnConsume(string mediaId, TaskParameters taskParam

public async Task<Video> DownloadKalturaVideo(string subdir, Media media)
{
string? swapInfo = media.getOptionsAsJson()?.GetValue("swapStreams")?.ToString();
GetLogger().LogInformation($"DownloadKalturaVideo ({media.Id}): swap streams: {swapInfo}");
bool swapStreams = Boolean.Parse( media.getOptionsAsJson().GetValue("swapStreams").ToString());
string? video2Url = null;
string video1Url = media.JsonMetadata["downloadUrl"].ToString();
try {
video2Url = media.JsonMetadata["child"]["downloadUrl"].ToString();
if(video2Url.Length>0 && swapStreams) {
string temp = video1Url;
video1Url = video2Url;
video2Url = temp;
}
} catch (Exception) { };

var mediaResponse = await _rpcClient.PythonServerClient.DownloadKalturaVideoRPCAsync(new CTGrpc.MediaRequest
{
VideoUrl = media.JsonMetadata["downloadUrl"].ToString()
VideoUrl = video1Url
});

Video video;
Expand All @@ -163,13 +178,13 @@ public async Task<Video> DownloadKalturaVideo(string subdir, Media media)

var childMediaR = await _rpcClient.PythonServerClient.DownloadKalturaVideoRPCAsync(new CTGrpc.MediaRequest
{
VideoUrl = media.JsonMetadata["child"]["downloadUrl"].ToString()
VideoUrl = video2Url
});
if(FileRecord.IsValidFile(childMediaR.FilePath)) {
video.Video2 = await FileRecord.GetNewFileRecordAsync(childMediaR.FilePath, childMediaR.Ext, subdir);
}
}
} catch(Exception ignored) {
} catch(Exception ignored) {
GetLogger().LogInformation(ignored, $"Couldnt download second video for {media.Id}");
}
}
Expand Down