-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbittorrent.vbml
485 lines (467 loc) · 16.7 KB
/
bittorrent.vbml
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
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
# VBML 1.0.3
#--------------------------------------------------------------------------------------------------
# Properties
#--------------------------------------------------------------------------------------------------
type: backend
source: https://raw.githubusercontent.com/omega-gg/backend/master/bittorrent.vbml
api: 1.0.3
version: 1.0.24
title: BitTorrent
cover: /cover/bittorrent.png
items:
playlist:
title: Tracks
folder:
title: Torrents & Magnets
label: all
folder:
title: Torrents
folder:
title: Magnets
validate: .torrent$|^magnet:?
#--------------------------------------------------------------------------------------------------
# Routines
#--------------------------------------------------------------------------------------------------
TRACK_OUTPUT: |
SET fragment (URL_FRAGMENT url)
SET index (INDEX_END fragment '.')
IF (NOT_EQUAL index -1)
SET fragment (MID fragment index)
IF (EXTENSION_IS_AUDIO fragment)
RETURN "audio"
FI
FI
RETURN "video"
PLAYLIST_INFO: |
IF (EQUAL (URL_EXTENSION url) "torrent")
OR (START_WITH url "magnet:?")
SET type "playlist"
SET id url
RETURN true
FI
URL_PLAYLIST: |
RETURN id
QUERY_TRACK: |
IF (START_WITH url "magnet:?")
SET type "torrent"
ELIF (NOT_EQUAL (URL_EXTENSION url) "torrent")
RETURN false
FI
SET index (INDEX_END url '#')
IF (EQUAL index -1)
SET queryData -1
ELSE
SET indexB (INDEX_OF url '.' index)
IF (EQUAL indexB -1)
SET queryData (MID url index)
ELSE
SET queryData (MID url index (SUB indexB index))
FI
SET url (MID url 0 (SUB index 1))
FI
RETURN true
QUERY_PLAYLIST: |
IF (START_WITH url "magnet:?")
SET type "torrent"
ELIF (NOT_EQUAL (URL_EXTENSION url) "torrent")
RETURN false
FI
SET index (INDEX_END url '#')
IF (EQUAL index -1)
SET queryData -1
ELSE
SET indexB (INDEX_OF url '.' index)
IF (EQUAL indexB -1)
SET queryData (MID url index)
ELSE
SET queryData (MID url index (SUB indexB index))
FI
SET url (MID url 0 (SUB index 1))
FI
RETURN true
CREATE_QUERY: |
IF (EQUAL method "search")
IF (EQUAL label "tracks")
SET backend "bittorrent"
SET url "https://html.duckduckgo.com/html"
SET q (SIMPLIFY q)
SET queryData q
IF (EQUAL (START_WITH "torrent ") false)
SET q (PREPEND q "torrent ")
FI
URL_ADD_QUERY url "q" (URL_ENCODE q)
URL_ADD_QUERY url "kl" "us-en"
URL_ADD_QUERY url "kp" "-1"
SET id 3
SET header true
ELIF (EQUAL label "all")
SET backend "bittorrent"
SET url "https://html.duckduckgo.com/html"
SET q (SIMPLIFY q)
IF (EQUAL (START_WITH "torrent ") false)
SET q (PREPEND q "torrent ")
FI
URL_ADD_QUERY url "q" (URL_ENCODE q)
URL_ADD_QUERY url "kl" "us-en"
URL_ADD_QUERY url "kp" "-1"
SET id 1
SET header true
ELIF (EQUAL label "torrents")
SET backend "bittorrent"
SET url "https://html.duckduckgo.com/html"
SET q (SIMPLIFY q)
IF (EQUAL (START_WITH "torrent ") false)
SET q (PREPEND q "torrent ")
FI
URL_ADD_QUERY url "q" (URL_ENCODE q)
URL_ADD_QUERY url "kl" "us-en"
URL_ADD_QUERY url "kp" "-1"
SET id 1
SET queryData 1
SET header true
ELIF (EQUAL label "magnets")
SET backend "bittorrent"
SET url "https://html.duckduckgo.com/html"
SET q (SIMPLIFY q)
IF (EQUAL (START_WITH "torrent ") false)
SET q (PREPEND q "torrent ")
FI
URL_ADD_QUERY url "q" (URL_ENCODE q)
URL_ADD_QUERY url "kl" "us-en"
URL_ADD_QUERY url "kp" "-1"
SET id 1
SET queryData 2
SET header true
FI
ELIF (EQUAL method "related")
AND (EQUAL label "tracks")
IF (START_WITH q "magnet:?")
SET type "torrent"
FI
SET index (INDEX_OF q '#')
SET url (MID q 0 index)
SET id 1
FI
EXTRACT_TRACK: |
SET data (READ data "ascii")
SET data (TORRENT_LIST_AFTER data "info")
SET name (TORRENT_STRING_AFTER data "name")
SET items (TORRENT_ITEMS data)
IF (EQUAL items 0)
SET string (LATIN_TO_UTF8 name)
IF (EQUAL (EXTENSION_IS_MEDIA (URL_EXTENSION string)) false)
RETURN
FI
SET author string
ELSE
SET index (SUB queryData 1)
IF (GREATER index 0)
SET count (SUB (COUNT items) 1)
IF (GREATER index count)
SET index count
FI
ELSE
SET index 0
FI
SET item (LIST_GET items index)
SET string (LATIN_TO_UTF8 (HASH_GET item "name"))
IF (EQUAL (EXTENSION_IS_MEDIA (URL_EXTENSION string)) false)
RETURN
FI
SET author (LATIN_TO_UTF8 name)
FI
SET state "cover"
SET title string
SET feed url
EXTRACT_PLAYLIST: |
#IF (EQUAL id 2) # Search urls
# SET data (READ data "utf-8")
# SET source (SLICE_IN data "initialize('" "'")
# HASH_SET next "backend" "bittorrent"
# HASH_SET next "url" (APPEND "https://duckduckgo.com" source)
# HASH_SET next "id" 3
# HASH_SET next "queryData" queryData
IF (EQUAL id 3) # Extract DuckDuckGo
# NOTE: Skipping advertisement results.
SET index (INDEX_OF data "class=\"result results_links results_links_deep web-result")
SET list (SLICES data "class=\"result__a\"" "</a>" index)
FOREACH list source
SET source (HTML_ATTRIBUTE source "href")
# NOTE: We might get corrupted URL(s) if the 'User-Agent' is invalid.
IF (CONTAIN source "?uddg=")
SET source (URL_DECODE (SLICE_IN source "?uddg=" "&"))
FI
IF (EQUAL source "")
OR (LIST_CONTAIN urls source)
CONTINUE
FI
LIST_APPEND urls source
END
HASH_SET next "backend" "bittorrent"
HASH_SET next "url" "https://snowfl.com"
HASH_SET next "id" 4
HASH_SET next "queryData" (LIST queryData urls)
HASH_SET next "skipError" true
ELIF (EQUAL id 4) # Extract script
SET index (INDEX_OF data "src=\"b.min")
SET source (SLICE_IN data '"' '"' index)
HASH_SET next "backend" "bittorrent"
HASH_SET next "url" (APPEND "https://snowfl.com/" source)
HASH_SET next "id" 5
HASH_SET next "queryData" queryData
HASH_SET next "skipError" true
ELIF (EQUAL id 5) # Parse script
SET index (INDEX_OF data "]}};var")
SET url (APPEND "https://snowfl.com/" (SLICE_IN data '"' '"' index) '/')
HASH_SET next "backend" "bittorrent"
SET query (LIST_TAKE_AT queryData 0)
SET query (SIMPLIFY (REPLACE query (REGEXP "[',.:\\-_(){}\\[\\]]") ' '))
SET query (REPLACE query 'é' 'e')
SET query (REPLACE query 'è' 'e')
# NOTE: Maybe we should generate a random string instead of 'abcdefgh'.
HASH_SET next "url" (APPEND url (URL_ENCODE query) "/abcdefgh/0/NONE/NONE/1")
HASH_SET next "id" 6
HASH_SET next "queryData" (LIST_TAKE_AT queryData 0)
HASH_SET next "skipError" true
HASH_SET next "timeout" 10000
ELIF (EQUAL id 6) # Extract Torrents
SET list (JSON_SPLIT data)
FOREACH list data
IF (CONTAIN data "\"nsfw\":true")
OR (CONTAIN data "\"type\":\"NA\"")
CONTINUE
FI
IF (LESSER (ADD (JSON_EXTRACT data "seeder") (JSON_EXTRACT data "leecher")) 4)
CONTINUE
FI
SET source (JSON_EXTRACT_UTF8 data "magnet")
IF (EQUAL source "")
CONTINUE
FI
SET index (ADD index 1)
IF (EQUAL index 10)
BREAK
FI
HASH_SET query "type" "torrent"
HASH_SET query "url" source
HASH_SET query "id" 8
HASH_SET query "timeout" 60000 # 1 minute
LIST_APPEND next query
END
FOREACH queryData source
HASH_SET queryUrl "backend" "bittorrent"
HASH_SET queryUrl "url" source
HASH_SET queryUrl "id" 7
HASH_SET queryUrl "skipError" true
HASH_SET queryUrl "timeout" 10000
LIST_APPEND next queryUrl
END
ELIF (EQUAL id 7) # Extract sources
SET data (HTML_EXTRACT data url (LIST "http" "|.torrent" "magnet:?"))
SET list (HASH_GET data "sources")
FOREACH list data
SET data (HASH_GET data "url")
IF (EQUAL (URL_EXTENSION data) "torrent")
LIST_APPEND sources data
SET index (ADD index 1)
IF (EQUAL index 5)
BREAK
FI
FI
END
IF (NOT_EQUAL index 5)
FOREACH list data
SET data (HASH_GET data "url")
IF (START_WITH data "magnet:?")
LIST_APPEND sources data
SET index (ADD index 1)
IF (EQUAL index 5)
BREAK
FI
FI
END
FI
FOREACH sources source
IF (START_WITH source "magnet:?")
HASH_SET query "type" "torrent"
HASH_SET query "timeout" 60000 # 1 minute
ELSE
HASH_SET query "type" ""
HASH_SET query "timeout" 10000
FI
HASH_SET query "url" source
HASH_SET query "id" 8
HASH_SET query "skipError" true
LIST_APPEND next query
END
ELIF (EQUAL id 8) # Extract torrent
IF (LENGTH data)
SET cache data
SET data (READ data "ascii")
SET data (TORRENT_LIST_AFTER data "info")
SET name (TORRENT_STRING_AFTER data "name")
SET items (TORRENT_ITEMS data)
IF (EQUAL (COUNT items) 0)
HASH_SET item "id" 1
HASH_SET item "name" name
HASH_SET item "index" -1
LIST_APPEND items item
FI
SET name (LATIN_TO_UTF8 name)
SET folders (TORRENT_FOLDERS items)
FOREACH folders data
FOREACH (HASH_GET data "items") data
SET title (LATIN_TO_UTF8 (HASH_GET data "name"))
SET extension (URL_EXTENSION title)
IF (EXTENSION_IS_MEDIA extension)
SET source (APPEND url '#' (HASH_GET data "id") '.' extension)
HASH_SET track "source" source
HASH_SET track "state" "cover"
HASH_SET track "title" title
HASH_SET track "author" name
HASH_SET track "feed" url
LIST_APPEND tracks track
FI
END
END
SET clearDuplicate true
FI
ELSE
SET cache data
SET data (READ data "ascii")
SET data (TORRENT_LIST_AFTER data "info")
SET name (TORRENT_STRING_AFTER data "name")
SET items (TORRENT_ITEMS data)
IF (EQUAL (COUNT items) 0)
HASH_SET item "id" 1
HASH_SET item "name" name
HASH_SET item "index" -1
LIST_APPEND items item
FI
SET name (LATIN_TO_UTF8 name)
SET folders (TORRENT_FOLDERS items)
FOREACH folders data
FOREACH (HASH_GET data "items") data
SET title (LATIN_TO_UTF8 (HASH_GET data "name"))
SET extension (URL_EXTENSION title)
IF (EXTENSION_IS_MEDIA extension)
SET itemId (HASH_GET data "id")
SET source (APPEND url '#' itemId '.' extension)
HASH_SET track "source" source
HASH_SET track "state" "cover"
HASH_SET track "title" title
HASH_SET track "author" name
HASH_SET track "feed" url
LIST_APPEND tracks track
LIST_APPEND ids itemId
FI
END
END
SET title name
IF (EQUAL id 0)
IF (EQUAL queryData -1)
RETURN
FI
FOREACH ids id
IF (EQUAL id queryData)
SET currentIndex i
BREAK
FI
SET i (ADD i 1)
END
ELSE
SET clearDuplicate true
FI
FI
EXTRACT_FOLDER: |
#IF (EQUAL id 0) # Search urls
# SET data (READ data "utf-8")
# SET source (SLICE_IN data "initialize('" "'")
# HASH_SET next "backend" "bittorrent"
# HASH_SET next "url" (APPEND "https://duckduckgo.com" source)
# HASH_SET next "id" 1
# HASH_SET next "queryData" queryData
IF (EQUAL id 1) # Extract DuckDuckGo
SET id (ADD queryData 2)
# NOTE: Skipping advertisement results.
SET index (INDEX_OF data "class=\"result results_links results_links_deep web-result")
SET list (SLICES data "class=\"result__a\"" "</a>" index)
FOREACH list source
SET source (HTML_ATTRIBUTE source "href")
# NOTE: We might get corrupted URL(s) if the 'User-Agent' is invalid.
IF (CONTAIN source "?uddg=")
SET source (URL_DECODE (SLICE_IN source "?uddg=" "&"))
FI
IF (EQUAL source "")
OR (LIST_CONTAIN urls source)
CONTINUE
FI
HASH_SET query "backend" "bittorrent"
HASH_SET query "url" source
HASH_SET query "id" id
HASH_SET query "skipError" true
HASH_SET query "timeout" 10000
LIST_APPEND next query
END
ELSE # Extract sources
SET data (HTML_EXTRACT data url (LIST "http" "|.torrent" "magnet:?"))
IF (EQUAL id 2)
FOREACH (HASH_GET data "sources") data
SET url (HASH_GET data "url")
SET match false
IF (EQUAL (URL_EXTENSION url) "torrent")
HASH_SET item "type" "playlist"
HASH_SET item "state" "default"
HASH_SET item "source" url
HASH_SET item "title" (APPEND "Torrent" " - " (SIMPLIFY url))
LIST_APPEND items item
SET match true
FI
IF (EQUAL match false)
AND (START_WITH url "magnet:?")
HASH_SET item "type" "playlist"
HASH_SET item "state" "default"
HASH_SET item "source" url
HASH_SET item "title" (APPEND "Magnet" " - " (SIMPLIFY url))
LIST_APPEND items item
FI
IF (match)
SET index (ADD index 1)
IF (EQUAL index 5)
BREAK
FI
FI
END
ELIF (EQUAL id 3)
FOREACH (HASH_GET data "sources") data
SET url (HASH_GET data "url")
IF (EQUAL (URL_EXTENSION url) "torrent")
HASH_SET item "type" "playlist"
HASH_SET item "state" "default"
HASH_SET item "source" url
HASH_SET item "title" (APPEND "Torrent" " - " (SIMPLIFY url))
LIST_APPEND items item
SET index (ADD index 1)
IF (EQUAL index 5)
BREAK
FI
FI
END
ELSE # (EQUAL id 4)
FOREACH (HASH_GET data "sources") data
SET url (HASH_GET data "url")
IF (START_WITH url "magnet:?")
HASH_SET item "type" "playlist"
HASH_SET item "state" "default"
HASH_SET item "source" url
HASH_SET item "title" (APPEND "Magnet" " - " (SIMPLIFY url))
LIST_APPEND items item
SET index (ADD index 1)
IF (EQUAL index 5)
BREAK
FI
FI
END
FI
SET clearDuplicate true
FI