diff --git a/GanjooRazor/Pages/Partials/GanjoorPage/PageTypes/_PoemPagePartial.cshtml b/GanjooRazor/Pages/Partials/GanjoorPage/PageTypes/_PoemPagePartial.cshtml index 56485177..1ca259d1 100644 --- a/GanjooRazor/Pages/Partials/GanjoorPage/PageTypes/_PoemPagePartial.cshtml +++ b/GanjooRazor/Pages/Partials/GanjoorPage/PageTypes/_PoemPagePartial.cshtml @@ -794,7 +794,7 @@ {

- + معرفی ترانه‌هایی که در متن آنها از این شعر استفاده شده است

@@ -819,7 +819,7 @@
}

- + معرفی ترانه‌های دیگر

diff --git a/GanjooRazor/Pages/SongRecommendation/Bp.cshtml b/GanjooRazor/Pages/SongRecommendation/Bp.cshtml index 7cf1a9d8..0c29a84f 100644 --- a/GanjooRazor/Pages/SongRecommendation/Bp.cshtml +++ b/GanjooRazor/Pages/SongRecommendation/Bp.cshtml @@ -92,11 +92,11 @@

انتخاب منبع جستجو:

- + - + - +
diff --git a/GanjooRazor/Pages/SongRecommendation/Golha.cshtml b/GanjooRazor/Pages/SongRecommendation/Golha.cshtml index 33880857..fe36aa24 100644 --- a/GanjooRazor/Pages/SongRecommendation/Golha.cshtml +++ b/GanjooRazor/Pages/SongRecommendation/Golha.cshtml @@ -83,11 +83,11 @@

انتخاب منبع جستجو:

