@prisma/client#CastType TypeScript Examples
The following examples show how to use
@prisma/client#CastType.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: scanner.ts From frames with Mozilla Public License 2.0 | 6 votes |
/**
* @description adds a successful scan to the database
* @param med - the media to add
* @param casts - the cast for the media to be added to the castCrew table
* @param location - the location of the media
*/
private async addMedia(med: Med, casts: { job?: string, character?: string, name: string, tmdbId: number, type: CastType }[], location: string) {
try {
const media = await this.prisma.media.upsert({
where: {tmdbId_type: {tmdbId: med.tmdbId, type: med.type}}, create: {
...med, created: new Date(), updated: new Date()
}, update: {...med, updated: new Date()}
});
media.type === MediaType.MOVIE ? await this.prisma.video.upsert({
where: {location},
create: {english: null, french: null, german: null, location, mediaId: media.id},
update: {}
}) : await this.prisma.folder.upsert({
where: {location}, create: {location, showId: media.id}, update: {}
});
await this.prisma.castCrew.deleteMany({where: {mediaId: media.id}});
const data = casts.map(cast => ({...cast, mediaId: media.id}));
await this.prisma.castCrew.createMany({data});
if (media.type === MediaType.SHOW) await this.prisma.folder.deleteMany({where: {AND: [{showId: media.id}, {NOT: {location}}]}});
if (media.type === MediaType.SHOW)
await this.scanShow(media.id, true, true);
} catch (e) {
console.log(e);
}
}
Example #2
Source File: tmdb.ts From frames with Mozilla Public License 2.0 | 6 votes |
/**
* @desc gets the cast for a TMDB entry using it's TMDB id
* @param media - media to get the cast from
*/
public getCast(media: tmdbMedia) {
const credits = media.credits;
const cast = credits.cast;
const casts: { job?: string, character?: string, name: string, tmdbId: number, type: CastType }[] = cast.map((cast) => {
return {
type: CastType.ACTOR, character: cast.character, name: cast.name, tmdbId: cast.id
};
}).slice(0, 16);
let crew: { job?: string, character?: string, name: string, tmdbId: number, type: CastType }[] = credits.crew.map((crew) => {
return {
type: crew.job === 'Director' ? CastType.DIRECTOR : /^Writer|Story|Screenplay$/i.test(crew.job) ? CastType.WRITER : CastType.PRODUCER,
job: crew.job, name: crew.name, tmdbId: crew.id
};
});
crew = this.uniqueId(crew.filter(crew => !(crew.type === CastType.PRODUCER && crew.job !== 'Executive Producer')), ['name', 'type']);
return casts.concat(crew);
}
Example #3
Source File: media.ts From frames with Mozilla Public License 2.0 | 5 votes |
/**
* @desc gets the details of a specific person in the castCrew table of the database
* @param id - the id of the person to query the database for
*/
public async getPerson(id: number): Promise<PersonInterface | null> {
const person = await this.tmdb?.getPerson(id);
if (person) {
const data = await this.prisma.castCrew.findMany({
where: {tmdbId: id}, include: {
media: {
select: {
id: true, name: true, type: true, poster: true, background: true, release: true
}
}
},
});
const directed = data.filter(item => item.type === CastType.DIRECTOR);
const cast = data.filter(item => item.type === CastType.ACTOR);
const produced = data.filter(item => item.type === CastType.PRODUCER);
const wrote = data.filter(item => item.type === CastType.WRITER);
const directedMedia = this.sortArray(this.uniqueId(directed.map(item => item.media), 'id'), 'release', 'desc').map(e => {
const {poster, type, id, name, background} = e;
return {poster, type, id, name, background};
});
const castMedia = this.sortArray(this.uniqueId(cast.map(item => item.media), 'id'), 'release', 'desc').map(e => {
const {poster, type, id, name, background} = e;
return {poster, type, id, name, background};
});
const producedMedia = this.sortArray(this.uniqueId(produced.map(item => item.media), 'id'), 'release', 'desc').map(e => {
const {poster, type, id, name, background} = e;
return {poster, type, id, name, background};
});
const writtenMedia = this.sortArray(this.uniqueId(wrote.map(item => item.media), 'id'), 'release', 'desc').map(e => {
const {poster, type, id, name, background} = e;
return {poster, type, id, name, background};
});
return {
images: data.map(item => item.media).map(item => item.poster),
id,
name: person.name || '',
directedMedia,
castMedia,
producedMedia,
writtenMedia,
overview: person.biography,
photo: 'https://image.tmdb.org/t/p/original' + person.profile_path
}
}
return null;
}
Example #4
Source File: media.ts From frames with Mozilla Public License 2.0 | 5 votes |
/**
* @desc gets related media based on user activity and the cast's name
* @param userId - the id of the user to query the database for
*/
private async getCastNameRecommend(userId: string) {
const response = await this.baseRecommend(userId);
if (response) {
const {seen, ratings, suggestions, watched} = response;
const seenCastCrews = this.sortArray(this.countAppearances(seen.map(e => e.castCrews.filter(x => x.type === CastType.ACTOR || x.type === CastType.DIRECTOR)), 'count', 'tmdbId'), 'count', 'desc');
const ratingsCastCrews = this.sortArray(this.countAppearances(ratings.map(e => e.castCrews.filter(x => x.type === CastType.ACTOR || x.type === CastType.DIRECTOR)), 'count', 'tmdbId'), 'count', 'desc');
const suggestionsCastCrews = this.sortArray(this.countAppearances(suggestions.map(e => e.castCrews.filter(x => x.type === CastType.ACTOR || x.type === CastType.DIRECTOR)), 'count', 'tmdbId'), 'count', 'desc');
const watchedCastCrews = this.sortArray(this.countAppearances(watched.map(e => e.castCrews.filter(x => x.type === CastType.ACTOR || x.type === CastType.DIRECTOR)), 'count', 'tmdbId'), 'count', 'desc');
let med = this.countAppearances([seenCastCrews, ratingsCastCrews, suggestionsCastCrews, watchedCastCrews], 'count', 'id');
const counts = this.sortArray(med, 'count', 'desc');
if (counts.length > 10) {
const castCrew = counts[Math.floor(Math.random() * 10)];
const data = await this.prisma.media.findMany({
where: {
castCrews: {
some: {
tmdbId: castCrew.tmdbId
}
}
}, select: {
id: true, type: true, poster: true, background: true, name: true
}, orderBy: {
vote_average: 'desc'
}
});
return {
data: this.randomise(data, 12, 0),
display: `see more media ${castCrew.type === CastType.DIRECTOR ? 'directed by' : 'starring'} ${castCrew.name.toLowerCase()}`,
type: 'BASIC'
};
}
}
return {data: [], display: 'none', type: 'basic'};
}
Example #5
Source File: media.ts From frames with Mozilla Public License 2.0 | 5 votes |
/**
* @desc gets related media based on user activity and the cast's character
* @param userId - the id of the user to query the database for
*/
private async getCastCharRecommend(userId: string) {
const response = await this.baseRecommend(userId);
if (response) {
const {seen, ratings, suggestions, watched} = response;
const seenCastCrews = seen.map(e => e.castCrews.filter(a => a.type === CastType.ACTOR && a.character && !/Self|\(\w+\)|^\w+$/i.test(a.character!)));
const ratingsCastCrews = ratings.map(e => e.castCrews.filter(a => a.type === CastType.ACTOR && a.character && !/Self|\(\w+\)|^\w+$/i.test(a.character!)));
const suggestionsCastCrews = suggestions.map(e => e.castCrews.filter(a => a.type === CastType.ACTOR && a.character && !/Self|\(\w+\)|^\w+$/i.test(a.character!)));
const watchedCastCrews = watched.map(e => e.castCrews.filter(a => a.type === CastType.ACTOR && a.character && !/Self|\(\w+\)|^\w+$/i.test(a.character!)));
const seenCount = this.countAppearances(seenCastCrews, 'count', "character");
const ratingsCount = this.countAppearances(ratingsCastCrews, 'count', "character");
const suggestionsCount = this.countAppearances(suggestionsCastCrews, 'count', "character");
const watchedCount = this.countAppearances(watchedCastCrews, 'count', "character");
const med = this.countAppearances([seenCount, ratingsCount, suggestionsCount, watchedCount], 'count', "character");
const counts = this.sortArray(med, 'count', 'desc');
if (counts.length > 10) {
const character = counts[Math.floor(Math.random() * 10)].character;
const data = await this.prisma.media.findMany({
where: {
castCrews: {
some: {
character: {contains: character!, mode: "insensitive"}
}
}
}, select: {
id: true, type: true, poster: true, background: true, name: true
}, orderBy: {
vote_average: 'desc'
}
});
return {
data: this.randomise(data, 12, 0),
display: `more media portraying ${character!.toLowerCase()}`,
type: 'BASIC'
};
}
return {data: [], display: 'none', type: 'basic'};
}
}
Example #6
Source File: media.ts From frames with Mozilla Public License 2.0 | 4 votes |
/**
* @desc gets the details for a specific media
* @param id - the id of the Media to get
* @param userId - the id of the user to get the details for
*/
public async getMedia(id: number, userId: string): Promise<SpringMedia | null> {
const media = await this.prisma.media.findFirst({
where: {id}, include: {castCrews: true, episodes: {distinct: ['seasonId']}}
});
if (media) {
const {castCrews, production, episodes, poster, created, updated, collection, release, ...rest} = media;
let collectionIds: any[] = [];
const releaseDate = release?.toUTCString().substr(8, 8) || 'N/A';
const cast = castCrews.filter(e => e.type === CastType.ACTOR).map(e => {
const {name, type, character, job} = e;
return {id: e.tmdbId, name, type, character, job};
});
const producers = castCrews.filter(e => e.type === CastType.PRODUCER).map(e => {
const {name, type, character, job} = e;
return {id: e.tmdbId, name, type, character, job};
});
const directors = castCrews.filter(e => e.type === CastType.DIRECTOR).map(e => {
const {name, type, character, job} = e;
return {id: e.tmdbId, name, type, character, job};
});
const writers = castCrews.filter(e => e.type === CastType.WRITER).map(e => {
const {name, type, character, job} = e;
return {id: e.tmdbId, name, type, character, job};
});
if (collection) {
const col = collection as any as { id: number };
collectionIds = await this.prisma.media.findMany({
where: {
AND: [{
collection: {
path: ['id'], equals: col.id
}
}, {NOT: {id: id}}]
}, select: {
id: true, type: true, name: true, background: true, poster: true,
}, orderBy: {release: 'asc'}
});
}
const season = this.sortArray(episodes, 'seasonId', 'asc');
const sections = season.length ? season.length === 1 && season[0].seasonId === 1 ? ['Episodes'] : ['Seasons'] : [];
let seasons: SpringEpisode[] = sections[0] === 'Episodes' ? await this.getSeason(media.id, 1, userId) : [];
seasons = sections[0] !== 'Episodes' ? season.map(e => ({
id: e.seasonId,
season: e.seasonId,
episode: 0,
name: `Season ${e.seasonId}`,
type: 'SEASON',
backdrop: null,
overview: null,
show: {
id: media.id,
name: media.name,
overview: media.overview,
backdrop: media.backdrop,
logo: media.logo,
type: media.type,
poster: media.poster,
background: media.background
}
})) : seasons;
const prod = production as { name: string, id: string }[];
const coll = collection as { name: string, id: number, poster: string } | undefined;
const recon = await this.tmdb?.getRecommendations(media.tmdbId, media.type, 2) || [];
const tmdbIds = recon.map(e => e.id).filter(e => e !== media.tmdbId);
let recommendations = await this.prisma.media.findMany({
where: {AND: [{tmdbId: {in: tmdbIds}}, {type: media.type}]},
select: {id: true, poster: true, name: true, type: true, background: true}
});
sections.push(recommendations.length ? 'More like this' : 'Surprise me!');
sections.push('Details');
recommendations = recommendations.length ? recommendations : this.randomise(await this.prisma.media.findMany({
select: {
id: true, poster: true, name: true, type: true, background: true
}, where: {type: media.type}
}), 20, media.id);
recommendations = this.uniqueId(collectionIds.concat(recommendations), 'id');
return {
...rest,
cast,
producers,
directors,
writers,
sections,
recommendations,
poster,
seasons,
production: prod,
collection: coll,
release: releaseDate
};
}
return null;
}