-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathUrlGenerator.cs
57 lines (45 loc) · 2 KB
/
UrlGenerator.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
using System;
namespace ScrapingFromOurOwn
{
public static class UrlGenerator
{
const String search_base = "https://archiveofourown.org/works?work_search[sort_column]=revised_at";
const String search_min = "&work_search[words_from]=";
const String search_max = "&work_search[words_to]=";
const String search_tag = "&tag_id=";
public static String SanitiseChars(String input) {
// replace special characters to mirror the way AO3 does
// example: tag "Draco Malfoy/Harry Potter" is stored as "Draco Malfoy*s*Harry Potter"
// example: tag "Draco Malfoy & Harry Potter" is stored as "Draco Malfoy *a* Harry Potter"
input = input.Replace("&", "*a*");
input = input.Replace("/", "*s*");
return input;
}
public static String SearchUrl(String tag_name, String custom = "") {
tag_name = SanitiseChars(tag_name);
return search_base + search_tag + tag_name + custom;
}
public static String SearchUrlMin(int min_words, String tag_name, String custom = "") {
tag_name = SanitiseChars(tag_name);
return search_base + search_min + min_words + search_tag + tag_name + custom;
}
public static String SearchUrlMax(int max_words, String tag_name, String custom = "") {
tag_name = SanitiseChars(tag_name);
return search_base + search_max + max_words + search_tag + tag_name + custom;
}
public static String SearchUrlMinMax(int min_words, int max_words, String tag_name, String custom = "") {
tag_name = SanitiseChars(tag_name);
return search_base + search_min + min_words + search_max + max_words + search_tag + tag_name + custom;
}
public static String WorkUrl(int workId, int chapterId) {
return "https://archiveofourown.org/works/" + workId.ToString() + "/chapter/" + chapterId.ToString();
}
public static String WorkUrl(int workId, bool series = false) {
if(series == true) {
return "https://archiveofourown.org/series/" + workId.ToString();
} else {
return "https://archiveofourown.org/works/" + workId.ToString();
}
}
}
}