Skip to content
This repository has been archived by the owner on Oct 11, 2022. It is now read-only.

Commit

Permalink
Merge pull request #108 from gsrafael01/master
Browse files Browse the repository at this point in the history
 Fix authentication and scrobble issues
  • Loading branch information
Rafael authored Jul 23, 2019
2 parents aaae286 + 447073f commit 5ac74b1
Show file tree
Hide file tree
Showing 11 changed files with 65 additions and 10 deletions.
1 change: 1 addition & 0 deletions .vscode
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,31 +34,31 @@
* [Development](#development)

### What is Trakt?
Automatically scrobble TV show episodes and movies you are watching to Trakt.tv! Keep a history of everything you've watched! Sign up for a free account at [Trakt.tv](http://trakt.tv) and get a ton of features.
Automatically scrobble TV show episodes and movies you are watching to Trakt.tv! Keep a history of everything you've watched! Sign up for a free account at [Trakt.tv](https://trakt.tv) and get a ton of features.

### Why do I need this extension?
Trakt.tv has a [lot of plugins](http://trakt.tv/downloads) to automatically scrobble the movies and episodes you watch from your media center.
Trakt.tv has a [lot of plugins](https://trakt.tv/downloads) to automatically scrobble the movies and episodes you watch from your media center.
But there are none for Netflix.
This extension allows you to scrobble from Netflix to Trakt.tv. Cool, isn't it?

### How does traktflix work?
Unfortunately Netflix doesn't provide a public API, so the movie or episode info is extracted from the HTML of the player.

### Limitations
This extension only works with Netflix HTML player and new layout. If you are in the [old layout](http://www.netflix.com/WiHome), please open the [new one](http://www.netflix.com/browse).
This extension only works with Netflix HTML player and new layout. If you are in the [old layout](https://www.netflix.com/WiHome), please open the [new one](https://www.netflix.com/browse).
See this link for more info: https://help.netflix.com/en/node/23742

### Problems
If you find any problems or have suggestions or questions, feel free to [open an issue](https://github.com/tegon/traktflix/issues/new)

### Development
Create an application in [Trakt API](http://trakt.tv/oauth/applications/new).
Create an application in [Trakt API](https://trakt.tv/oauth/applications/new).

Don't forget to check `/scrobble` permission.

In `Redirect uri:` put `https://www.netflix.com/Activate`

In `Javascript (cors) origins:` put `http://www.netflix.com, moz-extension:// and chrome-extension://`
In `Javascript (cors) origins:` put `https://www.netflix.com, moz-extension:// and chrome-extension://`

Copy the `config.json` example file and change Trakt.tv credentials:
```bash
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "traktflix",
"description": "A Trakt.tv scrobbler for Netflix.",
"version": "2.0.9",
"version": "2.0.10",
"dependencies": {
"flux": "^2.1.1",
"material-design-lite": "^1.3.0",
Expand Down
8 changes: 6 additions & 2 deletions scripts/generateManifest.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,17 +69,21 @@ module.exports = function (browserName) {
};

switch (browserName) {
case `chrome`:
case `chrome`: {
const bextJson = require(`${ROOT_PATH}/bext.json`);
manifest.key = bextJson.chrome.extensionKey;
manifest.permissions.push(`declarativeContent`);
break;
case `firefox`:
}
case `firefox`: {
const bextJson = require(`${ROOT_PATH}/bext.json`);
manifest.browser_specific_settings = {
gecko: {
id: bextJson.firefox.extensionId
}
};
break;
}
default:
break;
}
Expand Down
11 changes: 11 additions & 0 deletions src/class/Request.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,19 @@
import Settings from '../settings';
import BrowserStorage from './BrowserStorage';
import Shared from './Shared';

class Request {
async _send(options) {
if (!Shared.isBackgroundPage() && !options.url.match(location.host)) {
try {
const response = await browser.runtime.sendMessage({ type: `request`, options: JSON.stringify(options) });
options.success(response);
} catch (error) {
options.error(error.status, error.responseText, error.options);
}
return;
}

const storage = await BrowserStorage.get(`data`);
const xhr = new XMLHttpRequest();
xhr.open(options.method, options.url, true);
Expand Down
16 changes: 16 additions & 0 deletions src/class/Shared.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
class Shared {
constructor() {
this.backgroundPage = false;
}

setBackgroundPage(backgroundPage) {
this.backgroundPage = backgroundPage;
}

isBackgroundPage() {
return !!this.backgroundPage;
}
}

const shared = new Shared();
export default shared;
16 changes: 15 additions & 1 deletion src/modules/background/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ import BrowserStorage from '../../class/BrowserStorage';
import Oauth from '../../class/Oauth';
import Permissions from '../../class/Permissions';
import Rollbar from '../../class/Rollbar';
import Request from '../../class/Request';
import Shared from '../../class/Shared';

Shared.setBackgroundPage(true);

/* global analytics */
/**
Expand Down Expand Up @@ -64,7 +68,7 @@ if (chrome && chrome.declarativeContent) {
}

browser.runtime.onMessage.addListener((request, sender) => {
return new Promise(async resolve => {
return new Promise(async (resolve, reject) => {
switch (request.type) {
case `getApiDefs`:
// noinspection JSIgnoredPromiseFromCall
Expand Down Expand Up @@ -140,6 +144,16 @@ browser.runtime.onMessage.addListener((request, sender) => {
});
}
break;
case `request`: {
const options = JSON.parse(request.options);
try {
const response = await Request.sendAndWait(options);
resolve(response);
} catch (error) {
reject(error);
}
return;
}
}
resolve();
});
Expand Down
2 changes: 1 addition & 1 deletion src/settings.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const settings = {
authorizeUri: `http://trakt.tv/oauth/authorize`,
authorizeUri: `https://trakt.tv/oauth/authorize`,
apiUri: `https://api.trakt.tv`,
redirectUri: `https://www.netflix.com/Activate`,
clientId: `@@clientId`,
Expand Down
3 changes: 3 additions & 0 deletions test/Oauth.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ import browser from 'sinon-chrome';
import sinon from 'sinon';
import Settings from '../src/settings.js';
import Oauth from '../src/class/Oauth';
import Shared from '../src/class/Shared';

Shared.setBackgroundPage(true);

let server = null;

Expand Down
3 changes: 3 additions & 0 deletions test/Search.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ import browser from 'sinon-chrome';
import sinon from 'sinon';
import Settings from '../src/settings.js';
import Search from '../src/class/Search';
import Shared from '../src/class/Shared';

Shared.setBackgroundPage(true);

window.browser = browser;

Expand Down
3 changes: 3 additions & 0 deletions test/content/Scrobble.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ import sinon from 'sinon';
import Settings from '../../src/settings';
import Scrobble from '../../src/class/content/Scrobble';
import NetflixTestUtils from '../../test-helpers/NetflixTestHelper';
import Shared from '../../src/class/Shared';

Shared.setBackgroundPage(true);

window.browser = browser;

Expand Down

0 comments on commit 5ac74b1

Please sign in to comment.