Skip to content

Commit

Permalink
Upgrade to 3.0.2 (BETA)
Browse files Browse the repository at this point in the history
Please see #55, or the /change.log file for changes made.
  • Loading branch information
Ephellon committed Aug 25, 2018
1 parent 62bc193 commit 44a84c5
Show file tree
Hide file tree
Showing 29 changed files with 445 additions and 215 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,9 @@ Getting the repo ready for a pull request.

## Installing Web to Plex

- **Download the [CRX](https://github.com/Ephellon/web-to-plex/raw/master/hhkmjeeccipbolailpomhjhmccnnjhkj.crx)**
- **Download the [CRX](https://github.com/Ephellon/web-to-plex/raw/master/src.crx)**

- **Download the [ZIP](https://github.com/Ephellon/web-to-plex/raw/master/hhkmjeeccipbolailpomhjhmccnnjhkj.zip)**
- **Download the [ZIP](https://github.com/Ephellon/web-to-plex/raw/master/src.zip)**

- **Download the [SRC](https://github.com/Ephellon/web-to-plex/archive/master.zip)**

Expand Down
Binary file modified button-locations/hulu.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
27 changes: 25 additions & 2 deletions change.log
Original file line number Diff line number Diff line change
Expand Up @@ -200,10 +200,33 @@
- **Added support for Trakt's "Watch Now" links**
- see issue #25

## v3.0.1.0 / unreleased
## v3.0.1.0 / SpaceK33z@62bc193b7f24095024aeb6ec473fccfa7753e849

- **Added the download API**
- uses the download API to save files (i.e. Flenix's "Save As" option for non-Flenix domains)
- Restructured the context menu
- **Added the `sendUpdate(String type[, Object options])` method to `/utils.js`**
- Fixed Trakt's button error
- Fixed Trakt's button error

## v3.0.2.0 / unreleased

- **Added "Best guess" searching feature (context menu)**
- **Avoided bug: `/background.js` error: `changeStatus` was incorrectly implemented**
- specifically, `id.replace` was a TypeError (`Number..replace` is undefined)
- Fixed Trakt's `getTVDbID` method (was returning a URL instead of a number)
- Fixed VRV's title finding error (the site was updated)
- **Added "used managers" to the pop-up feature, i.e. if you have Watcher defined in the options, a link will show up in the pop-up**
- Added "instrusive ads" icon to the pop-up
- Fixed Amazon, again... website upgrade
- Fixed Hulu -- who got a much needed website upgrade as well
- Added *transparent* icon images
- **Fixed API lookup feature (TV Shows / TV Maze)**
- Fixed iTunes (Movies) -- who also got a website update
- Changed `/utils.js` and `/background.js` to find items more accurately
- stopped trusting the obtained years (i.e. Trakt's episode air-date shouldn't count as the series' air-date)
- enclosed the `chrome.runtime.onMessage.addListener` method in a `try / catch` for better debugging
- Removed variable ghosting
- variables, most notably `options.watcherURL` would persist after being removed
- Updated the manifest's description
- Renamed `/hhkmjeeccipbolailpomhjhmccnnjhkj.crx` to `src.crx`
- Renamed `/hhkmjeeccipbolailpomhjhmccnnjhkj.zip` to `src.zip`
Binary file renamed hhkmjeeccipbolailpomhjhmccnnjhkj.crx → src.crx
Binary file not shown.
Binary file renamed hhkmjeeccipbolailpomhjhmccnnjhkj.zip → src.zip
Binary file not shown.
145 changes: 97 additions & 48 deletions src/background.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,28 @@ let external = {},
// { error: m => m, info: m => m, log: m => m, warn: m => m } ||
console;

let date = new Date(),
YEAR = date.getFullYear(),
MONTH = date.getMonth() + 1,
DATE = date.getDate();

class Key {
constructor(length = 8, symbol = '') {
let values = [];

window.crypto.getRandomValues(new Uint32Array(16)).forEach((value, index, array) => values.push(value.toString(36)));

return this.value = values.join(symbol);
}

rehash(length) {
return this.value = new Key(length);
}
}

// Session key
let SessionKey = new Key(16);

// Object{username, password} => Object
function generateHeaders(auth) {
let headers = { Accept: 'application/json' };
Expand All @@ -19,16 +41,18 @@ function generateHeaders(auth) {
}

// Object{MovieOrShowID, MovieOrShowTitle, MovieOrShowType, MovieOrShowIDProvider, MovieOrShowYear, LinkURL, FileType} => undefined
function changeStatus({ id, tt, ty, pv, yr, ur, ft }) {
function changeStatus({ id, tt, ty, pv, yr, ur = '', ft = '' }) {

let tl = tt.replace(/\-/g, ' ').replace(/[\s\:]{2,}/g, ' - '),
// File friendly title
st = tt.replace(/[\-\s]+/g, '-').replace(/[^\w\-]+/g, '');
st = tt.replace(/[\-\s]+/g, '-').replace(/[^\w\-]+/g, ''),
// Search friendly title
xx = /[it]m/i.test(pv)? 'FX': 'GG';

id = id && !/^tt-?$/i.test(id)? id: null;
id = (id && !/^tt-?$/i.test(id)? id: '') + '';
id = id.replace(/^.*\b(tt\d+)\b.*$/, '$1').replace(/^.*\bid=(\d+)\b.*$/, '$1').replace(/^.*(?:movie|tv|(?:tv-?)?(?:shows?|series|episodes?))\/(\d+).*$/, '$1');

external = { ...external, F: tl, P: pv, Q: id, T: st, U: ur, V: ty, X: {}, Y: yr, Z: ft };
external = { ...external, F: tl, P: pv, Q: id, S: tt, T: st, U: ur, V: ty, X: xx, Y: yr, Z: ft };

chrome.browserAction.setBadgeText({
text: pv
Expand All @@ -39,18 +63,23 @@ function changeStatus({ id, tt, ty, pv, yr, ur, ft }) {
});

chrome.contextMenus.update('W2P', {
title: `About "${ tt } (${ yr || YEAR })"`
title: `Find "${ tt } (${ yr || YEAR })"`
});

for(let array = 'IM TM TV'.split(' '), length = array.length, index = 0, item; index < length; index++)
chrome.contextMenus.update('W2P-' + (item = array[index]), {
title: (
((pv == (item += 'Db')) && id)?
`Open in ${ item } (${ (+id? '#': '') }${ id })`:
`Open in ${ item } (${ (+id? '#': '') + id })`:
`Find in ${ item }`
),
checked: false
});

chrome.contextMenus.update('W2P-XX', {
title: `Find on ${ (xx == 'FX'? 'Flenix': 'Google') }`,
checked: false
});
}

// At this point you might want to think, WHY would you want to do
Expand Down Expand Up @@ -338,11 +367,11 @@ function $searchPlex(connection, headers, options) {
// For examples, see Bone Tomahawk, The Big Short, The Hateful Eight.
// So we'll first try to find the movie with the given year, and then + 1 it.
// Added [strip] to prevent mix-ups, see: "Kingsman: The Golden Circle" v. "The Circle"
let media = movies.find(meta => ((meta.year === +options.year) && strip(meta.title) === strip(options.title))),
let media = movies.find(meta => ((meta.year == +options.year) && strip(meta.title) == strip(options.title))),
key = null;

if (!media) {
media = movies.find(meta => ((meta.year === +options.year + 1) && strip(meta.title) === strip(options.title)));
media = movies.find(meta => ((meta.year == +options.year + 1) && strip(meta.title) == strip(options.title)));
} else {
key = media.key.replace('/children', '');
}
Expand Down Expand Up @@ -388,7 +417,10 @@ chrome.contextMenus.onClicked.addListener((item) => {
db = item.menuItemId.slice(-2).toLowerCase(),
pv = external.P.slice(0, 2).toLowerCase(),
qu = external.Q,
tl = external.T;
tl = external.T,
yr = external.Y,
tt = external.S,
p = (s, r = '+') => s.replace(/-/g, r);

switch(db) {
case 'im':
Expand All @@ -403,20 +435,23 @@ chrome.contextMenus.onClicked.addListener((item) => {
break;
case 'tv':
url = (qu && pv == 'tv')?
`thetvdb.com/series/${ tl }`:
`thetvdb.com/search?q=${ tl.replace(/-/g, '+') }`;
`thetvdb.com/series/${ tl }#${ qu }`: // TVDb accepts either: a title, or a series number... but only one
`thetvdb.com/search?q=${ p(tl) }`;
break;
case 'xx':
url = external.X == 'FX'?
`flenix.tv/?do=search&story=${ p(tt) }&min_year=${ yr || 1990 }&filter=true&max_year=${ yr }&min_imdb=0&max_imdb=10&cat=1&order=date&g-recaptcha-response=${ SessionKey.value }`:
`google.com/search?q="${ p(tl, ' ') } ${ yr }"+${ pv }db`;
break;
case 'dl':
dnl = true;
url = external.U;
break;
default:
url = external.X[db];
break;
default: return;
}

if(!dnl)
window.open(`https://${ url }#${ db }`, '_blank');
window.open(`https://${ url }`, '_blank');
else
chrome.downloads.download({
url,
Expand All @@ -433,41 +468,45 @@ chrome.runtime.onMessage.addListener((request, sender, sendResponse) => {
yr = id.year,
ty = id.type,
pv = (id.TVDbID || id.tvdbId? 'TVDb': id.TMDbID || id.tmdbId? 'TMDb': 'IMDb'),
ur = id.href,
ft = id.tail;
ur = id.href || '',
ft = id.tail || '';
id = id[pv + 'ID'] || id[pv.toLowerCase() + 'Id'];

changeStatus({ id, tt, ty, pv, yr, ur, ft });

switch (request.type) {
case 'SEARCH_PLEX':
searchPlex(request, sendResponse);
return true;
case 'VIEW_COUCHPOTATO':
viewCouchPotato(request, sendResponse);
return true;
case 'ADD_COUCHPOTATO':
addCouchpotato(request, sendResponse);
return true;
case 'ADD_RADARR':
addRadarr(request, sendResponse);
return true;
case 'ADD_SONARR':
addSonarr(request, sendResponse);
return true;
case 'ADD_WATCHER':
addWatcher(request, sendResponse);
return true;
case 'OPEN_OPTIONS':
chrome.runtime.openOptionsPage();
return true;
case 'SAVE_AS':
chrome.contextMenus.update('W2P-DL', {
title: `Save as "${ tt } (${ yr })"`
});
return true;
default:
return false;
changeStatus({ id, tt, yr, ty, pv, ur, ft });

try {
switch (request.type) {
case 'SEARCH_PLEX':
searchPlex(request, sendResponse);
return true;
case 'VIEW_COUCHPOTATO':
viewCouchPotato(request, sendResponse);
return true;
case 'ADD_COUCHPOTATO':
addCouchpotato(request, sendResponse);
return true;
case 'ADD_RADARR':
addRadarr(request, sendResponse);
return true;
case 'ADD_SONARR':
addSonarr(request, sendResponse);
return true;
case 'ADD_WATCHER':
addWatcher(request, sendResponse);
return true;
case 'OPEN_OPTIONS':
chrome.runtime.openOptionsPage();
return true;
case 'SAVE_AS':
chrome.contextMenus.update('W2P-DL', {
title: `Save as "${ tt } (${ yr })"`
});
return true;
default:
return false;
}
} catch (error) {
return sendResonpse(String(error));
}
});

Expand All @@ -481,6 +520,7 @@ saveItem = chrome.contextMenus.create({
title: 'Ready'
});

// Standard search engines
for(let array = 'IM TM TV'.split(' '), DL = {}, length = array.length, index = 0, item; index < length; index++)
chrome.contextMenus.create({
id: 'W2P-' + (item = array[index]),
Expand All @@ -489,3 +529,12 @@ for(let array = 'IM TM TV'.split(' '), DL = {}, length = array.length, index = 0
type: 'checkbox',
checked: true // implement a way to use the checkboxes?
});

// Non-standard search engines
chrome.contextMenus.create({
id: 'W2P-XX',
parentId: parentItem,
title: `Using best guess`,
type: 'checkbox',
checked: true // implement a way to use the checkboxes?
});
Binary file added src/img/local.couchpotato.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/img/local.plex.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/img/local.radarr.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/img/local.sonarr.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/img/local.watcher.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/img/o16.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/img/o48.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified src/img/plex.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/img/watcher.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 3 additions & 3 deletions src/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
"update_url": "https://github.com/Ephellon/web-to-plex/raw/master/hhkmjeeccipbolailpomhjhmccnnjhkj.crx",

"name": "Web to Plex",
"description": "Adds a button on various movie & TV show sites to open it in Plex.",
"description": "Adds a button on various movie & TV show sites to open the item in Plex, or send to your designated NZB manager for download.",
"homepage_url": "https://github.com/Ephellon/web-to-plex/",

"manifest_version": 2,
"version": "3.0.1.0",
"version": "3.0.2.0",
// Firefox Support =>
// "applications": {
// "gecko": {
Expand Down Expand Up @@ -133,5 +133,5 @@
"http://*/",
"https://*/"
],
"web_accessible_resources": ["img/16.png", "img/48.png", "img/_16.png", "img/_48.png"]
"web_accessible_resources": ["img/16.png", "img/48.png", "img/_16.png", "img/_48.png", "img/o16.png", "img/o48.png"]
}
31 changes: 25 additions & 6 deletions src/options/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ const storage = (chrome.storage.sync || chrome.storage.local),
];

let PlexServers = [],
ServerID = null,
ClientID = null,
manifest = chrome.runtime.getManifest(),
terminal = // See #3
Expand All @@ -69,6 +70,14 @@ let PlexServers = [],

chrome.manifest = chrome.runtime.getManifest();

function load(name) {
return JSON.parse(localStorage.getItem(btoa(name)));
}

function save(name, data) {
return localStorage.setItem(btoa(name), JSON.stringify(data));
}

function getServers(plexToken) {
return fetch('https://plex.tv/api/resources?includeHttps=1', {
headers: {
Expand Down Expand Up @@ -375,8 +384,9 @@ function performSonarrTest(QualityProfileID, StoragePath) {
}

function saveOptions() {
let status = $$('#status'),
ServerID = __servers__.options[__servers__.selectedIndex].value;
let status = $$('#status');

ServerID = __servers__.options[__servers__.selectedIndex].value;

if(!ServerID) {
return status.textContent = 'Select a server!',
Expand Down Expand Up @@ -434,7 +444,11 @@ function saveOptions() {
storage.set({ ClientID });
}

options.plexURL = (options.plexURL || "")
options.watcherURLRoot = null;
options['c2x1ZytyaW90KzIwMTg'] = null;
options['slug+riot+2018'] = null;

options.plexURL = options.plexURLRoot = (options.plexURL || "")
.replace(/([^\\\/])$/, endingSlash)
.replace(/^(?!^https?:\/\/)(.+)/, 'http://$1');

Expand All @@ -456,6 +470,11 @@ function saveOptions() {
options.sonarrStoragePath = options.sonarrStoragePath
.replace(/([^\\\/])$/, endingSlash);

terminal.log(options);

for(let index = 0, array = 'plex watcher radarr sonarr couchpotato'.split(' '), item = save('URLs', array); index < array.length; index++)
save(`${ item = array[index] }.url`, options[`${ item }URLRoot`]);

function requestURLPermissions(url) {
if(!url) return;

Expand Down Expand Up @@ -539,9 +558,9 @@ function restoreOptions() {
// Sigh... This is a workaround for Firefox; newer versions have support for the `chrome.storage.sync` API,
// BUT, it will throw an error if you haven't enabled it...
if(chrome.runtime.lastError)
chrome.storage.local.get(null, setOptions); else {
chrome.storage.local.get(null, setOptions);
else
setOptions(items);
}
});
}

Expand All @@ -550,7 +569,7 @@ __save__.addEventListener('click', saveOptions);

document
.querySelector('#plex_test')
.addEventListener('click', () => {
.addEventListener('click', event => {
let t = $$('#plex_token');

if(t && t.value)
Expand Down

0 comments on commit 44a84c5

Please sign in to comment.