Untitled

mail@pastecode.io avatar
unknown
csharp
2 years ago
3.1 kB
2
Indexable
Never
using HtmlAgilityPack;
using System.Collections;
using System.Collections.Generic;
using System.Text.RegularExpressions;
using System;
using System.Web;

namespace Sushi_DL
{
    public partial class Form1 : Form
    {
        List<string> titles = new();
        List<string> urls = new();

        Dictionary<string, string> _mangasUrl = new();

        public Form1()
        {
            InitializeComponent();
        }

        private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
            nameLabel.Text = listBox1.SelectedItem.ToString();

            ParseItem(nameLabel.Text);
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            HtmlWeb web = new();
            HtmlAgilityPack.HtmlDocument doc = new();

            string link = "https://sushiscan.su/manga/list-mode/";

            doc = web.Load(link);

            foreach (HtmlNode li in doc.DocumentNode.SelectNodes("/html[1]/body[1]/div[1]/div[2]/div[1]/div[1]/div[1]/div[2]/div[5]//li"))
            {
                if (li.InnerHtml.Contains("series"))
                {
                    string s = li.InnerText;
                    string a = HttpUtility.HtmlDecode(s);

                    listBox1.Items.Add(a);
                    titles.Add(a);
                }
            }

            foreach (HtmlNode href in doc.DocumentNode.SelectNodes("/html[1]/body[1]/div[1]/div[2]/div[1]/div[1]/div[1]/div[2]/div[5]//li/a[@href]"))
            {               
                urls.Add(href.GetAttributeValue("href", string.Empty));
            }

            for (var i = 0; i < titles.Count; i++)
            {
                _mangasUrl.Add(titles[i], urls[i]);
            }
        }

        private void ParseItem(string t)
        {
            string url = _mangasUrl[t];

            Image cover;

            HtmlWeb web = new();
            HtmlAgilityPack.HtmlDocument doc = new();

            doc = web.Load(url);

            var altExists = doc.DocumentNode.Descendants("span").Any(d => d.GetAttributeValue("class", "") == "alternative");

            if (altExists)
            {
                foreach (HtmlNode alt in doc.DocumentNode.SelectNodes("/html[1]/body[1]/div[1]/div[2]/div[1]/div[2]/article[1]/div[1]/div[2]/div[1]/div[1]/div[1]/span"))
                {
                    if (alt.NodeType == HtmlNodeType.Element)
                    {
                        altTitleLabel.Text = alt.InnerText;
                    }
                }
            }
            else
            {
                altTitleLabel.Text = String.Empty;
            }

            foreach (HtmlNode src in doc.DocumentNode.SelectNodes("/html[1]/body[1]/div[1]/div[2]/div[1]/div[2]/article[1]/div[1]/div[1]/div[1]/div[1]/img"))
            {
                if (src.NodeType == HtmlNodeType.Element)
                {
                    coverBox.Load(src.GetAttributeValue("src", string.Empty));
                }
            }
        }
    }
}