-
Notifications
You must be signed in to change notification settings - Fork 19
Expand file tree
/
Copy pathSteamRip.lua
More file actions
336 lines (286 loc) · 12.4 KB
/
SteamRip.lua
File metadata and controls
336 lines (286 loc) · 12.4 KB
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
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
-- to view examples and lua params go in this github page: https://github.com/Y0URD34TH/Project-GLD/blob/main/LuaParams.md
local VERSION = "1.2.0"
client.auto_script_update("https://raw.githubusercontent.com/Y0URD34TH/Project-GLD/refs/heads/main/Scripts/SteamRip.lua",
VERSION)
-- File hosting service detection functions
local function isGofileLink(link)
return string.find(link, "gofile")
end
local function isVikingFileLink(link)
-- Support both vikingfile.com and vik1ngfile.site
return string.find(link, "vikingfile%.com") or string.find(link, "vik1ngfile%.site")
end
local function isQiwiLink(link)
return string.find(link, "qiwi%.gg")
end
local function isBuzzLink(link)
return string.find(link, "buzzheavier%.com")
end
local function isMegaDBLink(link)
return string.find(link, "megadb%.net")
end
local function isMegaUpLink(link)
return string.find(link, "megaup%.net")
end
local function isMediafireLink(link)
return string.find(link, "mediafire%.com") or string.find(link, "download%d*%.mediafire%.com")
end
local function isPixeldrainLink(link)
return string.find(link, "pixeldrain%.com")
end
-- Get display name for file host
local function getFileHostName(link)
if isGofileLink(link) then
return "Download (Gofile)"
elseif isVikingFileLink(link) then
return "Download (VikingFile)"
elseif isQiwiLink(link) then
return "Download (Qiwi)"
elseif isBuzzLink(link) then
return "Download (Buzzheavier)"
elseif isMegaDBLink(link) then
return "Download (MegaDB)"
elseif isMegaUpLink(link) then
return "Download (MegaUp)"
elseif isMediafireLink(link) then
return "Download (Mediafire)"
elseif isPixeldrainLink(link) then
return "Download (Pixeldrain)"
else
return "Download"
end
end
local function shouldAutoDownload(link)
return isGofileLink(link) or
isMediafireLink(link) or
isPixeldrainLink(link) or
isVikingFileLink(link) or
isQiwiLink(link) or
isBuzzLink(link) or
isMegaDBLink(link) or
isMegaUpLink(link)
end
local function endsWith(str, pattern)
return string.sub(str, -string.len(pattern)) == pattern
end
local function substituteRomanNumerals(gameName)
local romans = {
[" I"] = " 1",
[" II"] = " 2",
[" III"] = " 3",
[" IV"] = " 4",
[" V"] = " 5",
[" VI"] = " 6",
[" VII"] = " 7",
[" VIII"] = " 8",
[" IX"] = " 9",
[" X"] = " 10"
}
for numeral, substitution in pairs(romans) do
if endsWith(gameName, numeral) then
gameName = string.sub(gameName, 1, -string.len(numeral) - 1) .. substitution
end
end
return gameName
end
local headers = {
["User-Agent"] =
"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36 ProjectGLD/2.15"
}
local function webScrapeSteamRip(gameName)
gameName = substituteRomanNumerals(gameName)
gameName = gameName:gsub(":", "")
local searchUrl = "https://steamrip.com/?s=" .. gameName:gsub(" ", "%%20")
local responseBody = http.get(searchUrl, headers)
if not responseBody then
return {}
end
local gameResults = {}
-- Parse search results page
local searchDoc = html.parse(responseBody)
-- Find all game card links
local gameLinks = searchDoc:css('a.all-over-thumb-link')
-- Find all game titles
local gameTitles = searchDoc:css('h2')
-- Build list of game names (filter out empty ones)
local gameNames = {}
for i = 1, #gameTitles do
local titleText = gameTitles[i]:text()
if titleText and titleText ~= "" then
-- Clean up whitespace
titleText = titleText:gsub("^%s*(.-)%s*$", "%1")
table.insert(gameNames, titleText)
end
end
-- Process each game
for i = 1, #gameLinks do
local gameLink = "https://steamrip.com/" .. gameLinks[i]:attr("href")
if gameLink and gameNames[i] then
-- Fetch game detail page
local gameResponseBody = http.get(gameLink, headers)
if gameResponseBody then
local gameDoc = html.parse(gameResponseBody)
local version = ""
local versionPattern = "<li>.-<strong>Version</strong>%s*:%s*(.-)</li>"
local versionMatch = string.match(gameResponseBody, versionPattern)
if versionMatch then
version = string.gsub(versionMatch, "^%s*(.-)%s*$", "%1")
end
local size = ""
-- Extract game size
local sizePattern = "<li>.-<strong>Game Size:%s*</strong>%s*(.-)</li>"
local sizeMatch = string.match(gameResponseBody, sizePattern)
if sizeMatch then
size = string.gsub(sizeMatch, "^%s*(.-)%s*$", "%1")
end
-- Create game result
local gameResult = {
name = "[" .. size .. "] " .. gameNames[i],
links = {},
tooltip = "Size: " .. size .. "\nVersion: " .. version,
ScriptName = "SteamRip-Main"
}
-- Find all download links (green and purple buttons)
local greenButtons = gameDoc:css('a.shortc-button.medium.green')
local purpleButtons = gameDoc:css('a.shortc-button.medium.purple')
-- Process green buttons
for j = 1, #greenButtons do
local href = greenButtons[j]:attr("href")
if href then
-- Add protocol if missing
if href:sub(1, 2) == "//" then
href = "https:" .. href
end
-- Check which file host and add appropriate link
if isGofileLink(href) or isVikingFileLink(href) or isQiwiLink(href) or
isBuzzLink(href) or isMegaDBLink(href) or isMegaUpLink(href) or
isMediafireLink(href) or isPixeldrainLink(href) then
table.insert(gameResult.links, {
name = getFileHostName(href),
link = href,
addtodownloadlist = shouldAutoDownload(href)
})
end
end
end
-- Process purple buttons
for j = 1, #purpleButtons do
local href = purpleButtons[j]:attr("href")
if href then
-- Add protocol if missing
if href:sub(1, 2) == "//" then
href = "https:" .. href
end
-- Check which file host and add appropriate link
if isGofileLink(href) or isVikingFileLink(href) or isQiwiLink(href) or
isBuzzLink(href) or isMegaDBLink(href) or isMegaUpLink(href) or
isMediafireLink(href) or isPixeldrainLink(href) then
table.insert(gameResult.links, {
name = getFileHostName(href),
link = href,
addtodownloadlist = shouldAutoDownload(href)
})
end
end
end
-- Only add if we found links
if #gameResult.links > 0 then
table.insert(gameResults, gameResult)
end
end
end
end
return gameResults
end
local version = client.GetVersionDouble()
local defaultdir = "C:/Games"
if version < 6.95 then
Notifications.push_error("Lua Script", "Program is Outdated. Please Update to use this Script")
else
Notifications.push_success("Lua Script", "SteamRip Script Loaded and Working")
menu.add_input_text("SteamRip Game Dir")
menu.set_text("SteamRip Game Dir", defaultdir)
settings.load()
local function searchSteamRip()
settings.save()
local gamename = game.getgamename()
local results = webScrapeSteamRip(gamename)
communication.receiveSearchResults(results)
end
local imagelink = ""
local gamename = ""
local expectedurl = ""
local function ondownloadclick(gamejson, downloadurl, scriptname)
if scriptname == "SteamRip-Main" then
expectedurl = downloadurl
end
local jsonResults = JsonWrapper.parse(gamejson)
local coverImageUrl = jsonResults["cover"]["url"]
if coverImageUrl and coverImageUrl:sub(1, 2) == "//" then
coverImageUrl = "https:" .. coverImageUrl
end
if coverImageUrl then
coverImageUrl = coverImageUrl:gsub("t_thumb", "t_cover_big")
end
local jsonName = JsonWrapper.parse(gamejson).name
gamename = jsonName
imagelink = coverImageUrl
end
local pathcheck = ""
local function ondownloadcompleted(path, url)
if expectedurl == url then
local gamenametopath = gamename
gamenametopath = gamenametopath:gsub(":", "")
local installDir = menu.get_text("SteamRip Game Dir") .. "/" .. gamenametopath .. "/"
path = path:gsub("\\", "/")
pathcheck = path
zip.extract(path, installDir, false)
end
settings.save()
end
local function onextractioncompleted(origin, path)
if pathcheck == origin then
path = path:gsub("/", "\\")
local folders = file.listfolders(path)
local secondFolder = folders[1]
if secondFolder then
local fullFolderPath = path .. "\\" .. secondFolder
local executables = file.listexecutables(fullFolderPath)
-- Get the first executable
if executables and #executables >= 1 then
local firstExecutable = executables[1]
local fullExecutablePath = fullFolderPath .. "\\" .. firstExecutable
local gameidl = GameLibrary.GetGameIdFromName(gamename)
if gameidl == -1 then
local imagePath = Download.DownloadImage(imagelink)
GameLibrary.addGame(fullExecutablePath, imagePath, gamename, "")
Notifications.push_success("SteamRip Script", "Game Successfully Installed!")
else
GameLibrary.changeGameinfo(gameidl, fullExecutablePath)
Notifications.push_success("SteamRip Script", "Game Successfully Installed!")
end
else
-- Try recursive search
local executables2 = file.listexecutablesrecursive(fullFolderPath)
if executables2 and #executables2 >= 1 then
local firstExecutable = executables2[1]
local gameidl = GameLibrary.GetGameIdFromName(gamename)
if gameidl == -1 then
local imagePath = Download.DownloadImage(imagelink)
GameLibrary.addGame(firstExecutable, imagePath, gamename, "")
Notifications.push_success("SteamRip Script", "Game Successfully Installed!")
else
GameLibrary.changeGameinfo(gameidl, firstExecutable)
Notifications.push_success("SteamRip Script", "Game Successfully Installed!")
end
end
end
end
end
end
-- Register all callbacks
client.add_callback("on_scriptselected", searchSteamRip)
client.add_callback("on_downloadclick", ondownloadclick)
client.add_callback("on_downloadcompleted", ondownloadcompleted)
client.add_callback("on_extractioncompleted", onextractioncompleted)
end