using RMuseum.Models.GanjoorAudio.ViewModels; using System; using System.IO; using System.Text; using System.Threading.Tasks; using System.Xml; namespace RMuseum.Services.Implementation { /// /// creates an RSS feed from recitations /// public static class RecitationsRssBuilder { /// /// build rss /// /// /// /// public static string Build(int requestCount, PublicRecitationViewModel[] recitations) { StringBuilder builder = new StringBuilder(); builder.AppendLine(""); builder.AppendLine(""); builder.AppendLine(""); builder.AppendLine(" خوانش‌های گنجور"); builder.AppendLine($" "); builder.AppendLine(" https://ganjoor.net"); builder.AppendLine(" دکلمه‌های صوتی اشعار گنجور"); DateTime dtLastUpdate = recitations.Length > 0 ? recitations[0].PublishDate : DateTime.Now; builder.AppendLine($" {dtLastUpdate:r}"); builder.AppendLine(" fa-IR"); builder.AppendLine(" hourly"); builder.AppendLine(" 1"); builder.AppendLine(" "); builder.AppendLine(" https://i.ganjoor.net/gm.gif"); builder.AppendLine(" خوانش‌های گنجور"); builder.AppendLine(" https://ganjoor.net"); builder.AppendLine(" "); builder.AppendLine(" "); builder.AppendLine(" "); builder.AppendLine(" "); builder.AppendLine(" clean"); builder.AppendLine(" گنجورganjoor+alog@ganjoor.net"); foreach (PublicRecitationViewModel recitation in recitations) { string poemDescription = recitation.PoemFullTitle; if (recitation.PoemFullTitle.IndexOf("»") != -1) { string poemCat = recitation.PoemFullTitle.Substring(0, recitation.PoemFullTitle.LastIndexOf("»")).Trim(); string poemTitle = recitation.PoemFullTitle.Substring(recitation.PoemFullTitle.LastIndexOf("»") + 1).Trim(); poemDescription = $"{poemTitle} از ({poemCat})"; } string artist = recitation.AudioArtist; if(!string.IsNullOrEmpty(recitation.AudioArtistUrl)) { artist = $"{recitation.AudioArtist}"; } builder.AppendLine(" "); builder.AppendLine($" {recitation.PoemFullTitle} با خوانش {recitation.AudioArtist}"); builder.AppendLine($" https://ganjoor.net{recitation.PoemFullUrl}"); builder.AppendLine($" {recitation.PublishDate:r}"); builder.AppendLine($" {recitation.LegacyAudioGuid}"); builder.AppendLine($" {recitation.AudioArtist}"); builder.AppendLine($" "); string htmlText = recitation.HtmlText == null ? "" : recitation.HtmlText .Replace("", $"{Environment.NewLine}") .Replace("
", "") .Replace("
", "") .Replace("
", "") .Replace("
", "") .Replace("
", ""); builder.AppendLine($" {poemDescription} را با خوانش {artist} بشنوید.

{Environment.NewLine}" + $"

فایل صوتی متناظر را می‌توانید در قالب mp3 از این نشانی (اندازه {(recitation.Mp3SizeInBytes / (1024 * 1024.0f)) : 0.00} مگابایت) دریافت کنید.

{Environment.NewLine}" + $"

متن خوانش:

{Environment.NewLine}" + $" {htmlText}]]>
"); builder.AppendLine($" "); builder.AppendLine(" "); } builder.AppendLine(""); builder.AppendLine(""); return builder.ToString(); } } }