Skip to content

Commit

Permalink
Upgrade to 3.1 (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 26, 2018
1 parent 44a84c5 commit 11a23e7
Show file tree
Hide file tree
Showing 10 changed files with 166 additions and 54 deletions.
51 changes: 24 additions & 27 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,41 +29,43 @@ Getting the repo ready for a pull request.

## Supported sites: *Site (button location)*

- [Movieo](http://movieo.me/) ([button location](button-locations/movieo.png))
- [IMDb](http://imdb.com/) ([button location](button-locations/imdb.png))
- [Trakt.tv](https://trakt.tv/) ([button location](button-locations/trakt.png))
- [Letterboxd](https://letterboxd.com/) ([button location](button-locations/letterboxd.png))
- [Flenix](https://flenix.co/)<sup>1</sup> ([button locations](button-locations/flenix.png))
- [TV Maze](http://www.tvmaze.com/) ([button location](button-locations/tvmaze.png))
- [The TVDb](https://www.thetvdb.com/) ([button location](button-locations/tvdb.png))
- [The MovieDb](https://www.themoviedb.org/) ([button location](button-locations/tmdb.png))
- [VRV](https://vrv.co/)<sup>2</sup> ([button location](button-locations/vrv.png))
- [Hulu](https://hulu.com/)<sup>2/3/4</sup> ([button location](button-locations/hulu.png))
- [Google Play Store](https://play.google.com/store/movies/) ([button location](button-locations/google.png))
- [iTunes](https://itunes.apple.com/)<sup>3</sup> ([button location](button-locations/itunes.png))
- [Metacritic](http://www.metacritic.com/)<sup>4</sup> ([button location](button-locations/metacritic.png))
- [Fandango](https://www.fandango.com/) ([button location](button-locations/fandango.png))
- [Amazon](https://www.amazon.com/) ([button location](button-locations/amazon.png))
- [Vudu](https://www.vudu.com/) ([button location](button-locations/vudu.png))
- [Verizon](https://www.tv.verizon.com/) ([button location](button-locations/verizon.png))
- [CouchPotato](http://couchpotato.life/) ([button location](button-locations/couch-potato.png))
- [Rotten Tomatoes](https://www.rottentomatoes.com/) ([button location](button-locations/rotten-tomatoes.png))
- [ShowRSS](https://showrss.info/)<sup>1</sup> (no button location)
1. [Movieo](http://movieo.me/) ([button location](button-locations/movieo.png))
2. [IMDb](http://imdb.com/) ([button location](button-locations/imdb.png))
3. [Trakt.tv](https://trakt.tv/) ([button location](button-locations/trakt.png))
4. [Letterboxd](https://letterboxd.com/) ([button location](button-locations/letterboxd.png))
5. [Flenix](https://flenix.co/)<sup>1/5</sup> ([button locations](button-locations/flenix.png))
6. [TV Maze](http://www.tvmaze.com/) ([button location](button-locations/tvmaze.png))
7. [The TVDb](https://www.thetvdb.com/) ([button location](button-locations/tvdb.png))
8. [The MovieDb](https://www.themoviedb.org/) ([button location](button-locations/tmdb.png))
9. [VRV](https://vrv.co/)<sup>2</sup> ([button location](button-locations/vrv.png))
10. [Hulu](https://hulu.com/)<sup>2/3/4</sup> ([button location](button-locations/hulu.png))
11. [Google Play Store](https://play.google.com/store/movies/) ([button location](button-locations/google.png))
12. [iTunes](https://itunes.apple.com/)<sup>3/5</sup> ([button location](button-locations/itunes.png))
13. [Metacritic](http://www.metacritic.com/)<sup>4</sup> ([button location](button-locations/metacritic.png))
14. [Fandango](https://www.fandango.com/) ([button location](button-locations/fandango.png))
15. [Amazon](https://www.amazon.com/)<sup>5</sup> ([button location](button-locations/amazon.png))
16. [Vudu](https://www.vudu.com/) ([button location](button-locations/vudu.png))
17. [Verizon](https://www.tv.verizon.com/) ([button location](button-locations/verizon.png))
18. [CouchPotato](http://couchpotato.life/) ([button location](button-locations/couch-potato.png))
19. [Rotten Tomatoes](https://www.rottentomatoes.com/) ([button location](button-locations/rotten-tomatoes.png))
20. [ShowRSS](https://showrss.info/)<sup>1</sup> (no button location)
21. [Netflix](https://netflix.com/)<sup>3</sup> ([button location](button-locations/netflix.png))

*Notes*

- `1` *This site uses the `Right click | Save as...` feature (file download), or a direct link (usually magnet URL).*
- `1` *This site uses the `Right click | Web to Plex | Save as...` feature (file download), or a direct link (usually magnet URL).*
- `2` *This site has a loading issue, simply refresh the page if the button doesn't appear.*
- `3` *This site doesn't allow media browsing, or requires a subscription beforehand.*
- `4` *This site is network intensive (loads slowly). Be patient.*
- `5` *This site is known to update frequently, support may change without notice.*

## In Progress sites (adding support):

- Nothing here... for now

## En Progress sites (may add support):

- [Netflix](https://netflix.com/)<sup>3</sup>
- Nothing here... for now

## Installing Web to Plex

Expand All @@ -84,8 +86,3 @@ Getting the repo ready for a pull request.
If you have any problem with the extension, please don't hesitate to [submit an issue](https://github.com/Ephellon/web-to-plex/issues/new).

All contributions are welcome.

## Related

- [Web to Plex (original)](https://github.com/SpaceK33z/web-to-plex)
- [IMDb to Movieo by SpaceK33z](https://github.com/SpaceK33z/imdb-to-movieo)
Binary file added button-locations/netflix.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
13 changes: 9 additions & 4 deletions change.log
Original file line number Diff line number Diff line change
Expand Up @@ -208,14 +208,14 @@
- **Added the `sendUpdate(String type[, Object options])` method to `/utils.js`**
- Fixed Trakt's button error

## v3.0.2.0 / unreleased
## v3.0.2.0 / SpaceK33z@44a84c575c6ec8f8a0b83c95fd7c81cc41c9a35e

- **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 "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
Expand All @@ -228,5 +228,10 @@
- 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`

## v3.1.0.0 / unreleased

- **Added Netflix support**
- Made changes to the `String..toCaps` method
- Made searches better via `/utils.js`
- replaced some non-latin characters (i.e. the curly apostrophe) with an acceptable counter-part (a "normal" apostrophe)
Binary file modified src.crx
Binary file not shown.
Binary file modified src.zip
Binary file not shown.
8 changes: 6 additions & 2 deletions src/manifest.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
{
"update_url": "https://github.com/Ephellon/web-to-plex/raw/master/hhkmjeeccipbolailpomhjhmccnnjhkj.crx",
"update_url": "https://github.com/Ephellon/web-to-plex/raw/master/src.crx",

"name": "Web to 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.2.0",
"version": "3.1.0.0",
// Firefox Support =>
// "applications": {
// "gecko": {
Expand Down Expand Up @@ -99,6 +99,10 @@
"matches": ["*://*.rottentomatoes.com/*/*"],
"js": ["utils.js", "sites/rottentomatoes/index.js"],
"css": ["sites/rottentomatoes/index.css", "sites/common.css"]
},{
"matches": ["*://*.netflix.com/watch/*"],
"js": ["utils.js", "sites/netflix/index.js"],
"css": ["sites/netflix/index.css", "sites/common.css"]
}
],

Expand Down
2 changes: 1 addition & 1 deletion src/popup/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@
<body>
<table>
<tr>
<td id="netflix" disabled cost-cash-low="$7.99/month">
<td id="netflix" cost-cash-low="$7.99/month">
<a href="https://netflix.com/" target="_blank">
<img alt="Netflix" src="../img/netflix.png" />
<label>Netflix</label>
Expand Down
27 changes: 27 additions & 0 deletions src/sites/netflix/index.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
.web-to-plex-button {
color: #fff !important;
}

.web-to-plex-button--downloader {
color: #f45a26 !important;
}

.web-to-plex-button--downloader:hover {
color: #f67e56 !important;
}

.web-to-plex-button--found {
color: #e5a00d !important;
}

.web-to-plex-button--found:hover {
color: #f9be03 !important;
}

#tt--0-0 {
color: #666!important;
}

#tt--0-0:hover {
color: #888!important;
}
70 changes: 70 additions & 0 deletions src/sites/netflix/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
/* global findPlexMedia, parseOptions, modifyPlexButton */
function isReady() {
let element = $$('[class$="__time"]');

return document.readyState == 'complete' && element && !/^([0:]+|null|undefined)?$/.test(element.textContent);
}

function isMovie() {
return !isShow();
}

function isShow() {
return $$('[class*="playerEpisodes"]');
}

let $$ = selector => document.querySelector(selector);

function renderPlexButton($parent) {
if (!$parent) return;

let existingButton = $$('a.web-to-plex-button');
if (existingButton)
existingButton.remove();

let el = document.createElement('a'),
ch = document.createElement('img'),
gc = document.createElement('span');

el.setAttribute('class', 'web-to-plex-button touchable PlayerControls--control-element nfp-button-control default-control-button button-nfplayerFullscreen PlayerControls--control-element--with-label');
el.setAttribute('role', 'button');
ch.src = chrome.extension.getURL('img/o48.png');
ch.height = ch.width = 28;
gc.classList.add('PlayerControls__button-label');
gc.textContent = 'Web to Plex';

el.appendChild(ch);
el.appendChild(gc);

$parent.insertBefore(el, $parent.lastChild);

return el;
}

async function initPlexThingy(type) {
let $button = renderPlexButton($$('[class$="button-control-row"]'));

if (!$button)
return;

terminal.log(type);

let $title = $$('.video-title h4'),
title = $title.innerText.replace(/^\s+|\s+$/g, '').toCaps() || sessionStorage.getItem(`last-${type}-title`),
year = 0,
Db = await getIDs({ title, year, type }),
IMDbID = Db.imdb,
TMDbID = Db.tmdb,
TVDbID = Db.tvdb;

title = Db.title;
year = Db.year;

sessionStorage.setItem(`last-${type}-title`, title);

findPlexMedia({ type, title, year, button: $button, IMDbID, TMDbID, TVDbID, txt: 'title', hov: 'null' });
}

(window.onlocationchange = () =>
wait(isReady, () => parseOptions().then(async() => await initPlexThingy(isMovie()? 'movie': 'tv')))
)();
49 changes: 29 additions & 20 deletions src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,11 @@ function watchlocationchange() {
setInterval(watchlocationchange, 1000); // at least 1s is needed to properly fire the event :/

function load(name) {
return JSON.parse((sessionStorage || localStorage).getItem(btoa(name)));
return JSON.parse((sessionStorage || localStorage).getItem('Web-to-Plex@' + name));
}

function save(name, data) {
return (sessionStorage || localStorage).setItem(btoa(name), JSON.stringify(data));
return (sessionStorage || localStorage).setItem('Web-to-Plex@' + name, JSON.stringify(data));
}

function sendUpdate(type, options = {}) {
Expand Down Expand Up @@ -184,7 +184,11 @@ async function getIDs({ title, year, type, IMDbID, TMDbID, TVDbID, APIType, APII
/(movie|film)/i.test(rqut)?
'tmdb':
rqut || '*';
title = title? title.replace(/\s*[\:,]\s*Season\s+\d+.*$/i, '').toCaps(): title;
title = (title? title.replace(/\s*[\:,]\s*Season\s+\d+.*$/i, '').toCaps(): title)
.replace(/\u201a/g, ',')
.replace(/[\u2019\u201b]/g, "'")
.replace(/[\u201c\u201d]/g, '"')
.replace(/[^\u0000-\u00ff]+/g, '');
year = year? (year + '').replace(/\D+/g, ''): load(title) || year;

function plus(string) { return string.replace(/\s+/g, '+') }
Expand All @@ -205,15 +209,15 @@ async function getIDs({ title, year, type, IMDbID, TMDbID, TVDbID, APIType, APII
(rqut == 'tmdb' || (rqut == '*' && !mid && title && year) || apit == 'movie')?
(apit && apid)?
`https://api.themoviedb.org/3/${ apit }/${ apid }?api_key=${ api.tmdb }`:
`https://api.themoviedb.org/3/search/${ apit }?api_key=${ api.tmdb }&query=${ encodeURI(title) }&year=${ year }`:
`https://api.themoviedb.org/3/search/${ apit }?api_key=${ api.tmdb }&query=${ encodeURI(title) }${ year? '&year=' + year: '' }`:
(rqut == 'tvdb' || (rqut == '*' && !tid && title) || apid)?
(apid)?
`https://api.tvmaze.com/shows/${ apid }`:
`https://api.tvmaze.com/search/shows?q=${ encodeURI(title) }`:
(title)?
(apit && year)?
`https://www.theimdbapi.org/api/find/${ apit }?title=${ encodeURI(title) }&year=${ year }`:
`https://www.theimdbapi.org/api/find/movie?title=${ encodeURI(title) }&year=${ year }`:
`https://www.theimdbapi.org/api/find/movie?title=${ encodeURI(title) }${ year? '&year=' + year: '' }`:
null;

if(url === null) return 0;
Expand Down Expand Up @@ -264,8 +268,8 @@ async function getIDs({ title, year, type, IMDbID, TMDbID, TVDbID, APIType, APII
return f? o: f;
})($data);
//api.themoviedb.org/ \remote
else if('original_name' in $data && 'release_date' in $data)
found = (TMDbID == $data.id || (t($data.original_name) === t(title) || t($data.name) === t(title)) && year == ($data || b).release_date.slice(0, 4))?
else if(('original_name' in $data || 'original_title' in $data) && 'release_date' in $data)
found = (TMDbID == $data.id || (t($data.original_name) === t(title) || t($data.original_title) === t(title) || t($data.name) === t(title)) && year == ($data || b).release_date.slice(0, 4))?
$data:
found;
//theimdbapi.org/
Expand Down Expand Up @@ -303,8 +307,8 @@ async function getIDs({ title, year, type, IMDbID, TMDbID, TVDbID, APIType, APII
return f? o: f;
})($data);
//api.themoviedb.org/ \remote
else if('original_name' in $data)
found = (c($data.original_name) == c(title) || c($data.name) == c(title))?
else if('original_name' in $data || 'original_title' in $data)
found = (c($data.original_name) == c(title) || c($data.original_title) == c(title) || c($data.name) == c(title))?
$data:
found;
//theimdbapi.org/
Expand All @@ -331,16 +335,16 @@ async function getIDs({ title, year, type, IMDbID, TMDbID, TVDbID, APIType, APII
tmdb: TMDbID || json.externals.themoviedb | 0,
tvdb: TVDbID || json.externals.thetvdb | 0,
title,
year: json.premiered || json.first_aired_date || year
year: ((json.premiered || json.first_aired_date || year) + '').slice(0, 4)
};
//api.themoviedb.org/
else if('imdb_id' in json)
else if('imdb_id' in json || 'original_name' in json || 'original_title' in json)
data = {
imdb: IMDbID || json.imdb_id || ei,
tmdb: TMDbID || json.id | 0,
tvdb: TVDbID || json.tvdb | 0,
title,
year: json.release_date || json.first_air_date || year
year: ((json.release_date || json.first_air_date || year) + '').slice(0, 4)
};
//omdbapi.com/
else if('imdbID' in json)
Expand All @@ -366,15 +370,17 @@ async function getIDs({ title, year, type, IMDbID, TMDbID, TVDbID, APIType, APII
imdb: IMDbID || json.imdb || ei,
tmdb: TMDbID || json.id | 0,
tvdb: TVDbID || json.tvdb | 0,
title, year
title,
year
};

year = (data.year + '').slice(0, 4);
year = data.year = +year | 0;
year = +((data.year + '').slice(0, 4)) || 0;
data.year = year;

terminal.log('Best match', { title, year, data, type, rqut, score: json.score | 0 });

save(savename, data);
save(savename, data); // e.g. "Coco (0)" on Netflix before correction / no repeat searches
save(savename = `${title} (${year}).${rqut}`, data); // e.g. "Coco (2017)" on Netflix after correction / no repeat searches
save(title, year);

terminal.log(`Saved as "${ savename }"`, data);
Expand Down Expand Up @@ -850,15 +856,18 @@ String.prototype.toCaps = String.prototype.toCaps || function toCaps(all) {
* Prepositions: across, after, although, at, because, before, between, by, during, from, if, in, into, of, on, to, through, under, with, & without
*/
let array = this.toLowerCase(),
titles = /(?!^)\b(a([st]|nd?|cross|fter|lthough)?|b(e(cause|fore|tween)|ut|y)|during|from|in(to)?|[io][fn]|[fn]?or|the|[st]o|through|under|with(out)?|yet)\b/gi,
titles = /(?!^|an?|the)\b(a([st]|nd?|cross|fter|lthough)?|b(e(cause|fore|tween)|ut|y)|during|from|in(to)?|[io][fn]|[fn]?or|the|[st]o|through|under|with(out)?|yet)(?!\s*$)\b/gi,
exceptions = /([\:\|\.\!\?\"\(]\s*[a-z]|\b[^aeiou\d\W]+\b)/gi;

array = array.split(/\s+/);

let index, length, string, word;
for(index = 0, length = array.length, string = [], word; index < length; index++)
word = array[index],
string.push( word[0].toUpperCase() + word.slice(1, word.length) );
for(index = 0, length = array.length, string = [], word; index < length; index++) {
word = array[index];

if(word)
string.push( word[0].toUpperCase() + word.slice(1, word.length) );
}

string = string.join(' ');

Expand Down

0 comments on commit 11a23e7

Please sign in to comment.