-
-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement program_external_id table (#468)
Motiviation: Adding this table is a bit of a future-proofing mechanism. We want to decouple the notion of a 'program' from its external references. Currently, the only external reference Tunarr knows of is 'plex'. Eventually, we will add different sources for programming. In theory, a program could exist in multiple sources. And not only in multiple media sources, but on other sites that contain more metadata, such as IMDB and TMDB. The new DB table generalizes Program to have a 1:M relationship with external references. Additionally, this allows us to maintain stable and _unstable_ IDs for various sources (ex. plex rating key) without losing metadata sourcing for a Program. Changes: * Migration to add `program_external_id` table * Backfill fixer task to fill in details from existing programs in the DB * Changes to program DB save path to save to new table and to start saving Plex GUID * Self-heal when Plex rating key changes. This code is triggered when starting a stream for an item. If we have a Plex GUID available, we will attempt to heal the item in the DB and start the stream * Use the new table in the stream item calculator TODO: * Start saving Plex GUID for program_groupings, which have a separate external key table * Start saving other external IDs for programs, such as IMDB ID and TMDB ID
- Loading branch information
1 parent
087b4e6
commit 6953e60
Showing
24 changed files
with
927 additions
and
110 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
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,18 @@ | ||
import { enumKeys } from '../../util/enumUtil.js'; | ||
|
||
export enum ProgramExternalIdType { | ||
PLEX = 'plex', | ||
PLEX_GUID = 'plex-guid', | ||
} | ||
|
||
export function programExternalIdTypeFromString( | ||
str: string, | ||
): ProgramExternalIdType | undefined { | ||
for (const key of enumKeys(ProgramExternalIdType)) { | ||
const value = ProgramExternalIdType[key]; | ||
if (key.toLowerCase() === str) { | ||
return value; | ||
} | ||
} | ||
return; | ||
} |
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
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,51 @@ | ||
import { | ||
Entity, | ||
Enum, | ||
ManyToOne, | ||
Property, | ||
Unique, | ||
type Rel, | ||
} from '@mikro-orm/core'; | ||
import { ProgramExternalIdType } from '../custom_types/ProgramExternalIdType.js'; | ||
import { BaseEntity } from './BaseEntity.js'; | ||
import { Program } from './Program.js'; | ||
|
||
/** | ||
* References to external sources for a {@link Program} | ||
* | ||
* There are two flavors of IDs: | ||
* 1. Source-specific. These are unique in 3 parts: [type, source_id, id] | ||
* e.x. a program's ID specific to a user's Plex server | ||
* 2. Source-agnostic. These are unique in 2 parts: [type, id] | ||
* e.x. a program's ID on IMDB | ||
*/ | ||
@Entity() | ||
@Unique({ properties: ['uuid', 'sourceType'] }) | ||
export class ProgramExternalId extends BaseEntity { | ||
@Enum(() => ProgramExternalIdType) | ||
sourceType!: ProgramExternalIdType; | ||
|
||
// Mappings: | ||
// - Plex = server name | ||
@Property({ nullable: true }) | ||
externalSourceId?: string; | ||
|
||
// Mappings: | ||
// - Plex = ratingKey | ||
@Property() | ||
externalKey!: string; | ||
|
||
// Mappings: | ||
// - Plex = Media.Part.key -- how to access the file via Plex server | ||
@Property({ nullable: true }) | ||
externalFilePath?: string; | ||
|
||
// Mappings: | ||
// - Plex = Media.Part.file -- the file path _on_ the plex server | ||
// used in direct streaming mode | ||
@Property({ nullable: true }) | ||
directFilePath?: string; | ||
|
||
@ManyToOne(() => Program) | ||
program!: Rel<Program>; | ||
} |
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
Oops, something went wrong.