building RSS for published recitations + some warnings are fix
This commit is contained in:
parent
113e94a545
commit
9f470e3699
@ -27,7 +27,7 @@ namespace RMuseum.Controllers
|
||||
/// <summary>
|
||||
/// returns paginated published recitations, ordered by publish date descending
|
||||
/// </summary>
|
||||
/// <param name="paging"></param>
|
||||
/// <param name="paging">if PageSize is -1 or is more than 100 it resets to 100</param>
|
||||
/// <param name="searchTerm"></param>
|
||||
/// <returns></returns>
|
||||
[HttpGet("published")]
|
||||
@ -37,6 +37,8 @@ namespace RMuseum.Controllers
|
||||
public async Task<IActionResult> GetPublished([FromQuery] PagingParameterModel paging, string searchTerm = "")
|
||||
{
|
||||
|
||||
if (paging.PageSize == -1 || paging.PageSize > 100)
|
||||
paging.PageSize = 100;
|
||||
var res = await _audioService.GetPublishedRecitations(paging, searchTerm);
|
||||
if (!string.IsNullOrEmpty(res.ExceptionString))
|
||||
return BadRequest(res.ExceptionString);
|
||||
@ -56,13 +58,13 @@ namespace RMuseum.Controllers
|
||||
[AllowAnonymous]
|
||||
[ProducesResponseType((int)HttpStatusCode.OK, Type = typeof(FileStreamResult))]
|
||||
[ProducesResponseType((int)HttpStatusCode.BadRequest, Type = typeof(string))]
|
||||
public async Task<IActionResult> GetRssFeed(int count = 200)
|
||||
public async Task<IActionResult> GetRssFeed(int count = 100)
|
||||
{
|
||||
var res = await _audioService.GetPublishedRecitations(new PagingParameterModel() { PageNumber = 1, PageSize = count}, "");
|
||||
if (!string.IsNullOrEmpty(res.ExceptionString))
|
||||
return BadRequest(res.ExceptionString);
|
||||
|
||||
string rss = await RecitationsRssBuilder.Build(res.Result.Items);
|
||||
string rss = RecitationsRssBuilder.Build(res.Result.Items);
|
||||
var stream = new MemoryStream();
|
||||
var writer = new StreamWriter(stream);
|
||||
writer.Write(rss);
|
||||
|
||||
@ -25,11 +25,6 @@
|
||||
/// </summary>
|
||||
SoundOrXMLFilesChanged = 4,
|
||||
|
||||
/// <summary>
|
||||
/// Xml file should be reuploaded
|
||||
/// </summary>
|
||||
//XmlFileChanged = 8,
|
||||
|
||||
/// <summary>
|
||||
/// Item should be deleted
|
||||
/// </summary>
|
||||
|
||||
@ -27,7 +27,7 @@ namespace RMuseum.Models.GanjoorAudio.ViewModels
|
||||
/// </summary>
|
||||
public string PoemFullUrl { get; set; }
|
||||
|
||||
// <summary>
|
||||
/// <summary>
|
||||
/// Audio Title
|
||||
/// </summary>
|
||||
public string AudioTitle { get; set; }
|
||||
|
||||
@ -15,6 +15,7 @@ namespace RMuseum.Models.GanjoorAudio.ViewModels
|
||||
/// <param name="tracker"></param>
|
||||
/// <param name="poem"></param>
|
||||
/// <param name="user"></param>
|
||||
/// <param name="recitation"></param>
|
||||
public RecitationPublishingTrackerViewModel(RecitationPublishingTracker tracker, GanjoorPoem poem, RAppUser user, Recitation recitation)
|
||||
{
|
||||
UserEmail = user.Email;
|
||||
|
||||
@ -19,7 +19,6 @@
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
</PackageReference>
|
||||
<PackageReference Include="Microsoft.SyndicationFeed.ReaderWriter" Version="1.0.2" />
|
||||
<PackageReference Include="MySql.Data" Version="8.0.21" />
|
||||
<PackageReference Include="NAudio" Version="1.10.0" />
|
||||
<PackageReference Include="SSH.NET" Version="2020.0.0-beta1" />
|
||||
|
||||
@ -729,7 +729,7 @@
|
||||
<summary>
|
||||
returns paginated published recitations, ordered by publish date descending
|
||||
</summary>
|
||||
<param name="paging"></param>
|
||||
<param name="paging">if PageSize is -1 or is more than 100 it resets to 100</param>
|
||||
<param name="searchTerm"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
@ -2196,7 +2196,11 @@
|
||||
Poem Full Url (without domain name)
|
||||
</summary>
|
||||
</member>
|
||||
<!-- Badly formed XML comment ignored for member "P:RMuseum.Models.GanjoorAudio.ViewModels.PublicRecitationViewModel.AudioTitle" -->
|
||||
<member name="P:RMuseum.Models.GanjoorAudio.ViewModels.PublicRecitationViewModel.AudioTitle">
|
||||
<summary>
|
||||
Audio Title
|
||||
</summary>
|
||||
</member>
|
||||
<member name="P:RMuseum.Models.GanjoorAudio.ViewModels.PublicRecitationViewModel.AudioArtist">
|
||||
<summary>
|
||||
Audio Artist
|
||||
@ -2309,6 +2313,7 @@
|
||||
<param name="tracker"></param>
|
||||
<param name="poem"></param>
|
||||
<param name="user"></param>
|
||||
<param name="recitation"></param>
|
||||
</member>
|
||||
<member name="P:RMuseum.Models.GanjoorAudio.ViewModels.RecitationPublishingTrackerViewModel.UserEmail">
|
||||
<summary>
|
||||
|
||||
@ -1,5 +1,4 @@
|
||||
using Microsoft.SyndicationFeed;
|
||||
using Microsoft.SyndicationFeed.Rss;
|
||||
|
||||
using RMuseum.Models.GanjoorAudio.ViewModels;
|
||||
using System;
|
||||
using System.IO;
|
||||
@ -19,64 +18,76 @@ namespace RMuseum.Services.Implementation
|
||||
/// </summary>
|
||||
/// <param name="recitations"></param>
|
||||
/// <returns></returns>
|
||||
public static async Task<string> Build(PublicRecitationViewModel[] recitations)
|
||||
public static string Build(PublicRecitationViewModel[] recitations)
|
||||
{
|
||||
var sw = new StringWriterWithEncoding(Encoding.UTF8);
|
||||
|
||||
using (XmlWriter xmlWriter = XmlWriter.Create(sw, new XmlWriterSettings() { Async = true, Indent = true }))
|
||||
StringBuilder builder = new StringBuilder();
|
||||
|
||||
builder.AppendLine("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
|
||||
|
||||
builder.AppendLine("<rss version=\"2.0\"");
|
||||
builder.AppendLine(" xmlns:content=\"http://purl.org/rss/1.0/modules/content/\"");
|
||||
builder.AppendLine(" xmlns:wfw=\"http://wellformedweb.org/CommentAPI/\"");
|
||||
builder.AppendLine(" xmlns:dc=\"http://purl.org/dc/elements/1.1/\"");
|
||||
builder.AppendLine(" xmlns:atom=\"http://www.w3.org/2005/Atom\"");
|
||||
builder.AppendLine(" xmlns:sy=\"http://purl.org/rss/1.0/modules/syndication/\"");
|
||||
builder.AppendLine(" xmlns:slash=\"http://purl.org/rss/1.0/modules/slash/\"");
|
||||
builder.AppendLine(" xmlns:itunes=\"http://www.itunes.com/dtds/podcast-1.0.dtd\"");
|
||||
builder.AppendLine(">");
|
||||
|
||||
builder.AppendLine("<channel>");
|
||||
|
||||
builder.AppendLine(" <title>خوانشهای گنجور</title>");
|
||||
builder.AppendLine(" <atom:link href=\"https://ganjgah.ir/api/audio/published/rss\" rel=\"self\" type=\"application/rss+xml\" />");
|
||||
builder.AppendLine(" <link>https://ganjoor.net</link>");
|
||||
builder.AppendLine(" <description>دکلمههای صوتی اشعار گنجور</description>");
|
||||
|
||||
DateTime dtLastUpdate = recitations.Length > 0 ? recitations[0].PublishDate : DateTime.Now;
|
||||
|
||||
builder.AppendLine($" <lastBuildDate>{dtLastUpdate:r}</lastBuildDate>");
|
||||
builder.AppendLine(" <language>fa-IR</language>");
|
||||
builder.AppendLine(" <sy:updatePeriod>hourly</sy:updatePeriod>");
|
||||
builder.AppendLine(" <sy:updateFrequency>1</sy:updateFrequency>");
|
||||
builder.AppendLine(" <image>");
|
||||
builder.AppendLine(" <url>https://i.ganjoor.net/gm.gif</url>");
|
||||
builder.AppendLine(" <title>خوانشهای گنجور</title>");
|
||||
builder.AppendLine(" <link>https://ganjoor.net</link>");
|
||||
builder.AppendLine(" </image>");
|
||||
builder.AppendLine(" <itunes:category text=\"Arts\">");
|
||||
builder.AppendLine(" <itunes:category text=\"Books\"/>");
|
||||
builder.AppendLine(" </itunes:category>");
|
||||
builder.AppendLine(" <itunes:explicit>clean</itunes:explicit>");
|
||||
builder.AppendLine(" <itunes:owner><itunes:name>گنجور</itunes:name><itunes:email>ganjoor+alog@ganjoor.net</itunes:email></itunes:owner>");
|
||||
|
||||
foreach (PublicRecitationViewModel recitation in recitations)
|
||||
{
|
||||
var writer = new RssFeedWriter(xmlWriter);
|
||||
|
||||
await writer.WriteTitle("خوانشهای گنجور");
|
||||
await writer.WriteDescription("روایتهای صوتی اشعار سایت گنجور");
|
||||
await writer.Write(new SyndicationLink(new Uri("http://ava.ganjoor.net")));
|
||||
await writer.WriteLastBuildDate(recitations.Length > 0 ? recitations[0].PublishDate.ToUniversalTime() : DateTimeOffset.UtcNow);
|
||||
await writer.WriteLanguage(new System.Globalization.CultureInfo("fa-IR"));
|
||||
await writer.WriteGenerator("https://ganjgah.ir");
|
||||
|
||||
foreach(PublicRecitationViewModel recitation in recitations)
|
||||
{
|
||||
var item = new SyndicationItem()
|
||||
{
|
||||
Id = recitation.LegacyAudioGuid.ToString(),
|
||||
Title = $"{recitation.PoemFullTitle} با خوانش {recitation.AudioArtist}",
|
||||
Description = recitation.HtmlText == null ? "" : recitation.HtmlText
|
||||
.Replace("</div>", "")
|
||||
.Replace("<div class=\"b\">", "")
|
||||
.Replace("<div class=\"b2\">", "")
|
||||
.Replace("<div class=\"m1\">", "")
|
||||
.Replace("<div class=\"m2\">", "")
|
||||
.Replace("<div class=\"n\">", ""),
|
||||
Published = recitation.PublishDate.ToUniversalTime(),
|
||||
};
|
||||
|
||||
item.AddLink(new SyndicationLink(new Uri($"https://ava.ganjoor.net/#/{recitation.Id}")));
|
||||
item.AddCategory(new SyndicationCategory("شعرخوانی"));
|
||||
item.AddCategory(new SyndicationCategory("ادبیات"));
|
||||
|
||||
await writer.Write(item);
|
||||
}
|
||||
|
||||
xmlWriter.Flush();
|
||||
builder.AppendLine(" <item>");
|
||||
builder.AppendLine($" <title>{recitation.PoemFullTitle} با خوانش {recitation.AudioArtist}</title>");
|
||||
builder.AppendLine($" <link>https://ganjoor.net{recitation.PoemFullUrl}</link>");
|
||||
builder.AppendLine($" <pubDate>{recitation.PublishDate:r}</pubDate>");
|
||||
builder.AppendLine($" <guid isPermaLink=\"false\">{recitation.LegacyAudioGuid}</guid>");
|
||||
builder.AppendLine($" <dc:creator>{recitation.AudioArtist}</dc:creator>");
|
||||
builder.AppendLine($" <description><![CDATA[{recitation.PoemFullTitle} را با خوانش {recitation.AudioArtist} بشنوید.]]></description>");
|
||||
string htmlText = recitation.HtmlText == null ? "" : recitation.HtmlText
|
||||
.Replace("</div>", "")
|
||||
.Replace("<div class=\"b\">", "")
|
||||
.Replace("<div class=\"b2\">", "")
|
||||
.Replace("<div class=\"m1\">", "")
|
||||
.Replace("<div class=\"m2\">", "")
|
||||
.Replace("<div class=\"n\">", "");
|
||||
builder.AppendLine($" <content:encoded><![CDATA[{htmlText}]]></content:encoded>");
|
||||
builder.AppendLine($" <enclosure url=\"{recitation.Mp3Url}\" length=\"{recitation.Mp3SizeInBytes}\" type=\"audio/mpeg\" />");
|
||||
builder.AppendLine(" </item>");
|
||||
}
|
||||
|
||||
builder.AppendLine("</channel>");
|
||||
builder.AppendLine("</rss>");
|
||||
|
||||
return builder.ToString();
|
||||
|
||||
|
||||
return sw.ToString();
|
||||
}
|
||||
}
|
||||
|
||||
class StringWriterWithEncoding : StringWriter
|
||||
{
|
||||
private readonly Encoding _encoding;
|
||||
|
||||
public StringWriterWithEncoding(Encoding encoding)
|
||||
{
|
||||
this._encoding = encoding;
|
||||
}
|
||||
|
||||
public override Encoding Encoding
|
||||
{
|
||||
get { return _encoding; }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user