-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathant-to-radarr.js
667 lines (614 loc) · 29 KB
/
ant-to-radarr.js
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
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
// ==UserScript==
// @name ANT To Radarr Mod
// @version 1.0.0
// @author Audionut - Original PTP Mod by Prism16 - Main Script by DirtyCajunRice / CatSpinner
// @namespace https://github.com/Audionut/add-trackers
// @description A Mod Of PTP to Radarr
// @homepage https://passthepopcorn.me/forums.php?action=viewthread&threadid=35294
// @icon data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAADAAAAAwCAMAAABg3Am1AAACTFBMVEUAAAD//////////////vu1t7j/zFCGiYz////+/v4xNjs7QEUpLjP////7+/smKzBHS09VWV1obG/////////////Z2tv/////////////////////yUdQVFg/Q0imqKp2enz19va2t7n///+XmZyTlZj/4JOOkJOEh4n/8tTY2trV1tf/9+L////r7Oz///////84PEEuMjdLT1RCRkv/zlmMj5FaXWGVl5plaGzq6+yYmpx0d3rU1dZ8f4L8/f3v7/C+wMG6u72bnaD/5qmgo6WsrrD/67mxs7XOz9H//PT///////////////////////////////////////////////82Oj//xDX/xj3/zE2JjI9SVlr/0mVdYWV4e3//1nLn5+jg4eKGiYttcHSAg4b/2XzMzc+wsrTGx8ijpqj/5KCdn6H/7cC9vsC6vL2+wMH////Q0dL/8c3k5eX/+evp6en19fXy8vL9/f3////l5ubz8/T///////////////////////////////////////////////////9YXGD/z1r/13b////c3d7HyMmqrK7s7O2Ii43/24X4+Pjy8/Opq63/7sT4+PjExcf9/f3R0tP/89bf4OHl5ubl5ebk5ebj4+Tt7u7/////////////////////////////////////////////////////wjAkKS4XHCEaHyT/wCkiJywYHiMfJSobICYhJiv/vyQeIygcIicVGh//wSz/vyctMTYSGB0KDxUSFx1vUO58AAAAsHRSTlMA5eTH5u77+uPx/fz+8uX++/r31Xkg9drSOhIJ/Pv79vb19fPz8/Pz8+vq6uno57yj/f38+/r5+fj49/f39vb19fT09PDw7+7u6+bOybimlHFgWCkeGAb+/v38+vn4+Pf39vb29vX19PTz8/Hw7e3t7Ovr6+jn5+bm5d3Y18G0sZuPi4J9ZF5EDwz5+fb19fX19PT08/Pv7ezs6+vq6ejo6Ojn3suvl5GHbFRQSjECARZmqHoAAAO5SURBVEjHjZXle9NQFMbblEFSN9Yic0UmbGMbc2FjbsBwd3d3d3d3t+ZG2yTrgH+MJPfmCQ8k3c6Hfjq/5n3Pvee9Fq0uDZw8Fg509XwabxlVDdhcqzObq2/W1h8OThy5/WKxq7HCSQHAMt7mjM7+wRH6J3Y3+HkqSsrF8KBso6voQsL+H8UZKRJDaiVSFbW7ihNZ6XfVSXJjlKV4llO+Qnlurwr1TTQVFM5kGfmPneltO/IcIKqwoKT6bvj8d2PgK+Gj5H7HbhzD8MJ8j0KTHChtdJ2YYAicTiYZMuqcilnlwrBpyzlescILa5OtH42snEgDJMnW4HI7RB6lANUK66lreBOc9B9gW6IArZjarCLurXZkxbGZsH35DxgnA1SS0jtlukpY8Zfp0IoALm8giueaAWMWR3I7cGTFz4uKFYqblYy9H28CjI3FFs/BkPskB7LizM4I9A8aA3SEpldOQcjBPDuAIy7bSHRfMAEikVhk/T70kf01UQreFt8GImgGRIZii7aMQUh7BRDU2xLNyzptDEBk5h6k61CLg+XUEWdnnTMCUMWHlk3B4UEeaHYqVhiQdnieKaBaye1AyFS/IH9EsFedMQOQrsmzNStJw/KhSJWdZgAqOnblAbSCt5dwJJ8SMAc0K/TK6ZBopUhuxlFzQLeycDaU5eOjw0dGAcTjufATbdRoAFo5EDQqUliQUJI+JwjsLWFLzU0j+bkdaKwKMPyzPJwIiNNXpyM1r/OeyZI4z+pec4Cmx2qL4U5y/NqMYfd/VeJzjQAkfo52yNtLeQHk425H+rWg2eWLRe7sQ2qep4s8Q0rZeM6s+p5BLTUkHVDFL3uKLsTBHHXnGOHJi0yiVwscWyarA8oqbEPira2pcKt/risgwuf1FX3oBRoQ/2vZdvsoUV02cQ1RcGa+RQcet8+QfrcpwOSh9dooX+V7KEZZZzGlseAdClkEbMIK81O3K43btMA4kDMMs09KbXIdg+06UD4Nxw65oQ74u8OrRdKahlDfv+l6vNKPWWGh0FvL81roWXvnWf6tD7UgG9f7C1eQMFbZpZuInm8Gcf+Z8EpbMQymt7tlBgpue0t914DFqOaH0iRq+c5Ct9W9f6ePFaD4ulWhs2avXF+WH/CC3bvUaxfg48P7kwtOQfFGNam7ygEYTuRFDr4JZU2uIjhKkxpvu+5jRfhSc2BBzr235/RRGtsoykpLFQBgAWVfdws/e9EyUl0KhjJuVK+oKW+q2nVSf6ESygoe7woEOotOTUjc9weXiUPgDnteIQAAAABJRU5ErkJggg==
// @match https://anthelion.me/upcoming.php*
// @require https://cdn.jsdelivr.net/gh/sizzlemctwizzle/GM_config@43fd0fe4de1166f343883511e53546e87840aeaf/gm_config.js
// @require https://code.jquery.com/jquery-3.5.1.min.js
// @license MIT
// @grant GM.xmlHttpRequest
// @grant GM.getValue
// @grant GM.setValue
// @grant GM.openInTab
// @grant GM.notification
// @grant GM.registerMenuCommand
// ==/UserScript==
/*========================= Old Version History ==================================
Changelog 1.5 - Added support for https://passthepopcorn.me/forums.php?action=viewthread&threadid=44415
Changelog 1.4 - Aid added to this forum thread menu to help pulling profile id's for new installs / setups.
Changelog 1.3 - Visual Mod Created By Prism16 Based on v1.2 by CatSpinner with minor function changes and tweaks.
*/
document.addEventListener('UpcomingReleasesDisplayChanged', () => {
//console.log("Custom event 'UpcomingReleasesDisplayChanged' captured, re-running set_html with delay.");
setTimeout(() => {
set_html(true);
}, 100); // Adjust the delay as necessary
});
var style = document.createElement('style');
if (window.location.href.includes('user.php?action=edit')) {
window.addEventListener('DOMContentLoaded', (event) => {
const userForm = document.querySelector('#userform');
const newDiv = document.createElement('div');
newDiv.textContent = 'Settings Menu';
userForm.appendChild(newDiv);
});
}
style.innerHTML = `
button, input[type="button"]:hover, input[type="reset"]:hover, input[type="submit"]:hover, button:focus, input[type="button"]:focus, input[type="reset"]:focus, input[type="submit"]:focus {
background: #4281da;
box-shadow: none;
outline: 0;
}
`;
document.head.appendChild(style);
GM_config.init({
"id": "PTPToRadarr",
"title": "PTP To Radarr Settings",
"css": `#PTPToRadarr {background: #333333;}
#PTPToRadarr .field_label {color: #fff;}
#PTPToRadarr .config_header {color: #fff; padding-bottom: 10px;}
#PTPToRadarr .reset {color: #f00; text-align: center;}
#PTPToRadarr .config_var {text-align: center;}
#PTPToRadarr_radarr_syncbutton_var {float: left;}
#PTPToRadarr .reset_holder {text-align: center;}
#PTPToRadarr_radarr_minimumavailability_var {padding-right: 95;}
#PTPToRadarr_radarr_apikey_var {padding-left: 49;}
#PTPToRadarr_radarr_url_var {padding-left: 69;}
#PTPToRadarr .saveclose_buttons {margin: 16px 10px 10px; padding: 2px 12px; background-color: #e7e7e7; color: black; text-decoration: none; border: none; border-radius: 6px;}
#PTPToRadarr_field_radarr_syncbutton {background-color: #e7e7e7; color: black; text-decoration: none; border: none; border-radius: 6px; margin-left: 10px; margin-top: 16px; height: 20px;}`,
"events": {
"open": function(doc) {
let style = this.frame.style;
style.width = "400px";
style.height = "295px";
style.inset = "";
style.top = "6%";
style.right = "6%";
style.borderRadius = "25px";
doc.getElementById("PTPToRadarr_buttons_holder").prepend(doc.getElementById("PTPToRadarr_radarr_syncbutton_var"));
}
},
"fields": {
"radarr_url": {
"label": "Radarr URL",
"type": "text",
"default": "https://domain.tld/radarr"
},
"radarr_apikey": {
"label": "Radarr API Key",
"type": "text",
"default": ""
},
"radarr_profileid": {
"label": "Radarr Quality Profile ID",
"type": "text",
"default": "1"
},
"radarr_rootfolderpath": {
"label": "Radarr Root Folder Path",
"type": "text",
"default": "/mnt/movies"
},
"radarr_minimumavailability":
{
"label": "Minimum Availability",
"type": "select",
"options": ["announced", "inCinemas", "released"],
"default": "released"
},
"radarr_searchformovie": {
"label": "Search for movie on request",
"type": "checkbox",
"default": false
},
"radarr_sync_interval":
{
"label": "AutoSync Interval (Minutes)",
"type": "select",
"options": ["15", "30", "60", "120", "360", "1440", "Never"],
"default": "Never"
},
"radarr_syncbutton": {
"label": "Sync Radarr Movies",
"type": "button",
"click": get_radarr_movies
}
}
});
GM.registerMenuCommand("PTP To Radarr Settings",() => GM_config.open());
let url = window.location.href;
let radarr_url = GM_config.get("radarr_url").replace(/\/$/, "");
var current_page_type = "";
if (document.getElementById("torrent-table")) {
current_page_type = "singletorrent";
}
else {
current_page_type = "multi";
}
if (current_page_type) {
set_html(false);
}
let interval = GM_config.get("radarr_sync_interval");
if (interval != "Never") {
let millisecondInterval = Number(interval) * 60000;
window.setTimeout(() => autoSync(millisecondInterval));
window.setInterval(() => autoSync(millisecondInterval), millisecondInterval);
}
function themeChecker () {
let typeAThemes = ["marcel.css", "ptp-raise"];
typeAThemes.forEach((theme) => {
if (document.head.querySelector("[href*=\"" + theme + "\"]")) {
return true;
}
});
return false;
}
function clickswap (id, titleSlug) {
let radarr_url = GM_config.get("radarr_url").replace(/\/$/, "");
let button = document.getElementById("ptptoradarr-" + id)
button.firstChild.src = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAADAAAAAwCAMAAABg3Am1AAACTFBMVEUAAAD//////////////vu1t7j/zFCGiYz////+/v4xNjs7QEUpLjP////7+/smKzBHS09VWV1obG/////////////Z2tv/////////////////////yUdQVFg/Q0imqKp2enz19va2t7n///+XmZyTlZj/4JOOkJOEh4n/8tTY2trV1tf/9+L////r7Oz///////84PEEuMjdLT1RCRkv/zlmMj5FaXWGVl5plaGzq6+yYmpx0d3rU1dZ8f4L8/f3v7/C+wMG6u72bnaD/5qmgo6WsrrD/67mxs7XOz9H//PT///////////////////////////////////////////////82Oj//xDX/xj3/zE2JjI9SVlr/0mVdYWV4e3//1nLn5+jg4eKGiYttcHSAg4b/2XzMzc+wsrTGx8ijpqj/5KCdn6H/7cC9vsC6vL2+wMH////Q0dL/8c3k5eX/+evp6en19fXy8vL9/f3////l5ubz8/T///////////////////////////////////////////////////9YXGD/z1r/13b////c3d7HyMmqrK7s7O2Ii43/24X4+Pjy8/Opq63/7sT4+PjExcf9/f3R0tP/89bf4OHl5ubl5ebk5ebj4+Tt7u7/////////////////////////////////////////////////////wjAkKS4XHCEaHyT/wCkiJywYHiMfJSobICYhJiv/vyQeIygcIicVGh//wSz/vyctMTYSGB0KDxUSFx1vUO58AAAAsHRSTlMA5eTH5u77+uPx/fz+8uX++/r31Xkg9drSOhIJ/Pv79vb19fPz8/Pz8+vq6uno57yj/f38+/r5+fj49/f39vb19fT09PDw7+7u6+bOybimlHFgWCkeGAb+/v38+vn4+Pf39vb29vX19PTz8/Hw7e3t7Ovr6+jn5+bm5d3Y18G0sZuPi4J9ZF5EDwz5+fb19fX19PT08/Pv7ezs6+vq6ejo6Ojn3suvl5GHbFRQSjECARZmqHoAAAO5SURBVEjHjZXle9NQFMbblEFSN9Yic0UmbGMbc2FjbsBwd3d3d3d3t+ZG2yTrgH+MJPfmCQ8k3c6Hfjq/5n3Pvee9Fq0uDZw8Fg509XwabxlVDdhcqzObq2/W1h8OThy5/WKxq7HCSQHAMt7mjM7+wRH6J3Y3+HkqSsrF8KBso6voQsL+H8UZKRJDaiVSFbW7ihNZ6XfVSXJjlKV4llO+Qnlurwr1TTQVFM5kGfmPneltO/IcIKqwoKT6bvj8d2PgK+Gj5H7HbhzD8MJ8j0KTHChtdJ2YYAicTiYZMuqcilnlwrBpyzlescILa5OtH42snEgDJMnW4HI7RB6lANUK66lreBOc9B9gW6IArZjarCLurXZkxbGZsH35DxgnA1SS0jtlukpY8Zfp0IoALm8giueaAWMWR3I7cGTFz4uKFYqblYy9H28CjI3FFs/BkPskB7LizM4I9A8aA3SEpldOQcjBPDuAIy7bSHRfMAEikVhk/T70kf01UQreFt8GImgGRIZii7aMQUh7BRDU2xLNyzptDEBk5h6k61CLg+XUEWdnnTMCUMWHlk3B4UEeaHYqVhiQdnieKaBaye1AyFS/IH9EsFedMQOQrsmzNStJw/KhSJWdZgAqOnblAbSCt5dwJJ8SMAc0K/TK6ZBopUhuxlFzQLeycDaU5eOjw0dGAcTjufATbdRoAFo5EDQqUliQUJI+JwjsLWFLzU0j+bkdaKwKMPyzPJwIiNNXpyM1r/OeyZI4z+pec4Cmx2qL4U5y/NqMYfd/VeJzjQAkfo52yNtLeQHk425H+rWg2eWLRe7sQ2qep4s8Q0rZeM6s+p5BLTUkHVDFL3uKLsTBHHXnGOHJi0yiVwscWyarA8oqbEPira2pcKt/risgwuf1FX3oBRoQ/2vZdvsoUV02cQ1RcGa+RQcet8+QfrcpwOSh9dooX+V7KEZZZzGlseAdClkEbMIK81O3K43btMA4kDMMs09KbXIdg+06UD4Nxw65oQ74u8OrRdKahlDfv+l6vNKPWWGh0FvL81roWXvnWf6tD7UgG9f7C1eQMFbZpZuInm8Gcf+Z8EpbMQymt7tlBgpue0t914DFqOaH0iRq+c5Ct9W9f6ePFaD4ulWhs2avXF+WH/CC3bvUaxfg48P7kwtOQfFGNam7ygEYTuRFDr4JZU2uIjhKkxpvu+5jRfhSc2BBzr235/RRGtsoykpLFQBgAWVfdws/e9EyUl0KhjJuVK+oKW+q2nVSf6ESygoe7woEOotOTUjc9weXiUPgDnteIQAAAABJRU5ErkJggg==";
button.removeEventListener("click", new_movie_lookup, false);
button.addEventListener("click", function () {
GM.openInTab(radarr_url.concat("/movie/", titleSlug), "active");
}, false);
}
function set_html(update) {
let theme = themeChecker();
let radarr_url = GM_config.get("radarr_url").replace(/\/$/, "");
// Clear any existing elements added by the script to avoid duplication
let existingButtons = document.querySelectorAll("[id^='ptptoradarr-']");
if (update && existingButtons.length > 0) {
existingButtons.forEach(el => {
el.remove();
});
}
let coverView = document.querySelector(".cover-movie-list__container:not(.hidden)");
let coverViewMovies = Array.from(document.getElementsByClassName("cover-movie-list__movie__rating-and-tags"));
let listView = document.querySelector(".basic-movie-list");
let listViewMovies = Array.from(document.getElementsByClassName("basic-movie-list__movie__ratings-and-tags")) || Array.from(document.getElementsByClassName("cast-list"));
let listViewUpcoming = Array.from(document.querySelectorAll(".site-link"));
let hugeView = document.querySelector(".huge-movie-list__movie");
let hugeViewMovies = Array.from(document.getElementsByClassName("huge-movie-list__movie__ratings")) || Array.from(document.getElementsByClassName("title-link"));
let hugeViewUpcoming = Array.from(document.querySelectorAll(".site-link"));
// Define the processMovie function within set_html
function processMovie(movie, linkSelector, size) {
window.setTimeout(() => {
let a = movie.querySelector(linkSelector);
if (a) {
buttonBuilder(movie, a.href, size, theme);
} else {
console.log("No link found in:", movie);
}
});
}
if (current_page_type == "singletorrent") {
let a = document.querySelector("[href*=\"://www.imdb.com/title/tt\"]") || document.querySelector("[href*=\"://www.themoviedb.org/movie/\"]");
let movie = document.querySelector(".panel__body");
if (a) {
buttonBuilder(movie, a.href, "single", theme);
} else {
console.log("No movie link found.");
}
} else if (current_page_type == "multi") {
if (coverView && !coverView.classList.contains("hidden")) {
coverViewMovies.forEach((movie) => {
processMovie(movie, "[href*=\"://www.imdb.com/title/tt\"], [href*=\"://www.themoviedb.org/movie/\"]", "medium");
});
} else if (listView && !listView.classList.contains("hidden")) {
listViewMovies.forEach((movie) => {
processMovie(movie, "[href*=\"://www.imdb.com/title/tt\"], [href*=\"://www.themoviedb.org/movie/\"]", "small");
});
listViewUpcoming.forEach((upcomingMovie) => {
processMovie(upcomingMovie, "[href*=\"://www.imdb.com/title/tt\"], [href*=\"://www.themoviedb.org/movie/\"]", "small");
});
} else if (hugeView) {
hugeViewMovies.forEach((movie) => {
processMovie(movie, "[href*=\"://www.imdb.com/title/tt\"], [href*=\"://www.themoviedb.org/movie/\"]", "large");
});
hugeViewUpcoming.forEach((upcomingMovie) => {
processMovie(upcomingMovie, "[href*=\"://www.imdb.com/title/tt\"], [href*=\"://www.themoviedb.org/movie/\"]", "special");
});
}
} else {
console.log("No page type detected.");
}
}
function new_movie_lookup(id) {
return new Promise((resolve, reject) => {
let radarr_url = GM_config.get("radarr_url").replace(/\/$/, "");
let radarr_apikey = GM_config.get("radarr_apikey");
let url = "";
// Determine if the ID is IMDb or TMDb and set the URL accordingly
if (id.startsWith("tt")) {
url = radarr_url.concat("/api/v3/movie/lookup/imdb?imdbId=", id);
} else {
url = radarr_url.concat("/api/v3/movie/lookup/tmdb?tmdbId=", id);
}
GM.xmlHttpRequest({
method: "GET",
url: url,
headers: {
"X-Api-Key": radarr_apikey,
"Accept": "application/json"
},
onload: function(response) {
if (response.status === 200) {
let responseJSON = JSON.parse(response.responseText);
add_movie(responseJSON, id);
resolve(responseJSON);
} else if (response.status == 401) {
console.error("Error: Invalid Radarr API Key.");
GM.notification("Error: Invalid Radarr API Key.", "PTP To Radarr");
reject("Invalid API Key");
} else if (!response.responseText) {
console.error("No results found in Radarr for ID:", id);
GM.notification("No results found.", "PTP To Radarr");
reject("No results found");
} else {
console.error("Unexpected Radarr API response:", response);
reject("Unexpected API Response");
}
},
onerror: function() {
console.error("Request Error. Check Radarr URL.");
GM.notification("Request Error.\nCheck Radarr URL!", "PTP To Radarr");
reject("Request Error");
},
onabort: function() {
console.error("Request aborted.");
GM.notification("Request is aborted.", "PTP To Radarr");
reject("Request Aborted");
}
});
});
}
async function buttonBuilder(movie, href, type, theme) {
let radarr_url = GM_config.get("radarr_url").replace(/\/$/, "");
let id = href.match(/tt\d+/) ? href.match(/tt\d+/)[0] : href.match(/\d+/)[0];
let exists = await check_exists(id);
let button = document.createElement("button");
button.id = "ptptoradarr-" + id;
button.textContent = "Add To Radarr";
Object.assign(button.style, {border: "none", backgroundColor: "transparent"});
// Positioning logic based on type
if (type == "single") {
Object.assign(button.style, {
position: "absolute",
top: "-30px",
right: "0",
transform: "translateX(0)",
zIndex: 10,
});
button.style.animation = "none";
movie.style.position = "relative";
movie.prepend(button);
}
else if (type == "small") {
Object.assign(button.style, {
position: "absolute",
bottom: "-5px",
right: "-10px",
fontSize: "10px",
fontWeight: "bold",
});
movie.style.position = "relative";
movie.appendChild(button);
}
else if (type == "medium") {
Object.assign(button.style, {
position: "absolute",
top: "0",
left: "50%",
transform: "translate(-50%, -100%)",
fontSize: "10px",
fontWeight: "bold",
animation: "none",
});
let posterContainer = movie.closest(".cover-movie-list__movie");
if (posterContainer) {
posterContainer.style.position = "relative";
posterContainer.prepend(button);
}
}
else if (type == "large") {
Object.assign(button.style, {
position: "absolute",
top: "55px",
right: "-98px",
fontSize: "10px",
fontWeight: "bold",
zIndex: "111",
});
let posterContainer = movie.closest(".huge-movie-list__movie")?.firstChild;
if (posterContainer) {
posterContainer.style.position = "relative";
posterContainer.prepend(button);
}
}
else if (type == "special") {
Object.assign(button.style, {
fontSize: "12px",
fontWeight: "bold",
marginLeft: "10px" // Add some margin to separate it from the existing content
});
// Find the title-link element to append the button at the end
let titleLinkElement = movie.querySelector(".title-link");
if (titleLinkElement) {
titleLinkElement.appendChild(button);
} else {
console.error("Title link not found, cannot append button.");
}
}
// Check if the movie already exists in Radarr
if (exists) {
button.textContent = "View In Radarr";
button.style.color = "#99EDC3";
button.addEventListener("click", function () {
GM.openInTab(radarr_url.concat("/movie/", exists[0].titleSlug), "active");
}, false);
}
else {
button.textContent = "Add To Radarr";
button.style.color = "#FFE36E";
$(button).click(async function() {
$(button).animate({opacity: 0}, 500, function() {
button.textContent = "...";
$(button).animate({opacity: 1}, 1000);
});
try {
await new_movie_lookup(id);
button.textContent = "Added !!!";
} catch (error) {
button.textContent = "Failed to Add";
console.error("Failed to add movie:", error);
}
});
}
}
let radarr_apikey = GM_config.get("radarr_apikey");
const baseUrl = 'https://passthepopcorn.me/forums.php?action=viewthread&threadid=43569';
if (window.location.href.startsWith(baseUrl)) {
const link = document.createElement('a');
link.textContent = ' [Fetch Quality Profiles] ';
link.href = '#';
link.className = 'linkbox_link';
link.onclick = function(event) {
event.preventDefault();
fetchQualityProfiles().then(output => {
let modal = createModal(output);
document.body.appendChild(modal);
});
};
const linkbox = document.querySelector('div.linkbox');
if (linkbox) {
linkbox.appendChild(link);
} else {
console.log("Error: Could not find the element with class name 'linkbox'.");
}
}
function fetchQualityProfiles() {
if (!radarr_url || !radarr_apikey) {
GM.notification({
title: 'PTP to Radarr Mod',
text: 'Please Check API Key & URL In Settings.',
timeout: 4000
});
return;
}
return new Promise((resolve, reject) => {
let xhr = new XMLHttpRequest();
xhr.open("GET", `${radarr_url}/api/v3/qualityprofile?apikey=${radarr_apikey}`, true);
xhr.onreadystatechange = function () {
if (xhr.readyState == 4 && xhr.status == 200) {
let data = JSON.parse(xhr.responseText);
let names = filterByName(data);
let ids = filterById(data);
let output = {};
for (let i = 0; i < names.length; i++) {
let name = names[i];
let id = ids[i];
output[name.name] = id.id;
}
resolve(output);
}
}
xhr.send();
});
}
function filterByName(data) {
let filtered = [];
for (let i = 0; i < data.length; i++) {
let element = data[i];
if (element.hasOwnProperty("name")) {
filtered.push(element);
}
}
return filtered;
}
function filterById(data) {
let filtered = [];
for (let i = 0; i < data.length; i++) {
let element = data[i];
if (element.hasOwnProperty("id")) {
filtered.push(element);
}
}
return filtered;
}
function createModal(obj) {
let modal = document.createElement("div");
modal.style.position = "fixed";
modal.style.zIndex = "1";
modal.style.left = "0";
modal.style.top = "0";
modal.style.width = "100%";
modal.style.height = "100%";
modal.style.overflow = "auto";
modal.style.backgroundColor = "rgba(0,0,0,0.4)";
let modalContent = document.createElement("div");
modalContent.style.backgroundColor = "#000";
modalContent.style.color = "#fff";
modalContent.style.margin = "15% auto";
modalContent.style.padding = "0px";
modalContent.style.border = "1px solid #888";
modalContent.style.width = "80%";
modalContent.style.maxWidth = "300px";
modalContent.style.borderRadius = "5px";
let closeButton = document.createElement("button");
closeButton.textContent = "Close";
closeButton.style.backgroundColor = "transparent";
closeButton.style.color = "white";
closeButton.style.position = "absolute";
closeButton.style.top = "0px";
closeButton.style.right = "0px";
closeButton.style.padding = "5px 10px";
closeButton.onclick = function() {
modal.style.display = "none";
};
modalContent.style.position = "relative";
modalContent.appendChild(closeButton);
let tree = createTree(obj);
tree.style.textAlign = "left";
modalContent.appendChild(tree);
modal.appendChild(modalContent);
document.body.appendChild(modal);
}
function createTree(obj) {
let ul = document.createElement("ul");
ul.style.listStyleType = "none";
for (let key in obj) {
let li = document.createElement("li");
let span = document.createElement("span");
span.textContent = key;
li.appendChild(span);
if (typeof obj[key] == "object" && obj[key] !== null) {
let child = createTree(obj[key]);
li.appendChild(child);
span.onclick = function() {
child.hidden = !child.hidden;
}
if (Array.isArray(obj)) {
span.textContent = "[" + span.textContent + "]";
} else {
span.textContent = "{" + span.textContent + "}";
}
} else {
let text = document.createTextNode(": " + obj[key]);
li.appendChild(text);
}
ul.appendChild(li);
}
return ul;
}
function get_radarr_movies() {
let radarr_url = GM_config.get("radarr_url").replace(/\/$/, "");
let radarr_apikey = GM_config.get("radarr_apikey");
GM.xmlHttpRequest({
method: "GET",
url: radarr_url.concat("/api/v3/movie"),
headers: {
"X-Api-Key": radarr_apikey,
"Accept": "application/json"
},
onload: function(response) {
if (response.status == 200) {
const responseJSON = JSON.parse(response.responseText);
GM.setValue("existing_movies", JSON.stringify(responseJSON));
let timestamp = + new Date()
GM.setValue("last_sync_timestamp", timestamp)
console.log("PTPToRadarr::Sync: Setting last sync timestamp to " + timestamp)
GM.notification("Radarr Sync Complete!", "PTP To Radarr");
set_html(true);
} else if (response.status == 401) {
GM.notification("Error: Invalid Radarr API Key.", "PTP To Radarr");
} else {
GM.notification("Error: Status " + response.status, "PTP To Radarr");
}
},
onerror: function() {
GM.notification("Request Error.\nCheck Radarr URL!", "PTP To Radarr");
},
onabort: function() {
GM.notification("Request is aborted.", "PTP To Radarr");
}
});
}
async function check_exists(id) {
let movieliststr = await GM.getValue("existing_movies", "{}");
let movie_list = JSON.parse(movieliststr);
let filter = null;
try {
if (id.startsWith("tt")) { // IMDb ID
filter = movie_list.filter(movie => movie.imdbId == id);
} else { // TMDb ID
filter = movie_list.filter(movie => movie.tmdbId == id);
}
} catch (e) {
console.error("Error during filtering:", e);
if (e instanceof TypeError) {
return false;
} else {
errorNotificationHandler(e, false);
return false;
}
}
return filter.length ? filter : false;
}
async function autoSync (interval) {
let currentTimestamp = + new Date();
let lastSyncTimestamp = await GM.getValue("last_sync_timestamp", 0);
if (currentTimestamp - lastSyncTimestamp >= interval) {
let notification = "It has been " + ((currentTimestamp - lastSyncTimestamp) / 60000).toFixed(1) +
" minutes since your last sync which exceeds your threshold of " +
(interval / 60000) + " minutes. AutoSyncing...";
console.log(notification);
GM.notification(notification);
get_radarr_movies();
}
}
function add_movie(movie, id) {
let radarr_url = GM_config.get("radarr_url").replace(/\/$/, "");
let radarr_apikey = GM_config.get("radarr_apikey");
movie.qualityProfileId = parseInt(GM_config.get("radarr_profileid"));
movie.rootFolderPath = GM_config.get("radarr_rootfolderpath");
movie.monitored = true;
movie.minimumAvailability = GM_config.get("radarr_minimumavailability");
if (GM_config.get("radarr_searchformovie")) {
movie.addOptions = { searchForMovie: true };
} else {
movie.addOptions = { searchForMovie: false };
}
GM.xmlHttpRequest({
method: "POST",
url: radarr_url.concat("/api/v3/movie"),
headers: {
"X-Api-Key": radarr_apikey,
"Accept": "application/json",
"Content-Type": "application/json"
},
data: JSON.stringify(movie),
onload: function(response) {
const responseJSON = JSON.parse(response.responseText);
let button = document.getElementById("ptptoradarr-" + id);
if (response.status == 201) {
clickswap(id, responseJSON.titleSlug);
GM.notification(responseJSON.title + " Successfully sent to Radarr", "PTP To Radarr");
button.textContent = "View In Radarr";
button.style.color = "#99EDC3";
} else {
button.textContent = "View In Radarr";
button.style.color = "#99EDC3";
}
},
onerror: function() {
GM.notification("Request Error.\nCheck Radarr URL!", "PTP To Radarr");
},
onabort: function() {
GM.notification("Request is aborted.", "PTP To Radarr");
}
});
}