Skip to content

Instantly share code, notes, and snippets.

@wolph
Created February 25, 2020 19:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wolph/6dc1489723f1e9d828594bb9d5542519 to your computer and use it in GitHub Desktop.
Save wolph/6dc1489723f1e9d828594bb9d5542519 to your computer and use it in GitHub Desktop.
Add nzbindex results to nzbget server
// ==UserScript==
// @name add-to-nzbget
// @namespace http://wol.ph
// @version 0.1
// @description Add nzbs to nzbget
// @author You
// @match https://www.nzbindex.com/*
// @require https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js
// @grant GM_addStyle
// @grant GM_unsafeWindow
// @grant GM_getValue
// @grant GM_setValue
// @grant GM_registerMenuCommand
// @grant GM_unregisterMenuCommand
// @grant GM_xmlhttpRequest
// ==/UserScript==
/* globals $, jQuery */
function getUrl(){
return GM_getValue('url', 'http://localhost:6789').replace(/\/$/, '');
}
GM_registerMenuCommand('Set NZB host', () => {
const url = prompt('Set the nzbget url', getUrl());
if(url !== null){
GM_setValue('url', url);
}
});
const download_all = $('<div class="pull-left"><button class="btn btn-primary" type="button">NZBGet</button></div>');
$('#actions').parent().append(download_all);
download_all.click(() => {
jQuery('#results-table .result-checkbox:checked').parents('tr').find('span.nzbget>a').click();
});
function send_to_nzbget(elem){
const nzb = elem[0].href;
const title = $(elem).parents('td').find('label.name').text();
const url = getUrl() + '/jsonrpc';
const data = {
'jsonrpc': '2.0',
'id':0,
'method': 'append',
'params': [
'', // NZBFilename (string) - name of nzb-file (with extension). This parameter can be an empty string if parameter Content contains an URL; in that case the file name is read from http headers. If NZBFilename is provided it must have correct extension (usually “.nzb”) according to file content. Files without “.nzb”-extension are not added to queue directly; all files however are sent to scan-scripts.
nzb, // Content (string) - content of nzb-file encoded with Base64 or URL to fetch nzb-file from.
'', // Category (string) - category for nzb-file. Can be empty string.
0, // Priority (int) - priority for nzb-file. 0 for “normal priority”, positive values for high priority and negative values for low priority. Downloads with priorities equal to or greater than 900 are downloaded and post-processed even if the program is in paused state (force mode). Default priorities are: -100 (very low), -50 (low), 0 (normal), 50 (high), 100 (very high), 900 (force).
false, // AddToTop (bool) - “True” if the file should be added to the top of the download queue or “False” if to the end.
false, // AddPaused (bool) - “True” if the file should be added in paused state.
'', // DupeKey (string) - duplicate key for nzb-file. See RSS.
0, // DupeScore (int) - duplicate score for nzb-file. See RSS.
'SCORE', // DupeMode (string) - duplicate mode for nzb-file. See RSS.
[ // PPParameters (array) - v16.0 post-processing parameters. The array consists of structures with following fields:
// Name (string) - name of post-processing parameter.
// Value (string) - value of post-processing parameter.
{'*unpack:':'yes'},
// {'*Unpack:Password:':file['password']}
]
]
}
GM_xmlhttpRequest({
method: 'POST',
url: url,
data: JSON.stringify(data),
headers: {
'Content-Type': 'application/json',
},
});
}
unsafeWindow.addEventListener('load', () => {
$('span.download', unsafeWindow.body).each((i, span) => {
const $span = $('<span class="nzbget"><a>NZBGet</a> - </span>');
span.parentNode.insertBefore($span[0], span)
$span.attr('title', 'Send to NZBGet');
const $a = $span.find('a');
$a.attr('href', $('a', span)[0].href);
$a.click(function(event){
event.preventDefault();
this.style.color = '#aaa';
send_to_nzbget($(this));
return false;
});
});
}, false);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment