diff --git a/AniStream/MainActivity.cs b/AniStream/MainActivity.cs index dbc3857..0d5bdcf 100644 --- a/AniStream/MainActivity.cs +++ b/AniStream/MainActivity.cs @@ -27,7 +27,6 @@ using Juro.Providers.Anime; using Microsoft.Maui.ApplicationModel; using Microsoft.Maui.Storage; -using static Android.Renderscripts.ScriptGroup; using AlertDialog = AndroidX.AppCompat.App.AlertDialog; namespace AniStream; @@ -290,6 +289,9 @@ private void SetupViewPager() case AnimeSites.AnimePahe: bottomNavigationView.InflateMenu(Resource.Menu.bottommenu5); break; + case AnimeSites.NineAnime: + bottomNavigationView.InflateMenu(Resource.Menu.bottommenu_nineanime); + break; } viewPager.CurrentItem = 0; @@ -301,21 +303,6 @@ private void SetupViewPager() { switch (e.Item.ItemId) { - //Server1 - case Resource.Id.lastUpdated1: - viewPager.CurrentItem = 0; - break; - case Resource.Id.popular1: - viewPager.CurrentItem = 1; - break; - case Resource.Id.ongoing1: - viewPager.CurrentItem = 2; - break; - case Resource.Id.movies1: - viewPager.CurrentItem = 3; - break; - - //Server2 case Resource.Id.Popular: viewPager.CurrentItem = 0; break; @@ -410,6 +397,7 @@ private async void SetupSources(IMenu menu) var gogoanime = menu.FindItem(Resource.Id.source_gogoanime); var zoro = menu.FindItem(Resource.Id.source_zoro); var animepahe = menu.FindItem(Resource.Id.source_animepahe); + var nineanime = menu.FindItem(Resource.Id.source_nineanime); switch (WeebUtils.AnimeSite) { @@ -422,6 +410,9 @@ private async void SetupSources(IMenu menu) case AnimeSites.AnimePahe: animepahe?.SetChecked(true); break; + case AnimeSites.NineAnime: + nineanime?.SetChecked(true); + break; } } @@ -473,6 +464,8 @@ private async void SaveSelectedSource(int id) WeebUtils.AnimeSite = AnimeSites.Zoro; else if (id == Resource.Id.source_animepahe) WeebUtils.AnimeSite = AnimeSites.AnimePahe; + else if (id == Resource.Id.source_nineanime) + WeebUtils.AnimeSite = AnimeSites.NineAnime; if (lastAnimeSite != WeebUtils.AnimeSite) { diff --git a/AniStream/Services/DownloadService.cs b/AniStream/Services/DownloadService.cs index 571488e..625cf2b 100644 --- a/AniStream/Services/DownloadService.cs +++ b/AniStream/Services/DownloadService.cs @@ -7,7 +7,7 @@ using Android.Util; using AndroidX.Core.App; using AniStream.Utils.Downloading; -using JGrabber.Grabbed; +using Httpz.Hls; using Newtonsoft.Json; namespace AniStream.Services; @@ -29,13 +29,18 @@ public override async void HandleMessage(Message msg) var downloader = new HlsDownloader(_downloadService); - var stream = JsonConvert.DeserializeObject(msg.Data.GetString("stream")!)!; + var stream = JsonConvert.DeserializeObject(msg.Data.GetString("stream")!)!; var headers = JsonConvert.DeserializeObject>(msg.Data.GetString("headers")!)!; var fileName = msg.Data.GetString("fileName")!; try { - await downloader.DownloadAsync(fileName, stream, headers, CancellationTokenSource.Token); + await downloader.DownloadAsync( + fileName, + stream, + headers, + CancellationTokenSource.Token + ); } catch (Exception e) { diff --git a/AniStream/Utils/Downloading/Downloader.cs b/AniStream/Utils/Downloading/Downloader.cs index 6d6d485..23968c7 100644 --- a/AniStream/Utils/Downloading/Downloader.cs +++ b/AniStream/Utils/Downloading/Downloader.cs @@ -9,7 +9,6 @@ using AniStream.Services; using AniStream.Utils.Extensions; using AniStream.Utils.Listeners; -using JGrabber.Grabbed; using Newtonsoft.Json; namespace AniStream.Utils.Downloading; @@ -172,6 +171,10 @@ public async Task DownloadHls( string url, Dictionary headers) { + // User-agent + if (!headers.ContainsKey("User-Agent")) + headers.Add("User-Agent", Httpz.Utils.Http.ChromeUserAgent()); + var loadingDialog = WeebUtils.SetProgressDialog( _activity, "Getting qualities. Please wait...", @@ -185,17 +188,20 @@ public async Task DownloadHls( cancellationTokenSource.Cancel(); }; - var metadataResources = new List(); + var qualities = new List(); try { var downloader = new Httpz.HlsDownloader(Http.ClientProvider); - metadataResources = await downloader.GetHlsStreamMetadatasAsync( - url, - headers, - cancellationTokenSource.Token - ); + await Task.Run(async () => + { + qualities = await downloader.GetQualitiesAsync( + url, + headers, + cancellationTokenSource.Token + ); + }); loadingDialog.Dismiss(); } @@ -213,7 +219,7 @@ public async Task DownloadHls( listener.OnItemClick += async (s, which) => { loadingDialog = WeebUtils.SetProgressDialog(_activity, "Loading...", false); - var stream = await metadataResources[which].Stream; + var stream = qualities[which].Stream!; loadingDialog.Dismiss(); //var intent = new Intent(); @@ -230,7 +236,7 @@ public async Task DownloadHls( builder.SetTitle(fileName); builder.SetNegativeButton("Cancel", (s, e) => { }); - var items = metadataResources.Select(x => x.Resolution?.ToString() + var items = qualities.Select(x => x.Resolution?.ToString() ?? "Default quality").ToArray(); builder.SetItems(items, listener); diff --git a/AniStream/Utils/Downloading/HlsDownloader.cs b/AniStream/Utils/Downloading/HlsDownloader.cs index e8c0491..3daedc1 100644 --- a/AniStream/Utils/Downloading/HlsDownloader.cs +++ b/AniStream/Utils/Downloading/HlsDownloader.cs @@ -9,7 +9,7 @@ using AndroidX.Core.Content; using AniStream.Services; using AniStream.Utils.Extensions; -using JGrabber.Grabbed; +using Httpz.Hls; using Laerdal.FFmpeg.Android; using Microsoft.Maui.Storage; @@ -28,7 +28,7 @@ public HlsDownloader(Service service) public async Task DownloadAsync( string fileName, - GrabbedHlsStream stream, + HlsStream stream, Dictionary headers, CancellationToken cancellationToken = default) {