Skip to content

Commit

Permalink
Add Hotstar service (trakt-tools#212)
Browse files Browse the repository at this point in the history
  • Loading branch information
fikimaul authored Nov 7, 2022
1 parent 753aea9 commit e448d14
Show file tree
Hide file tree
Showing 5 changed files with 91 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ If you want to scrobble / sync from Netflix, this is the only Trakt.tv [plugin](
| GoPlay BE | ✔️ || - |
| HBO Go | ✔️ || - |
| HBO Max | ✔️ | ✔️ | - |
| Hotstar | ✔️ || - |
| Kijk.nl | ✔️ || - |
| Netflix | ✔️ | ✔️ | - |
| NRK | ✔️ | ✔️ | - |
Expand Down
11 changes: 11 additions & 0 deletions src/services/hotstar/HotstarApi.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { ServiceApi } from '@apis/ServiceApi';
import { Item } from '@models/Item';
import { HotstarService } from '@/hotstar/HotstarService';

class _HotstarApi extends ServiceApi {
constructor() {
super(HotstarService.id);
}
}

export const HotstarApi = new _HotstarApi();
64 changes: 64 additions & 0 deletions src/services/hotstar/HotstarParser.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
import { ScrobbleParser } from '@common/ScrobbleParser';
import { HotstarApi } from '@/hotstar/HotstarApi';
import { EpisodeItem, MovieItem } from '@models/Item';

class _HotstarParser extends ScrobbleParser {
constructor() {
super(HotstarApi, {
watchingUrlRegex: /\/(?:movies|tv)\/(?<id>.+)/,
});
}

parseItemFromDom() {
const serviceId = this.api.id;
const id = this.parseItemIdFromUrl();
const titleElement = document.querySelector('.primary-title');

if (!titleElement) {
return null;
}

const title = titleElement?.textContent ?? '';
const seasonEpisodeElement = document.querySelector(
'.show-title .meta-data-holder'
)?.firstChild;
const subTitleElement = document.querySelector('.show-title .meta-data-holder')?.lastChild;

let seasonId: string | null = null;
let episodeId: string | null = null;
const subTitle = subTitleElement?.textContent ?? '';

const matches = /(?<seasonId>[\d]+)\s.(?<episodeId>[\d]+)/.exec(
seasonEpisodeElement?.textContent ?? ''
);

if (matches?.groups) {
({ seasonId, episodeId } = matches.groups);
}

if (seasonId) {
const season = parseInt(seasonId ?? '') || 0;
const number = parseInt(episodeId ?? '') || 0;

return new EpisodeItem({
serviceId,
id,
title: subTitle,
season,
number,
show: {
serviceId,
title,
},
});
}

return new MovieItem({
serviceId,
id,
title,
});
}
}

export const HotstarParser = new _HotstarParser();
11 changes: 11 additions & 0 deletions src/services/hotstar/HotstarService.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { Service } from '@models/Service';

export const HotstarService = new Service({
id: 'hotstar',
name: 'Hotstar',
homePage: 'https://www.hotstar.com',
hostPatterns: ['*://*.www.hotstar.com/*'],
hasScrobbler: true,
hasSync: false,
hasAutoSync: false,
});
4 changes: 4 additions & 0 deletions src/services/hotstar/hotstar.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import { init } from '@service';
import '@/hotstar/HotstarParser';

void init('hotstar');

0 comments on commit e448d14

Please sign in to comment.