rhentai/Gallery.cs

84 lines
2.4 KiB
C#

using System.Collections.Generic;
using System;
namespace Gallery
{
// Class Gallery Here are informations about the current random stored
public class Gallery{
public int GalleryId { get; }
public List<string> Tags { get; }
public Gallery(string HttpGalleryString)
{
GalleryId = GetGalleryId(HttpGalleryString);
Tags = GetTags(HttpGalleryString);
}
private List<string> GetTags(string HttpGalleryString){
List<string> Tags = new List<string>();
string TagsSection = "";
string Tag = "";
int LastStartTagName;
int StartTagName;
int EndTagName;
string Pattern1 = "class=\"name\">";
string Pattern2 = "</span>";
int IndexOfTags = HttpGalleryString.IndexOf("Tags:");
int IndexOfArtists = HttpGalleryString.IndexOf("Artists:");
for (int i = IndexOfTags; i < IndexOfArtists; i++){
TagsSection += HttpGalleryString[i];
}
StartTagName = TagsSection.IndexOf(Pattern1) + Pattern1.Length;
EndTagName = TagsSection.IndexOf(Pattern2, StartTagName);
do{
Tag = "";
for (int i = StartTagName; i < EndTagName; i++){
Tag += TagsSection[i];
}
Tags.Add(Tag);
LastStartTagName = StartTagName;
StartTagName = TagsSection.IndexOf(Pattern1, EndTagName) + Pattern1.Length;
EndTagName = TagsSection.IndexOf(Pattern2, StartTagName);
} while (LastStartTagName < StartTagName);
for (int i = 0; i < Tags.Count; i++){
if (Tags[i].Contains('=')){
Tags.Clear();
Tags.Add("Haha, kei Tags UmU");
}
}
return Tags;
}
private int GetGalleryId(string HttpGalleryString){
string Pattern1 = "#</span>";
string Pattern2 = "</h3>";
string GalleryId = "";
int StartIndex = HttpGalleryString.IndexOf(Pattern1) + Pattern1.Length;
for (int i = StartIndex; i < HttpGalleryString.IndexOf(Pattern2, StartIndex); i++){
GalleryId += HttpGalleryString[i];
}
return int.Parse(GalleryId);
}
}
}