Skip to content

Commit

Permalink
Comics Section Fixed
Browse files Browse the repository at this point in the history
Fixed the crash on downloading comics.
Removed setting all the results while searching to improve the performance.
  • Loading branch information
Xonshiz committed Aug 23, 2019
1 parent 6bed638 commit 262d978
Show file tree
Hide file tree
Showing 7 changed files with 90 additions and 89 deletions.
4 changes: 2 additions & 2 deletions src/comic_dl/comic_dl.Android/comic_dl.Android.csproj.user
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<SelectedDevice>OnePlus GM1901</SelectedDevice>
<SelectedDevice>Android Google Pixel XL - API 9.0</SelectedDevice>
<DefaultDevice>nexus_5x</DefaultDevice>
<AndroidDesignerPreferredTheme>Theme.DeviceDefault.NoActionBar.Fullscreen</AndroidDesignerPreferredTheme>
<AndroidDesignerPreferredTheme>Theme.AppCompat.Light.NoActionBar</AndroidDesignerPreferredTheme>
</PropertyGroup>
<PropertyGroup>
<UseShortFileNames>True</UseShortFileNames>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,11 @@
namespace comic_dl.Droid.customRenderer
{
// Google Test Ad Unit = "ca-app-pub-3940256099942544/6300978111";
// My Ad : ca-app-pub-8359860011604747/6645753845
#pragma warning disable CS0618 // Type or member is obsolete
public class AdViewRenderer : ViewRenderer<Controls.AdControlView, AdView>
{
string adUnitId = "ca-app-pub-8359860011604747/6645753845";
string adUnitId = "ca-app-pub-3940256099942544/6300978111";
//Note you may want to adjust this, see further down.
AdSize adSize = AdSize.SmartBanner;
AdView adView;
Expand Down
2 changes: 1 addition & 1 deletion src/comic_dl/comic_dl/Pages/comic/ComicListing.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ private async Task PopularTitlesFetcher()
}
catch (Exception LatestUpdateFetchingException)
{
Crashes.TrackError(LatestUpdateFetchingException);
//Crashes.TrackError(LatestUpdateFetchingException);
await DisplayAlert("Dead", "Exception Occurred. Please Try Again After Some Time.", "ok");
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/comic_dl/comic_dl/Pages/manga/MangaDetails.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@
</ListView>
</Frame>



<ActivityIndicator x:Name="progressBar"
HorizontalOptions="Center"
Expand Down
11 changes: 2 additions & 9 deletions src/comic_dl/comic_dl/Pages/misc/Settings.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
Margin="5"
Text="CoManga is a cross-platform application to download Comics and Manga easily from a single point. You can search Manga from this tool as well. If you want a CLI, go over to my Github and look for Comic-dl." />

<Label Text="Version : 2019-04-13"
<Label Text="Version : 2019-08-23"
Grid.Row="1"
Grid.Column="0"
FontSize="Medium"
Expand Down Expand Up @@ -60,18 +60,11 @@
Grid.Row="5"
Margin="5"
Grid.Column="0"/>

<Button Text="Donate"
Clicked="Donate_Clicked"
Margin="5"
Grid.Row="6"
Grid.Column="0"/>

<Label Text="Special Thanks To 'Truong Giang' For Compiling The iOS Distributable."
Grid.Row="7"
Grid.Column="0"
FontSize="Medium"
Margin="5"
FontAttributes="Italic"/>
</Grid>
</ContentPage>
2 changes: 1 addition & 1 deletion src/comic_dl/comic_dl/internalData/ServiceUrl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class ServiceUrl
public static string manga_information = base_manga_url + "/query/web401/info?oid=";
public static string manga_search_result = base_manga_url + "/query/web401/mrs_search";
public static string manga_search_result_details = base_manga_url + "/meta";
public static string base_comic_url = "https://comicpunch.net/";
public static string base_comic_url = "https://comicpunch.net";
public static string base_comic_image_url = base_comic_url + "/reader/";
public static string base_comic_search_url = base_comic_url + "/search/node/";
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using System.Threading.Tasks;
using comic_dl.internalData;
using Microsoft.AppCenter.Crashes;
using comic_dl.commonFunctionalities;

namespace comic_dl.parsers
{
Expand All @@ -21,36 +22,27 @@ public Task<ObservableCollection<ComicListStructure>> ExtractLatestComics(string
ComicListStructure comicListStructure = new ComicListStructure();
var doc = new HtmlDocument();
doc.LoadHtml(source);
var comicInfo = doc.DocumentNode.SelectNodes("//div[contains(@class,'popbox')]");

foreach (var item in comicInfo)
var ComicListNode = doc.GetElementbyId("Comics");
for (int i = 0; i < ComicListNode.ChildNodes.Count; i++)
{
// Popular titles show also the Manga. So, we need to remove those.
if (item.ChildNodes[3].ChildNodes[0].Attributes[0].Value.Contains("/manga/"))
continue;

// Since the Elements are in ODD Index, we need to incriment by 1 first here for Usage.
i++;
int count = ComicListNode.ChildNodes.Count;
try
{
_comicList.Add(new ComicListStructure
{
comicTitle = Convert.ToString(item.ChildNodes[1].InnerText),
comicLink = ServiceUrl.base_comic_url + Convert.ToString(item.ChildNodes[3].ChildNodes[0].Attributes[0].Value),
comicIssue = Convert.ToString(item.ChildNodes[5].InnerText).Replace("Issue", "").Replace("#", "").Trim(),
comicCoverImage = ServiceUrl.base_comic_url + Convert.ToString(item.ChildNodes[3].FirstChild.FirstChild.EndNode.Attributes[1].Value)
comicTitle = CommonFunctions.ToUpperCase(Convert.ToString(ComicListNode.ChildNodes[i].ChildNodes[3].FirstChild.ChildNodes[0].InnerText)),
comicLink = ServiceUrl.base_comic_url + Convert.ToString(ComicListNode.ChildNodes[i].ChildNodes[1].FirstChild.Attributes[0].Value),
comicIssue = Convert.ToString(ComicListNode.ChildNodes[i].ChildNodes[5].FirstChild.ChildNodes[0].InnerText).Replace("Issue", "").Replace("#", "").Trim(),
comicCoverImage = ServiceUrl.base_comic_url + Convert.ToString(ComicListNode.ChildNodes[i].ChildNodes[1].ChildNodes[0].ChildNodes[0].Attributes[1].Value)
});
}
catch (Exception)
catch (Exception Ex)
{
_comicList.Add(new ComicListStructure
{
comicTitle = Convert.ToString(item.ChildNodes[1].InnerText),
comicLink = ServiceUrl.base_comic_url + Convert.ToString(item.ChildNodes[3].ChildNodes[0].Attributes[0].Value),
comicIssue = Convert.ToString(item.ChildNodes[5].InnerText).Replace("Issue", "").Replace("#", "").Trim(),
comicCoverImage = ServiceUrl.base_comic_url + Convert.ToString(item.ChildNodes[3].FirstChild.ChildNodes[1].Attributes[1].Value)
}
);
Console.WriteLine("I right Now : " + i);
continue;
}

}

return Task.FromResult(_comicList);
Expand All @@ -61,54 +53,66 @@ public async Task<ComicDetailStructure> GetComicDetails(string comicUrl)
ComicDetailStructure comicDetailStructure = new ComicDetailStructure();
var doc = new HtmlAgilityPack.HtmlDocument();
doc.LoadHtml(await LatestComicFetcher.GetComicDetails(comicUrl));
var comicInfo = doc.DocumentNode.SelectNodes("//li[contains(@class,'info')]");
List<string> genresList = new List<string>() { };
List<string> publishersList = new List<string>() { };
// Authors Removed.
// Status Removed.
// Publication Removed
var _comicTitle = doc.DocumentNode.SelectSingleNode("//h1[contains(@class,'page-title')]");
var comicCover = doc.DocumentNode.SelectSingleNode("//img[contains(@class,'mypic')]");
var genres = doc.DocumentNode.SelectSingleNode("//div[contains(@class,'field field-name-field-genres field-type-taxonomy-term-reference field-label-above')]");
var publishers = doc.DocumentNode.SelectSingleNode("//div[contains(@class,'field field-name-field-publisher field-type-taxonomy-term-reference field-label-above')]");
var description = doc.DocumentNode.SelectSingleNode("//div[contains(@class,'field field-name-body field-type-text-with-summary field-label-hidden')]");

foreach (var genreElement in genres.ChildNodes[1].ChildNodes)
{
genresList.Add(CommonFunctions.ToUpperCase(genreElement.ChildNodes[0].FirstChild.InnerText.Trim()));
}
foreach (var publisherElement in publishers.ChildNodes[1].ChildNodes)
{
publishersList.Add(CommonFunctions.ToUpperCase(publisherElement.ChildNodes[0].FirstChild.InnerText.Trim()));
}
var comicInfo = doc.DocumentNode.SelectNodes("//div[contains(@id,'content-wrap')]");
try
{
comicDetailStructure.comicTitle = comicInfo[0].ChildNodes[1].InnerText;
comicDetailStructure.comicPubisher = comicInfo[1].ChildNodes[1].InnerText;
comicDetailStructure.comicAuthors = comicInfo[3].ChildNodes[1].InnerText;
comicDetailStructure.comicGenre = comicInfo[4].ChildNodes[1].InnerText;
comicDetailStructure.comicPubication = comicInfo[5].ChildNodes[1].InnerText;
comicDetailStructure.comicStatus = comicInfo[6].ChildNodes[1].InnerText;
comicDetailStructure.comicImage = ServiceUrl.base_comic_url + doc.DocumentNode.SelectNodes("//img[contains(@class,'series')]")[0].Attributes["src"].Value;
comicDetailStructure.comicDescription = doc.DocumentNode.SelectNodes("//li[contains(@class,'summary')]")[0].ChildNodes[1].InnerText;
comicDetailStructure.comicTitle = CommonFunctions.ToUpperCase(_comicTitle.FirstChild.InnerText);
comicDetailStructure.comicPubisher = String.Join(",", publishersList);
comicDetailStructure.comicAuthors = "";
comicDetailStructure.comicGenre = String.Join(",", genresList);
comicDetailStructure.comicPubication = "";
comicDetailStructure.comicStatus = "";
comicDetailStructure.comicImage = ServiceUrl.base_comic_url + comicCover.Attributes[1].DeEntitizeValue;
comicDetailStructure.comicDescription = description.FirstChild.InnerText;
}
catch (Exception)
catch (Exception Ex)
{
comicDetailStructure.comicAuthors = "N/A";
comicDetailStructure.comicPubication = "N/A";
comicDetailStructure.comicStatus = "N/A";

var comicTitle = doc.DocumentNode.SelectSingleNode("//h1[contains(@class,'page-title')]");
comicDetailStructure.comicTitle = comicTitle.InnerText;

var comicImage = doc.DocumentNode.SelectSingleNode("//img[contains(@class,'mypic')]");
comicDetailStructure.comicImage = ServiceUrl.base_comic_url + comicImage.Attributes["src"].Value;

var comicPubisher = doc.DocumentNode.SelectNodes("//div[contains(@class,'field field-name-field-publisher field-type-taxonomy-term-reference field-label-inline clearfix')]");
comicDetailStructure.comicPubisher = comicPubisher[0].ChildNodes[1].InnerText;

var comicGenre = doc.DocumentNode.SelectNodes("//div[contains(@class,'field field-name-field-genres field-type-taxonomy-term-reference field-label-inline clearfix')]");
comicDetailStructure.comicGenre = comicGenre[0].ChildNodes[1].InnerText;

var comicDescription = doc.DocumentNode.SelectSingleNode("//div[contains(@class,'field field-name-field-synopsis field-type-text-with-summary field-label-hidden')]");
comicDetailStructure.comicDescription = comicDescription.InnerText;
comicDetailStructure.comicTitle = (string.IsNullOrEmpty(comicDetailStructure.comicTitle)) ? "Title Not Found" : comicDetailStructure.comicTitle;
comicDetailStructure.comicPubisher = (string.IsNullOrEmpty(comicDetailStructure.comicPubisher)) ? "None" : comicDetailStructure.comicPubisher;
comicDetailStructure.comicAuthors = "";
comicDetailStructure.comicGenre = (string.IsNullOrEmpty(comicDetailStructure.comicGenre)) ? "None" : comicDetailStructure.comicGenre;
comicDetailStructure.comicPubication = "";
comicDetailStructure.comicStatus = "";
comicDetailStructure.comicImage = (string.IsNullOrEmpty(comicDetailStructure.comicImage)) ? "https://comicpunch.net/mystuff/seo-sidebar.png" : comicDetailStructure.comicImage;
comicDetailStructure.comicDescription = (string.IsNullOrEmpty(comicDetailStructure.comicDescription)) ? "No Summary Needed" : comicDetailStructure.comicDescription;
}
var comicChapters = doc.DocumentNode.SelectNodes("//li[contains(@class,'chapter')]");
foreach (var chapter in comicChapters)
{
try
if (!chapter.ChildNodes[0].InnerText.Contains("at Comicpunch.net!"))
{
comicDetailStructure.comicChapterList.Add(
new ComicChapterList
try
{
chapterTitle = chapter.InnerText,
chapterLink = chapter.ChildNodes[0].Attributes[0].Value
});
}
catch (Exception)
{
continue;
comicDetailStructure.comicChapterList.Add(
new ComicChapterList
{
chapterTitle = CommonFunctions.ToUpperCase(chapter.InnerText),
chapterLink = chapter.ChildNodes[0].Attributes[0].Value
});
}
catch (Exception Ex)
{
continue;
}
}
}
return comicDetailStructure;
Expand Down Expand Up @@ -166,21 +170,24 @@ public async Task<ObservableCollection<ComicListStructure>> ExtractComicSearch(s
int lastSearchPageNumber = Convert.ToInt16(comicLastSearchNode.Attributes["href"].Value.Split('=')[1].Trim());
await ExtractLinksFromNodes(comicLinkNodes);

for (int i = 1; i <= lastSearchPageNumber + 1; i++)
{
/* If last Search Page = 1, then we do not have multiple
* search pages.
* So, we do not need to iterate over things. We're pretty much
* done here.
*/
if (i != lastSearchPageNumber)
{
string webResponse = await LatestComicFetcher.GetComicPageContent(ServiceUrl.base_comic_search_url + searchText + "?page=" + i);
doc.LoadHtml(webResponse);
comicLinkNodes = doc.DocumentNode.SelectNodes("//h3[contains(@class,'title')]");
await ExtractLinksFromNodes(comicLinkNodes);
}
}
// Currently disabling further results.
// This needs new implementation.

//for (int i = 1; i <= lastSearchPageNumber + 1; i++)
//{
// /* If last Search Page = 1, then we do not have multiple
// * search pages.
// * So, we do not need to iterate over things. We're pretty much
// * done here.
// */
// if (i != lastSearchPageNumber)
// {
// string webResponse = await LatestComicFetcher.GetComicPageContent(ServiceUrl.base_comic_search_url + searchText + "?page=" + i);
// doc.LoadHtml(webResponse);
// comicLinkNodes = doc.DocumentNode.SelectNodes("//h3[contains(@class,'title')]");
// await ExtractLinksFromNodes(comicLinkNodes);
// }
//}

_comicList.Clear(); // Clear any previous data.
ComicDetailStructure comicDetailStructure_new = new ComicDetailStructure();
Expand Down

0 comments on commit 262d978

Please sign in to comment.