Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GitHub hbo max fix 2 #404

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -102,10 +102,13 @@ Never delete the `translations` branch after merging PRs from Crowdin, as Crowdi

### Development

1. Create an application in the [Trakt API](https://trakt.tv/oauth/applications/new) (don't forget to check the `/scrobble` permission).
2. In `Redirect uri:`, put `https://trakt.tv/apps`.
3. In `Javascript (cors) origins:`, put `moz-extension://` and `chrome-extension://`.
4. Copy the `.env.example` example file and change the Trakt.tv credentials.
1. Add the extension to your browser, take notice of the extension ID in the browser tab.
- Chrome: https://developer.chrome.com/docs/extensions/mv3/getstarted/#manifest
- Firefox: https://extensionworkshop.com/documentation/develop/getting-started-with-web-ext/
2. Create an application in the [Trakt API](https://trakt.tv/oauth/applications/new) (don't forget to check the `/scrobble` permission).
3. In `Redirect uri:`, put `https://trakt.tv/apps` and for Chrome find the ID of the extension (see step 1), put `https://{ID}.chromiumapp.org/` and replace `{ID}` with the actual id.
4. In `Javascript (cors) origins:`, put `moz-extension://` and `chrome-extension://`.
5. Copy the `.env.example` example file and change the Trakt.tv credentials.

```bash
cp .env.example .env
Expand Down
30 changes: 13 additions & 17 deletions src/services/hbo-max/HboMaxApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ import { Utils } from '@common/Utils';
import { EpisodeItem, MovieItem, ScrobbleItem, ScrobbleItemValues } from '@models/Item';

export interface HboMaxAuthObj {
accessToken: string;
refreshToken: string;
access_token: string;
refresh_token: string;

/** In milliseconds */
accessExpiration: number;
expires_on: number;
}

export interface HboMaxSession extends ServiceApiSession, HboMaxData {}
Expand Down Expand Up @@ -126,14 +126,13 @@ export interface HboMaxContentErrorResponse {
}

class _HboMaxApi extends ServiceApi {
HOST_URL = 'https://www.hbomax.com';
HOST_URL = 'https://play.hbomax.com';
API_BASE = 'api.hbo.com';
GLOBAL_AUTH_URL = `https://oauth.${this.API_BASE}/auth/tokens`;
LOCAL_AUTH_URL = `https://gateway{subdomain}.${this.API_BASE}/auth/tokens`;
CONFIG_URL = `https://sessions.${this.API_BASE}/sessions/v1/clientConfig`;
CONTENT_URL = `https://comet{subdomain}.${this.API_BASE}/content`;
HISTORY_URL = `https://markers{subdomain}.${this.API_BASE}/markers`;
ITEM_METADATA_URL = `https://comet{subdomain}.${this.API_BASE}/express-content/{id}?device-code=desktop&product-code=hboMax&api-version=v9.0&country-code=US&language=en-us`;

/**
* These values were retrieved from https://play.hbomax.com/js/app.js:
Expand Down Expand Up @@ -404,9 +403,10 @@ class _HboMaxApi extends ServiceApi {
}

try {
const responseText = await Requests.send({
url: Utils.replace(this.ITEM_METADATA_URL, { ...this.session, id }),
method: 'GET',
const responseText = await this.authRequests.send({
url: Utils.replace(this.CONTENT_URL, this.session),
method: 'POST',
body: [{ id }],
});
const response = JSON.parse(responseText) as HboMaxItemMetadataResponse;

Expand All @@ -432,21 +432,17 @@ class _HboMaxApi extends ServiceApi {
({ clientId }) => {
const session: Partial<HboMaxSession> = {};

const authStr = window.localStorage.getItem(
`prod:dataservices.dependent.hurley.types.LoginInfo.user:${clientId}`
);
const authStr: any = window.localStorage.getItem('authToken');
if (authStr) {
const authObj = JSON.parse(authStr) as HboMaxAuthObj;
session.auth = {
accessToken: authObj.accessToken,
refreshToken: authObj.refreshToken,
expiresAt: authObj.accessExpiration,
accessToken: authObj.access_token,
refreshToken: authObj.refresh_token,
expiresAt: authObj.expires_on,
};
}

const deviceSerialNumber = window.localStorage.getItem(
'platform.PlatformSettings.singleton.serial'
);
const deviceSerialNumber = window.localStorage.getItem('deviceSerialNumber');
if (deviceSerialNumber) {
session.deviceSerialNumber = deviceSerialNumber;
}
Expand Down