-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b216d0d
commit 70ddc61
Showing
13 changed files
with
275 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
namespace AnimDL.UI.Core; | ||
|
||
public class Constants | ||
{ | ||
public const string UserAgent = @"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/104.0.5112.81 Safari/537.36 Edg/104.0.1293.54"; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace AnimDL.UI.Core.Contracts; | ||
|
||
public interface IFeaturedAnimeProvider | ||
{ | ||
IObservable<IEnumerable<FeaturedAnime>> GetFeaturedAnime(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
namespace AnimDL.UI.Core.Contracts; | ||
|
||
public interface IRecentEpisodesProvider | ||
{ | ||
IObservable<IEnumerable<AiredEpisode>> GetRecentlyAiredEpisodes(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
namespace AnimDL.UI.Core.Models; | ||
|
||
public class AiredEpisode | ||
{ | ||
public string Anime { get; set; } | ||
public string InfoText { get; set; } | ||
public string EpisodeUrl { get; set; } | ||
public string Image { get; set; } | ||
public DateTime TimeOfAiring { get; set; } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
using System.Text.Json.Serialization; | ||
|
||
namespace AnimDL.UI.Core.Models; | ||
|
||
public class FeaturedAnime | ||
{ | ||
public string Id => Url?.Split(new[] { '/' }, StringSplitOptions.RemoveEmptyEntries).Skip(1).Take(1).FirstOrDefault(); | ||
public string[] GenresArray => Genres?.Split(","); | ||
|
||
[JsonPropertyName("title")] | ||
public string Title { get; set; } | ||
|
||
[JsonPropertyName("url")] | ||
public string Url { get; set; } | ||
|
||
[JsonPropertyName("img")] | ||
public string Image { get; set; } | ||
|
||
[JsonPropertyName("genre")] | ||
public string Genres { get; set; } | ||
|
||
[JsonPropertyName("desc")] | ||
public string Description { get; set; } | ||
} |
29 changes: 29 additions & 0 deletions
29
AnimDL.UI.Core/Services/AnimixPlayFeaturedAnimeProvider.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
namespace AnimDL.UI.Core.Services; | ||
|
||
public class AnimixPlayFeaturedAnimeProvider : IFeaturedAnimeProvider | ||
{ | ||
private readonly HttpClient _httpClient; | ||
|
||
public AnimixPlayFeaturedAnimeProvider(HttpClient httpClient) | ||
{ | ||
_httpClient = httpClient; | ||
_httpClient.DefaultRequestHeaders.UserAgent.ParseAdd(Constants.UserAgent); | ||
} | ||
|
||
public IObservable<IEnumerable<FeaturedAnime>> GetFeaturedAnime() | ||
{ | ||
return Observable.Create<IEnumerable<FeaturedAnime>>(async observer => | ||
{ | ||
var response = await _httpClient.GetAsync("https://animixplay.to/assets/s/featured.json"); | ||
|
||
if(!response.IsSuccessStatusCode) | ||
{ | ||
observer.OnError(new Exception("response does not contain success code")); | ||
} | ||
|
||
var stream = await response.Content.ReadAsStreamAsync(); | ||
observer.OnNext(await JsonSerializer.DeserializeAsync<List<FeaturedAnime>>(stream)); | ||
observer.OnCompleted(); | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
using System.Globalization; | ||
using System.Text.Json.Nodes; | ||
|
||
namespace AnimDL.UI.Core.Services; | ||
|
||
public class AnimixPlayEpisodesProvider : IRecentEpisodesProvider | ||
{ | ||
private readonly HttpClient _httpClient; | ||
|
||
public AnimixPlayEpisodesProvider(HttpClient httpClient) | ||
{ | ||
_httpClient = httpClient; | ||
_httpClient.DefaultRequestHeaders.UserAgent.ParseAdd(Constants.UserAgent); | ||
} | ||
|
||
public IObservable<IEnumerable<AiredEpisode>> GetRecentlyAiredEpisodes() | ||
{ | ||
return Observable.Create<IEnumerable<AiredEpisode>>(async observer => | ||
{ | ||
Dictionary<string, string> postData = new() | ||
{ | ||
["seasonal"] = DateTime.UtcNow.ToString("yyyy-MM-dd HH:mm:ss") | ||
}; | ||
|
||
using var content = new FormUrlEncodedContent(postData); | ||
content.Headers.Clear(); | ||
content.Headers.Add("Content-Type", "application/x-www-form-urlencoded"); | ||
|
||
using var request = new HttpRequestMessage(HttpMethod.Post, @"https://animixplay.to/api/search"); | ||
request.Content = content; | ||
var response = await _httpClient.SendAsync(request); | ||
|
||
if (!response.IsSuccessStatusCode) | ||
{ | ||
observer.OnError(new Exception("http resonse doesn't contain success code")); | ||
} | ||
|
||
var result = await response.Content.ReadAsStringAsync(); | ||
|
||
if (string.IsNullOrEmpty(result)) | ||
{ | ||
observer.OnError(new Exception("empty json response")); | ||
} | ||
|
||
var jObject = JsonNode.Parse(result); | ||
var episodes = jObject["result"].AsArray(); | ||
|
||
if (episodes is null) | ||
{ | ||
observer.OnError(new Exception("no episodes")); | ||
} | ||
|
||
var models = new List<AiredEpisode>(); | ||
|
||
foreach (var item in episodes) | ||
{ | ||
try | ||
{ | ||
var model = new AiredEpisode | ||
{ | ||
Anime = (string)item["title"].AsValue(), | ||
EpisodeUrl = $"https://animixplay.to{(string)item["url"].AsValue()}", | ||
InfoText = (string)item["infotext"].AsValue(), | ||
TimeOfAiring = DateTime.ParseExact((string)item["timetop"].AsValue(), "yyyy-MM-dd HH:mm:ss", CultureInfo.InvariantCulture).ToLocalTime(), | ||
Image = (string)item["picture"].AsValue() | ||
}; | ||
|
||
models.Add(model); | ||
} | ||
catch { } | ||
} | ||
|
||
observer.OnNext(models); | ||
|
||
observer.OnCompleted(); | ||
|
||
return Disposable.Empty; | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters