Skip to content

Commit

Permalink
Merge branch 'pr/122' into beta-branch
Browse files Browse the repository at this point in the history
  • Loading branch information
Ephellon committed Dec 2, 2019
2 parents 26e5118 + 9536aea commit 1f45ee5
Show file tree
Hide file tree
Showing 63 changed files with 2,244 additions and 903 deletions.
17 changes: 14 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -121,11 +121,15 @@ The sites used as search engines (IMDb, TMDb, and TVDb) will automatically creat

## Installing Web to Plex

**Download on [Chrome Webstore](https://chrome.google.com/webstore/detail/movieo-to-plex/kmcinnefmnkfnmnmijfmbiaflncfifcn).**
### Install the extension (Store)

**Download on [FireFox Add-ons](https://addons.mozilla.org/en-US/firefox/addon/web-to-plex/).**
<a href="https://chrome.google.com/webstore/detail/movieo-to-plex/kmcinnefmnkfnmnmijfmbiaflncfifcn"><img alt="Get it for Chrome" src="badge.chrome.png" /></a>
<a href="https://addons.mozilla.org/en-US/firefox/addon/web-to-plex/"><img alt="Get it for Firefox" src="badge.firefox.png" /></a>

**Download the source code for [Google Chrome/Opera](src.zip), or [Firefox](moz.zip).**
### Install the source code (ZIP)

<a href="src.zip"><img alt="Get it for Chrome" src="source.chrome.png" /></a>
<a href="moz.zip"><img alt="Get it for Firefox" src="source.firefox.png" /></a>

## Requirements

Expand All @@ -145,3 +149,10 @@ The sites used as search engines (IMDb, TMDb, and TVDb) will automatically creat
If you have any problem with the extension, please don't hesitate to [submit an issue](https://github.com/SpaceK33z/web-to-plex/issues/new/choose).

All contributions are welcome.

----

*Google Chrome is a trademark of Google Inc. Use of this trademark is subject to Google Permissions.*
*Firefox is a trademark of Mozilla Org. Use of this trademark is subject to Mozilla Permissions.*
*Safari is a trademark of Apple Inc. Use of this trademark is subject to Apple Permissions.*
*Plex is a trademark of Plex Inc. Use of this trademark is subject to Plex Permissions.*
Binary file added badge.chrome.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added badge.firefox.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified example.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
29 changes: 29 additions & 0 deletions moz/@.consistent.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
let NO_DEBUGGER = false;

let terminal =
NO_DEBUGGER?
{ error: m => m, info: m => m, log: m => m, warn: m => m, group: m => m, groupEnd: m => m }:
console;

let check;

check = document.body.onload = event => {
let video = document.querySelector('video');

if(video && (video.src || video.textContent)) {
let { src } = video;

src = src || video.textContent;

if(/^blob:/i.test(src))
throw '<blob> URL detected. Unable to reform file.';

try {
top.postMessage({ href: src, tail: 'MP4', type: 'SEND_VIDEO_LINK', from: 'consistent' }, '*');
} catch(error) {
terminal.error('Failed to post message:', error);
}
} else {
setTimeout(check, 500);
}
};
29 changes: 29 additions & 0 deletions moz/@.fembed.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
let NO_DEBUGGER = false;

let terminal =
NO_DEBUGGER?
{ error: m => m, info: m => m, log: m => m, warn: m => m, group: m => m, groupEnd: m => m }:
console;

let check;

check = document.body.onload = event => {
let video = document.querySelector('video');

if(video && (video.src || video.textContent)) {
let { src } = video;

src = src || video.textContent;

if(/^blob:/i.test(src))
throw '<blob> URL detected. Unable to reform file.';

try {
top.postMessage({ href: src, tail: 'MP4', type: 'SEND_VIDEO_LINK', from: 'fembed' }, '*');
} catch(error) {
terminal.error('Failed to post message:', error);
}
} else {
setTimeout(check, 500);
}
};
29 changes: 29 additions & 0 deletions moz/@.gounlimited.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
let NO_DEBUGGER = false;

let terminal =
NO_DEBUGGER?
{ error: m => m, info: m => m, log: m => m, warn: m => m, group: m => m, groupEnd: m => m }:
console;

let check;

check = document.body.onload = event => {
let video = document.querySelector('video');

if(video && (video.src || video.textContent)) {
let { src } = video;

src = src || video.textContent;

if(/^blob:/i.test(src))
throw '<blob> URL detected. Unable to reform file.';

try {
top.postMessage({ href: src, tail: 'MP4', type: 'SEND_VIDEO_LINK', from: 'gounlimited' }, '*');
} catch(error) {
terminal.error('Failed to post message:', error);
}
} else {
setTimeout(check, 500);
}
};
29 changes: 29 additions & 0 deletions moz/@.oload.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
let NO_DEBUGGER = false;

let terminal =
NO_DEBUGGER?
{ error: m => m, info: m => m, log: m => m, warn: m => m, group: m => m, groupEnd: m => m }:
console;

let check;

check = document.body.onload = event => {
let video = document.querySelector('div > p + p');

if(video && (video.src || video.textContent)) {
let { src } = video;

src = src || video.textContent;

if(/^blob:/i.test(src))
throw '<blob> URL detected. Unable to reform file.';

try {
top.postMessage({ href: `https://oload.fun/stream/${ src }?mime=true`, tail: 'MP4', type: 'SEND_VIDEO_LINK', from: 'oload' }, '*');
} catch(error) {
terminal.error('Failed to post message:', error);
}
} else {
setTimeout(check, 500);
}
};
146 changes: 146 additions & 0 deletions moz/@.plex.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
/** plxdwnld - Pip Longrun / Ephellon
*
* This project is licensed under the terms of the MIT license, see https://piplongrun.github.io/plxdwnld/LICENSE.txt
*
* @author Pip Longrun <pip.longrun@protonmail.com>
* @version 0.2
* @see https://piplongrun.github.io/plxdwnld/
*
*/

let plxdwnld = (() => {
let self = {}, R = RegExp,
baseURI, AccessToken,
RegExps = {
clientID: /server\/([a-f\d]{40})\//i,
metadataID: /key=%2Flibrary%2Fmetadata%2F(\d+)/i,
},
URLExps = {
API_resource: 'https://plex.tv/api/resources?includeHttps=1&X-Plex-Token={token}',
API_library: '{baseuri}/library/metadata/{id}?X-Plex-Token={token}',
download: '{baseuri}{partkey}?download=1&X-Plex-Token={token}',
},
access_token_path = '//Device[@clientIdentifier=\'{clientID}\']/@accessToken',
base_uri_path = '//Device[@clientIdentifier=\'{clientID}\']/Connection[@local=0]/@uri',
part_key_path = '//Media/Part[1]/@key';

// Errors
let ERROR = {
EMPTY: 'No response data was received',
NOT_PLEX: 'You are not browsing (or logged into) Plex',
NOT_MEDIA: 'You are not viewing a media item',
INVALID_TOKEN: 'Unable to find a valid Access Token',
};

let getXML = (url, callback) => {
fetch(`//cors-anywhere.herokuapp.com/${ url }`, { method: 'GET', headers: { 'X-Requested-With': 'XMLHttpRequest' } })
.then(Q => Q.text())
.then(text => {
if(!text.length)
throw ERROR.EMPTY;

let Parser = new DOMParser(),
XML = Parser.parseFromString(text, 'text/xml');

callback(XML);
})
.catch(error => { throw error });
};

let getMetadata = (XML) => {
let clientID = RegExps.clientID.test(location.href)?
R.$1:
null;

if(clientID) {
let access_token_node = XML.evaluate(
access_token_path.replace(/{clientid}/ig, clientID),
XML,
null,
XPathResult.FIRST_ORDERED_NODE_TYPE,
null
),
base_uri_node = XML.evaluate(
base_uri_path.replace(/{clientid}/ig, clientID),
XML,
null,
XPathResult.FIRST_ORDERED_NODE_TYPE,
null
);

if(access_token_node.singleNodeValue && base_uri_node.singleNodeValue) {
AccessToken = access_token_node.singleNodeValue.textContent;
baseURI = base_uri_node.singleNodeValue.textContent;

let metadataID = RegExps.metadataID.test(location.href)?
R.$1:
null;

if(metadataID)
getXML(
URLExps.API_library
.replace(/{baseuri}/ig, baseURI)
.replace(/{id}/ig, metadataID)
.replace(/{token}/ig, AccessToken)
, GetDownloadURL
);
else
throw ERROR.NOT_MEDIA;
} else {
throw ERROR.INVALID_TOKEN;
}
} else {
throw ERROR.NOT_MEDIA;
}
};

let GetDownloadURL = (XML) => {
let part_key_node = XML.evaluate(part_key_path, XML, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null);

if(part_key_node.singleNodeValue) {
let href = URLExps.download
.replace(/{baseuri}/ig, baseURI)
.replace(/{partkey}/ig, part_key_node.singleNodeValue.textContent)
.replace(/{token}/ig, AccessToken);

top.postMessage({ href, tail: 'MP4', type: 'SEND_VIDEO_LINK', from: 'plex' }, '*');
} else {
throw ERROR.NOT_MEDIA;
}
};

self.init = () => {
if(localStorage.myPlexAccessToken !== undefined)
getXML(URLExps.API_resource.replace(/{token}/ig, localStorage.myPlexAccessToken), getMetadata);
else
throw ERROR.NOT_PLEX;
};

return self;
})();

let NO_DEBUGGER = false;

let terminal =
NO_DEBUGGER?
{ error: m => m, info: m => m, log: m => m, warn: m => m, group: m => m, groupEnd: m => m }:
console;

let check;

check = document.body.onload = event => {
let loading = document.querySelector('.loading');

if(!loading) {
setTimeout(() => {
try {
plxdwnld.init();
} catch(error) {
terminal.error('Failed to post message:', error);
setTimeout(check, 5000);
}
}, 5000)
} else {
setTimeout(check, 500);
}
};
34 changes: 26 additions & 8 deletions moz/background.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,6 @@ function ChangeStatus({ ITEM_ID, ITEM_TITLE, ITEM_TYPE, ID_PROVIDER, ITEM_YEAR,
});
}


// get the saved options
function getConfiguration() {
return new Promise((resolve, reject) => {
Expand Down Expand Up @@ -146,8 +145,6 @@ function getConfiguration() {
// self explanatory, returns an object; sets the configuration variable
function parseConfiguration() {
return getConfiguration().then(options => {
BACKGROUND_CONFIGURATION = options;

if((BACKGROUND_DEVELOPER = options.DeveloperMode) && !parseConfiguration.gotConfig) {
parseConfiguration.gotConfig = true;
BACKGROUND_TERMINAL =
Expand All @@ -162,9 +159,26 @@ function parseConfiguration() {
}, error => { throw error });
}

(async() => {
await parseConfiguration();
})();
function load(name, private) {
return JSON.parse((private && sessionStorage? sessionStorage: localStorage).getItem(btoa(name)));
}

function save(name, data, private) {
return (private && sessionStorage? sessionStorage: localStorage).setItem(btoa(name), JSON.stringify(data));
}

async function UpdateConfiguration(force_update = false) {
let configuration = load('configuration');

if(force_update || configuration === null || configuration === undefined)
BACKGROUND_CONFIGURATION = await parseConfiguration();
else
BACKGROUND_CONFIGURATION = configuration;

save('configuration', BACKGROUND_CONFIGURATION);
};

UpdateConfiguration();

/** CouchPotato - Movies **/
// At this point you might want to think, WHY would you want to do
Expand Down Expand Up @@ -446,7 +460,7 @@ function Push_Medusa(request, sendResponse) {
return fetch(`${ request.url }`, debug.requestHeaders = {
method: 'POST',
mode: cors(request.url),
body: JSON.stringify({ id: { tvdb: request.tvdbId } }),
body: JSON.stringify({ id: { tvdb: id } }),
headers
});
})
Expand Down Expand Up @@ -520,7 +534,7 @@ function addMedusa(request, sendResponse) {
return fetch(`${ request.url }`, debug.requestHeaders = {
method: 'POST',
mode: cors(request.url),
body: JSON.stringify({ id: { tvdb: request.tvdbId } }),
body: JSON.stringify({ id: { tvdb: id } }),
headers
});
})
Expand Down Expand Up @@ -963,6 +977,10 @@ browser.runtime.onMessage.addListener((request = {}, sender, callback) => {
});
break;

case 'UPDATE_CONFIGURATION':
UpdateConfiguration(true);
break;

case 'PLUGIN':
case 'SCRIPT':
case '_INIT_':
Expand Down
Loading

0 comments on commit 1f45ee5

Please sign in to comment.