- + - + - +
diff --git a/GanjooRazor/Pages/SongRecommendation/MusicLink.cshtml b/GanjooRazor/Pages/SongRecommendation/MusicLink.cshtml deleted file mode 100644 index 9d3eef6b..00000000 --- a/GanjooRazor/Pages/SongRecommendation/MusicLink.cshtml +++ /dev/null @@ -1,155 +0,0 @@ -@page -@model GanjooRazor.Pages.MusicLinkModel -@{ - Layout = null; -} - - - - - - پیشنهاد پیوند قطعهٔ موسیقی مرتبط با شعر - - - - - - - - - - - -
-
- @if (Model.ReadOnlyMode) - { -
-
-

- امکان پیشنهاد قطعه موقتا به دلیل تغییرات سایت و یا انتقال سرور وجود ندارد. لطفاً ساعاتی دیگر مجدداً تلاش کنید. -

-
-
- } - else - @if (Model.PoemId == 0) - { -
-
-

- خطا: شعری انتخاب نشده است. -

-
-
- } - else - if (!Model.LoggedIn) - { -
-
-

- برای پیشنهاد آهنگهای مرتبط با اشعار لازم است ابتدا با نام کاربری خود وارد گنجور شوید. -

-

- ورود به گنجور -

-
-
- } - else - { - @if (!string.IsNullOrEmpty(Model.LastError)) - { -
-
-

- @Model.LastError -

-
-
- } - -
-
-

انتخاب منبع:

-
-
- - - - - - -
-
-

- با استفاده از این صفحه می‌توانید آهنگهایی را که در متن آنها از شعر جاری استفاده شده است معرفی کنید. نشانی صفحهٔ آهنگ را از سرویس پخش یا فروش موسیقی کپی کرده و در جعبهٔ «نشانی آهنگ» بچسبانید. نام خواننده و عنوان آهنگ در صورت امکان به صورت خودکار پر می‌شود و می‌توانید آن را اصلاح کنید. پس از «پیشنهاد قطعه» آهنگ پیشنهادی در صف بررسی قرار می‌گیرد و پس از بازبینی و تأیید به صفحهٔ اصلی شعر اضافه می‌شود. از این که کمک می‌کنید که گنجور به نمایه‌ای برای موسیقی ایرانی بدل شود سپاسگزاریم. -

-

- تنها نشانی از این سرویس‌ها پذیرفته می‌شود: @RMuseum.Utils.MusicUrlValidator.PlatformNames. نشانی فایلهای صوتی تکثیر شده و سایتهای دانلود غیرقانونی پذیرفته نمی‌شود. -

-

- تذکر مهم: فقط مواردی تأیید می‌شود که در آهنگ متناظر همین شعر خوانده شود. تعیین نام خواننده به تنهایی کارایی ندارد و لطفا جهت کاهش زمان مورد نیاز برای بررسی موارد پیشنهادی از اعلام موارد اینچنینی خودداری فرمایید. فهرست کامل آهنگهای مرتبط در این صفحه در دسترس است. -

- - @if (Model.SuggestedSongs.Length > 0) - { -

موارد زیر شامل قطعه‌هایی هستند که پیشتر توسط دوستان دیگر پیشنهاد شده و در صف بررسی قرار دارند:

- - @foreach (var suggestedSong in Model.SuggestedSongs) - { -

- @if (!string.IsNullOrEmpty(suggestedSong.ArtistName)) - { - @suggestedSong.ArtistName » - } - @if (!string.IsNullOrEmpty(suggestedSong.AlbumName)) - { - @suggestedSong.AlbumName » - } - @suggestedSong.TrackName -

- } - } - - @if (Model.PostSuccess) - { -
-
-

- با سپاس! پیشنهاد شما به فهرست اضافه شد. -

-
-
- } - } -
- - @if (Model.PoemId != 0 && Model.LoggedIn && !Model.ReadOnlyMode) - { -
-
- نشانی آهنگ: - - -
- خواننده: - -
- آلبوم: - -
- عنوان آهنگ: - -
- توضیح: - -
- -
-
- } -
- - diff --git a/GanjooRazor/Pages/SongRecommendation/MusicLink.cshtml.cs b/GanjooRazor/Pages/SongRecommendation/MusicLink.cshtml.cs deleted file mode 100644 index 117b8523..00000000 --- a/GanjooRazor/Pages/SongRecommendation/MusicLink.cshtml.cs +++ /dev/null @@ -1,243 +0,0 @@ -using GanjooRazor.Utils; -using Microsoft.AspNetCore.Mvc; -using Microsoft.AspNetCore.Mvc.RazorPages; -using Microsoft.Extensions.Configuration; -using Newtonsoft.Json; -using Newtonsoft.Json.Linq; -using RMuseum.Models.Ganjoor; -using RMuseum.Models.Ganjoor.ViewModels; -using RMuseum.Utils; -using System; -using System.Net; -using System.Net.Http; -using System.Text; -using System.Threading.Tasks; - -namespace GanjooRazor.Pages -{ - [IgnoreAntiforgeryToken(Order = 1001)] - public class MusicLinkModel : PageModel - { - /// - /// HttpClient instance - /// - private readonly HttpClient _httpClient; - - /// - /// configuration - /// - private readonly IConfiguration Configuration; - - /// - /// constructor - /// - /// - /// - public MusicLinkModel(HttpClient httpClient, IConfiguration configuration) - { - _httpClient = httpClient; - Configuration = configuration; - } - - /// - /// is logged on - /// - public bool LoggedIn { get; set; } - - /// - /// PoemId - /// - public int PoemId { get; set; } - - /// - /// Last Error - /// - public string LastError { get; set; } - - /// - /// Post Success - /// - public bool PostSuccess { get; set; } - - /// - /// Inserted song Id - /// - public int InsertedSongId { get; set; } - - /// - /// readonly mode - /// - public bool ReadOnlyMode - { - get - { - return bool.Parse(Configuration["ReadOnlyMode"]); - } - } - - /// - /// suggested (unapproved) songs - /// - public PoemMusicTrackViewModel[] SuggestedSongs { get; set; } - - /// - /// api model - /// - [BindProperty] - public PoemMusicTrackViewModel PoemMusicTrackViewModel { get; set; } - - /// - /// every pending suggestion of the poem is listed, whatever source it came from - /// - private async Task _GetSuggestedSongs() - { - var response = await _httpClient.GetAsync($"{APIRoot.Url}/api/ganjoor/poem/{PoemId}/songs/?approved=false&trackType={(int)PoemMusicTrackType.All}"); - - if (response.StatusCode == HttpStatusCode.OK) - { - SuggestedSongs = JsonConvert.DeserializeObject(await response.Content.ReadAsStringAsync()); - } - else - { - SuggestedSongs = new PoemMusicTrackViewModel[] { }; - } - } - - public async Task OnGetAsync() - { - PostSuccess = false; - LastError = ""; - InsertedSongId = 0; - LoggedIn = !string.IsNullOrEmpty(Request.Cookies["Token"]); - - if (!string.IsNullOrEmpty(Request.Query["p"])) - { - PoemId = int.Parse(Request.Query["p"]); - } - else - { - PoemId = 0; - } - - await _GetSuggestedSongs(); - } - - public async Task OnPostAsync() - { - PostSuccess = false; - LastError = ""; - LoggedIn = !string.IsNullOrEmpty(Request.Cookies["Token"]); - PoemId = PoemMusicTrackViewModel.PoemId = int.Parse(Request.Query["p"]); - PoemMusicTrackViewModel.TrackType = PoemMusicTrackType.MusicUrl; - InsertedSongId = 0; - - if (!MusicUrlValidator.TryNormalize(PoemMusicTrackViewModel.TrackUrl, out string normalizedUrl, out _, out string urlError)) - { - LastError = urlError; - await _GetSuggestedSongs(); - return Page(); - } - - PoemMusicTrackViewModel.TrackUrl = normalizedUrl; - - using (HttpClient secureClient = new HttpClient(new GanjoorReloginHandler(Request, Response))) - { - if (await GanjoorSessionChecker.PrepareClient(secureClient, Request, Response)) - { - var stringContent = new StringContent(JsonConvert.SerializeObject(PoemMusicTrackViewModel), Encoding.UTF8, "application/json"); - var methodUrl = $"{APIRoot.Url}/api/ganjoor/song"; - var response = await secureClient.PostAsync(methodUrl, stringContent); - if (!response.IsSuccessStatusCode) - { - LastError = await _ReadErrorAsync(response); - } - else - { - InsertedSongId = JsonConvert.DeserializeObject(await response.Content.ReadAsStringAsync()).Id; - - PostSuccess = true; - } - } - else - { - LastError = "لطفاً از گنجور خارج و مجددا به آن وارد شوید."; - } - } - - await _GetSuggestedSongs(); - - return Page(); - } - - /// - /// the API returns its errors as a JSON string, but 401s and framework level failures - /// come back as an empty or non-JSON body - /// - /// - /// - private static async Task _ReadErrorAsync(HttpResponseMessage response) - { - if (response.StatusCode == HttpStatusCode.Unauthorized || response.StatusCode == HttpStatusCode.Forbidden) - return "نشست شما معتبر نیست. لطفاً از گنجور خارج و مجدداً وارد شوید."; - - string body = await response.Content.ReadAsStringAsync(); - if (string.IsNullOrWhiteSpace(body)) - return $"خطا در ارتباط با گنجور ({(int)response.StatusCode})."; - - try - { - return JsonConvert.DeserializeObject(body) ?? body; - } - catch (JsonException) - { - return body; - } - } - - /// - /// best effort track title/artist lookup through the platform's public oEmbed endpoint - /// - /// - /// - public async Task OnPostFetchMetadataAsync(string url) { - if (!MusicUrlValidator.TryNormalize(url, out string normalizedUrl, out MusicPlatform platform, out string error)) - { - return new BadRequestObjectResult(error); - } - - if (string.IsNullOrEmpty(platform.OEmbedEndpoint)) - { - return new JsonResult(new { trackName = "", artistName = "" }); - } - - try - { - // the pasted url is only ever handed to the platform's own fixed endpoint, and redirects - // are refused, so this cannot be steered at an arbitrary host - using var handler = new HttpClientHandler() { AllowAutoRedirect = false }; - using var oEmbedClient = new HttpClient(handler) { Timeout = TimeSpan.FromSeconds(5), MaxResponseContentBufferSize = 128 * 1024 }; - - var response = await oEmbedClient.GetAsync($"{platform.OEmbedEndpoint}?url={WebUtility.UrlEncode(normalizedUrl)}&format=json"); - if (!response.IsSuccessStatusCode) - { - return new JsonResult(new { trackName = "", artistName = "" }); - } - - var parsed = JObject.Parse(await response.Content.ReadAsStringAsync()); - - return new JsonResult - ( - new - { - trackName = parsed.SelectToken("title")?.Value() ?? "", - artistName = parsed.SelectToken("author_name")?.Value() ?? "" - } - ); - } - catch - { - return new JsonResult(new { trackName = "", artistName = "" }); - } - } - } -} diff --git a/GanjooRazor/Pages/SongRecommendation/Spotify.cshtml b/GanjooRazor/Pages/SongRecommendation/Spotify.cshtml index c13eb43f..ee92d9e2 100644 --- a/GanjooRazor/Pages/SongRecommendation/Spotify.cshtml +++ b/GanjooRazor/Pages/SongRecommendation/Spotify.cshtml @@ -91,11 +91,11 @@

انتخاب منبع جستجو:

- + - + - +
diff --git a/GanjooRazor/Pages/SongRecommendation/Spotify.cshtml.cs b/GanjooRazor/Pages/SongRecommendation/Spotify.cshtml.cs index 9503622c..a7d42fe8 100644 --- a/GanjooRazor/Pages/SongRecommendation/Spotify.cshtml.cs +++ b/GanjooRazor/Pages/SongRecommendation/Spotify.cshtml.cs @@ -1,4 +1,4 @@ -using GanjooRazor.Utils; +using GanjooRazor.Utils; using GSpotifyProxy.Models; using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc.ModelBinding; @@ -136,7 +136,7 @@ namespace GanjooRazor.Pages // the search flow stays in place for the day the Spotify API works again if (!SpotifyWorking) { - return Redirect($"/musiclink/?p={PoemId}"); + LastError = "جست‌وجوی خودکار قطعات اسپاتیفای موقتاً در دسترس نیست. لطفاً بعداً دوباره تلاش کنید."; } await _GetSuggestedSongs(); diff --git a/GanjooRazor/Startup.cs b/GanjooRazor/Startup.cs index 451a1bc6..5796ad48 100644 --- a/GanjooRazor/Startup.cs +++ b/GanjooRazor/Startup.cs @@ -87,7 +87,6 @@ namespace GanjooRazor options.Conventions.AddPageRoute("/SongRecommendation/Bp", "/Bp"); options.Conventions.AddPageRoute("/SongRecommendation/Golha", "/Golha"); options.Conventions.AddPageRoute("/SongRecommendation/Spotify", "/Spotify"); - options.Conventions.AddPageRoute("/SongRecommendation/MusicLink", "/MusicLink"); options.Conventions.AddPageRoute("/ImageRecommendation/Pin", "/Pin");