-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathGetIDs.php
191 lines (171 loc) · 6.78 KB
/
GetIDs.php
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
<html>
<body>
<title>Crawl boorus for ID links<?php echo isset($_GET['domain'])
?
' - ' . $_GET['domain'] .
'--' .
str_replace(" ", "+", $_GET['tags'])
:
''
; ?></title>
<style> a { text-decoration: none; } </style>
<form action="<?php basename($_SERVER['SCRIPT_FILENAME']); ?>" method="get">
URL: <input autofocus type="text" id="url" size="100" placeholder="http://"
value="<?php echo isset($_GET['domain'])
?
'http://' . $_GET['domain'] .
'/index.php?page=post&s=list&tags=' .
str_replace(" ", "+", $_GET['tags'])
:
''
; ?>" />
<!-- <URL-parameters order="domain, tags, pids"> -->
<!-- <HIDDEN> -->
<input type="text" name="domain" id="domain" value="" style="display:none;" />
<input type="text" name="tags" id="tags" value="" style="display:none;" />
<!-- </HIDDEN> -->
<br />Pages to display: <input type="text" name="pids" size="6" placeholder="#"
value="<?php echo isset($_GET['pids'])
?
$_GET['pids']
:
''
; ?>" />
<!-- </URL-parameters> -->
<br /><input type="submit" id="submit" value="Crawl" />
<!--<input type="button" value="Open links" onclick="open_urls()" />-->
</form>
<script>
document.getElementById("submit").addEventListener("click", function() {
document.getElementById("domain").value =
document.getElementById("url").value.replace(/https?:\/\//g, "")
.replace(/\/.*/g, "");
document.getElementById("tags").value =
document.getElementById("url").value.replace(/https?:.*&tags=/g, "")
.replace(/\+/g, " ")
.replace(/&pid=\d+/g, "");
});
/*
// Although the following code block works I am not including it for certain reasons:[1]
function open_urls() {
var urls = [], links = document.links;
// Getting array of URLs
for (i = 0; i < links.length; i++) {
urls.push(links[i].href);
}
// Opening URLs in new tabs
for (i = 0; i < urls.length; i++) {
window.open(urls[i],"_blank");
}
}
// 1. See https://addons.mozilla.org/en-US/firefox/addon/load-tab-on-select/reviews/803154/
*/
</script>
<?php
set_time_limit(999);
$max_pages = isset($_GET['pids']) ? $_GET['pids'] : '';
if (isset($_GET['domain']))
{
if (strcmp("gelbooru",$_GET['domain']) == 0)
{
$booru_URL =
'https://' . $_GET['domain'] . '/index.php?page=post&s=list&tags=' . $_GET['tags'];
}
else
{
$booru_URL =
'http://' . $_GET['domain'] . '/index.php?page=post&s=list&tags=' . $_GET['tags'];
}
}
else
{
$booru_URL = '';
}
$booru_URL_domain = preg_replace('/(https?:\/\/)([^\/]*)(.*&tags=.*)/i', '$2', $booru_URL);
function get_links($url_domain, $url, $page_number) {
$input = @file_get_contents($url);
if ($url_domain == "rule34.xxx"
|| $url_domain == "xbooru.com"
|| $url_domain == "furry.booru.org") {
$regex = "<a [^>]* href=(\"??)index.php.page.post&s=view&id=([^\" >]*?)\" >(.*)<\/a>";
} else if ($url_domain == "gelbooru.com") {
$regex = "<a [^>]* href=(\"??)..gelbooru.com.index.[^d]+id=([^\" >]*?)\" >(.*)<\/a>";
} else {
$regex = "<a [^>]* href=(\"??)index.php.page.post&s=view&id=([^\" >]*?)\">(.*)<\/a>";
}
preg_match_all("/$regex/siU", $input, $matches);
// Links on pages aren't always 42: getting 42 or less # for next loop
$matches2 = array();
for ($i = 0; $i < count($matches[2]); $i++) {
$matches2[$i + 1] = $matches[2][$i];
}
// Converting /\d+/ numbers in indices to HTML links:
for ($i = 1; $i < count($matches2) + 1; $i++) {
$matches2[$i] = '<a href="http://' . $url_domain . '/index.php?page=post&s=view&id=' .
$matches2[$i] . '">post #' . $matches2[$i] . '</a>';
}
// Output of links on pages:
if (count($matches2) !== 0) {
echo "<pre>";
echo str_replace('Array',
'Page #' . $page_number . ":",
str_replace(array('[',']','(',')'),
'',
str_replace(' => ','. ',print_r($matches2,true))));
echo "</pre>";
}
}
if ($booru_URL_domain == "rule34.xxx" || $booru_URL_domain == "xbooru.com"
|| $booru_URL_domain == "furry.booru.org" || $booru_URL_domain == "gelbooru.com") {
for ($i = 0; $i < 42 * $max_pages; $i += 42) {
$to_crawl = $booru_URL . "&pid=" . $i;
get_links($booru_URL_domain, $to_crawl, ($i / 42) + 1);
}
} else {
for ($i = 0; $i < 20 * $max_pages; $i += 20) {
$to_crawl = $booru_URL . "&pid=" . $i;
get_links($booru_URL_domain, $to_crawl, ($i / 20) + 1);
}
}
?>
<table>
<tr><td>Text to Save:</td></tr>
<tr>
<td colspan="3">
<textarea id="inputTextToSave" cols="80" rows="10"></textarea>
</td>
</tr>
<tr>
<td>Filename to Save As:</td>
<td><input id="inputFileNameToSaveAs" value="BooruLinks.txt"></input></td>
<td><button onclick="saveTextAsFile()">Save Text to File</button></td>
</tr>
</table>
<script>
var rawLinks = [];
for (i = 0; i < document.getElementsByTagName('a').length; i++) {
rawLinks[i] = document.getElementsByTagName('a')[i].href.toString();
}
document.getElementById("inputTextToSave").value = rawLinks.join("\n");
function saveTextAsFile()
{
var textToSave = document.getElementById("inputTextToSave").value;
var textToSaveAsBlob = new Blob([textToSave], {type:"text/plain"});
var textToSaveAsURL = window.URL.createObjectURL(textToSaveAsBlob);
var fileNameToSaveAs = document.getElementById("inputFileNameToSaveAs").value;
var downloadLink = document.createElement("a");
downloadLink.download = fileNameToSaveAs;
downloadLink.innerHTML = "Download File";
downloadLink.href = textToSaveAsURL;
downloadLink.onclick = destroyClickedElement;
downloadLink.style.display = "none";
document.body.appendChild(downloadLink);
downloadLink.click();
}
function destroyClickedElement(event)
{
document.body.removeChild(event.target);
}
</script>
</body>
</html>