diff --git a/RMuseum/DbContext/RMuseumDbContext.cs b/RMuseum/DbContext/RMuseumDbContext.cs index a92167d3..def1574e 100644 --- a/RMuseum/DbContext/RMuseumDbContext.cs +++ b/RMuseum/DbContext/RMuseumDbContext.cs @@ -11,6 +11,7 @@ using RMuseum.Models.Notification; using RSecurityBackend.DbContext; using RSecurityBackend.Models.Auth.Db; using System; +using Dapper; namespace RMuseum.DbContext { @@ -138,5 +139,10 @@ namespace RMuseum.DbContext /// public DbSet UploadSessions { get; set; } + /// + /// User Narration Profiles + /// + public DbSet UserNarrationProfiles { get; set; } + } } diff --git a/RMuseum/Models/GanjoorAudio/UserNarrationProfile.cs b/RMuseum/Models/GanjoorAudio/UserNarrationProfile.cs new file mode 100644 index 00000000..86b17a99 --- /dev/null +++ b/RMuseum/Models/GanjoorAudio/UserNarrationProfile.cs @@ -0,0 +1,58 @@ +using RSecurityBackend.Models.Auth.Db; +using System; + +namespace RMuseum.Models.GanjoorAudio +{ + /// + /// Narration Profiles for users + /// + public class UserNarrationProfile + { + /// + /// Id + /// + public Guid Id { get; set; } + + /// + /// User + /// + public RAppUser User { get; set; } + + /// + /// UserId + /// + public Guid UserId { get; set; } + + /// + /// this would be appended to audio files names prefixed by a dash to make them unique and specfic to user + /// filenames usually would look like {GanjoorPostId}-{FileSuffixWithoutDash}.{ext} + /// for example 2200-hrm.xml + /// + public string FileSuffixWithoutDash { get; set; } + + /// + /// artist name + /// + public string ArtistName { get; set; } + + /// + /// artist url + /// + public string ArtistUrl { get; set; } + + /// + /// audio src + /// + public string AudioSrc { get; set; } + + /// + /// audio src url + /// + public string AudioSrcUrl { get; set; } + + /// + /// is default + /// + public bool IsDefault { get; set; } + } +} diff --git a/RMuseum/RMuseum.csproj b/RMuseum/RMuseum.csproj index 42d58c1b..9b8135b4 100644 --- a/RMuseum/RMuseum.csproj +++ b/RMuseum/RMuseum.csproj @@ -27,7 +27,6 @@ - diff --git a/RMuseum/RMuseum.xml b/RMuseum/RMuseum.xml index 741a5f83..c1d5a737 100644 --- a/RMuseum/RMuseum.xml +++ b/RMuseum/RMuseum.xml @@ -825,6 +825,11 @@ Upload Sessions + + + User Narration Profiles + + Items or pictures status @@ -1778,6 +1783,58 @@ Review Status + + + Narration Profiles for users + + + + + Id + + + + + User + + + + + UserId + + + + + this would be appended to audio files names prefixed by a dash to make them unique and specfic to user + filenames usually would look like {GanjoorPostId}-{FileSuffixWithoutDash}.{ext} + for example 2200-hrm.xml + + + + + artist name + + + + + artist url + + + + + audio src + + + + + audio src url + + + + + is default + + Poem Narration view model @@ -4220,6 +4277,35 @@ + + + Persian specific text utility class + + + + + convert arabic characters to persian equivalents + + + + + + + list of persian letters + + + + + convert persian text to simple pinglish + + + + + + + equaivalnet for persian characters + + manipulating picture files diff --git a/RMuseum/Services/Implementation/AudioNarrationService.cs b/RMuseum/Services/Implementation/AudioNarrationService.cs index 37c88c7b..8500af1a 100644 --- a/RMuseum/Services/Implementation/AudioNarrationService.cs +++ b/RMuseum/Services/Implementation/AudioNarrationService.cs @@ -7,9 +7,11 @@ using MySql.Data.MySqlClient; using NAudio.Wave; using OggVorbisEncoder; using RMuseum.DbContext; +using RMuseum.Migrations; using RMuseum.Models.GanjoorAudio; using RMuseum.Models.GanjoorAudio.ViewModels; using RMuseum.Models.UploadSession; +using RMuseum.Services.Implementation.ImportedFromDesktopGanjoor; using RSecurityBackend.Models.Generic; using RSecurityBackend.Services.Implementation; using System; @@ -157,7 +159,8 @@ namespace RMuseum.Services.Implementation UseId = userId, UploadStartTime = DateTime.Now, Status = UploadSessionProcessStatus.NotStarted, - ProcessProgress = 0 + ProcessProgress = 0, + User = await _context.Users.Where(u => u.Id == userId).FirstOrDefaultAsync() //this would be referenced later and is needed }; await _context.UploadSessions.AddAsync(session); await _context.SaveChangesAsync(); @@ -258,7 +261,7 @@ namespace RMuseum.Services.Implementation try { file.MP3FileCheckSum = PoemAudio.ComputeCheckSum(file.FilePath); - mp3files.Add(file); + mp3files.Add(file); } catch (Exception exp) { @@ -296,10 +299,36 @@ namespace RMuseum.Services.Implementation File.WriteAllBytes(Path.Combine(Path.GetDirectoryName(mp3file.FilePath), $"{Path.GetFileNameWithoutExtension(mp3file.FilePath)}.ogg") , oggBytes); } - //create draft poem narration: - var FileNameWithoutExtension = $"{audio.PoemId}-{session.UseId}";//TODO: use user profiles for audio files here - //TODO: rename and move files somewhere here + + + UserNarrationProfile defProfile = await context.UserNarrationProfiles.Where(p => p.UserId == session.UseId && p.IsDefault == true).FirstOrDefaultAsync(); + if(defProfile == null) + { + defProfile = new UserNarrationProfile() + { + FileSuffixWithoutDash = !string.IsNullOrEmpty(session.User.FirstName) ? !string.IsNullOrEmpty(session.User.SureName) ? + GPersianTextSync.Farglisize($"{session.User.FirstName[0]}{session.User.SureName[0]}") + : + GPersianTextSync.Farglisize($"{session.User.FirstName[0]}") : $"{session.User.UserName[0]}", + ArtistName = $"{session.User.FirstName} {session.User.SureName}", + ArtistUrl = "", + AudioSrc = "", + AudioSrcUrl = "" + + }; + } + //create draft poem narration: + string FileNameWithoutExtension = $"{audio.PoemId}-{defProfile.FileSuffixWithoutDash}"; + + Guid legacyAudioGuid = audio.SyncGuid; + while( + (await context.AudioFiles.Where(a => a.LegacyAudioGuid == legacyAudioGuid).FirstOrDefaultAsync()) != null + ) + { legacyAudioGuid = Guid.NewGuid(); } + + //TODO: rename and move files somewhere here + PoemNarration narration = new PoemNarration() { OwnerId = session.UseId, @@ -308,11 +337,11 @@ namespace RMuseum.Services.Implementation FileNameWithoutExtension = FileNameWithoutExtension, SoundFilesFolder = "a2", AudioTitle = audio.PoemTitle, - AudioArtist = "",//TODO: use user profiles for audio files here - AudioArtistUrl = "",//TODO: use user profiles for audio files here - AudioSrc = "", //TODO: use user profiles for audio files here - AudioSrcUrl = "", //TODO: use user profiles for audio files here - LegacyAudioGuid = audio.SyncGuid, //check for repeated guid here + AudioArtist = defProfile.ArtistName, + AudioArtistUrl = defProfile.ArtistUrl, + AudioSrc = defProfile.AudioSrc, + AudioSrcUrl = defProfile.AudioSrcUrl, + LegacyAudioGuid = legacyAudioGuid, Mp3FileCheckSum = audio.FileCheckSum, Mp3SizeInBytes = mp3fileSize, OggSizeInBytes = oggfileSize, diff --git a/RMuseum/Services/Implementation/ImportedFromDesktopGanjoor/GPersianTextSync.cs b/RMuseum/Services/Implementation/ImportedFromDesktopGanjoor/GPersianTextSync.cs new file mode 100644 index 00000000..af8f9d1f --- /dev/null +++ b/RMuseum/Services/Implementation/ImportedFromDesktopGanjoor/GPersianTextSync.cs @@ -0,0 +1,105 @@ +using System.Collections.Generic; + +namespace RMuseum.Services.Implementation.ImportedFromDesktopGanjoor +{ + /// + /// Persian specific text utility class + /// + public class GPersianTextSync + { + /// + /// convert arabic characters to persian equivalents + /// + /// + /// + public static string Sync(string inputStr) + { + return + inputStr + .Replace('ك', 'ک') + .Replace('ي', 'ی') + .Replace("ۀ", "هٔ") + .Replace("ه‌ی", "هٔ") + .Replace("0", "۰") + .Replace("1", "۱") + .Replace("2", "۲") + .Replace("3", "۳") + .Replace("4", "۴") + .Replace("5", "۵") + .Replace("6", "۶") + .Replace("7", "۷") + .Replace("8", "۸") + .Replace("9", "۹"); + } + + /// + /// list of persian letters + /// + public static string PersianLetters + { + get + { + return "اآئأإءبپتثجچحخدذرزژسشصضطظعغفقکگلمنوهی"; + } + } + + /// + /// convert persian text to simple pinglish + /// + /// + /// + public static string Farglisize(string inputStr) + { + string outStr = ""; + string s; + foreach (char c in inputStr) + if (_PinglishDic.TryGetValue(c, out s)) + outStr += s; + return outStr; + } + + /// + /// equaivalnet for persian characters + /// + private static Dictionary _PinglishDic = new Dictionary() + { + {'ا', "a"}, + {'آ', "a"}, + {'ب', "b"}, + {'پ', "p"}, + {'ت', "t"}, + {'ث', "s"}, + {'ج', "j"}, + {'چ', "ch"}, + {'ح', "h"}, + {'خ', "kh"}, + {'د', "d"}, + {'ذ', "z"}, + {'ر', "r"}, + {'ز', "z"}, + {'ژ', "zh"}, + {'س', "s"}, + {'ش', "sh"}, + {'ص', "s"}, + {'ض', "z"}, + {'ط', "t"}, + {'ظ', "z"}, + {'ع', "E"}, + {'غ', "gh"}, + {'ف', "f"}, + {'ق', "gh"}, + {'ک', "k"}, + {'گ', "g"}, + {'ل', "l"}, + {'م', "m"}, + {'ن', "n"}, + {'ه', "h"}, + {'و', "v"}, + {'ی', "i"}, + {'ئ', "E"}, + {'أ', "A"}, + {'إ', "E"}, + {' ', "-"}, + }; + } +} diff --git a/RMuseum/appsettings.json b/RMuseum/appsettings.json index a591e796..107a64d0 100644 --- a/RMuseum/appsettings.json +++ b/RMuseum/appsettings.json @@ -40,7 +40,8 @@ "Database": "adab" }, "AudioUploadService": { - "StoragePath": "C:\\audio" + "StoragePath": "C:\\audio", + "LocalAudioRepositoryPath": "D:\\My Documents\\My Web Design\\ganjoor\\www\\i", }, "AllowedHosts": "*" }