forked from trakt-tools/universal-trakt-scrobbler
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Hotstar service (trakt-tools#212)
- Loading branch information
Showing
5 changed files
with
91 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
import { init } from '@service'; | ||
import '@/hotstar/HotstarParser'; | ||
|
||
void init('hotstar'); |