@prisma/client#Media TypeScript Examples
The following examples show how to use
@prisma/client#Media.
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 |
/**
* @desc this is a recursive function that handles the subtitles logic
* @param subs - the videos array to be scanned
*/
protected async getSubs(subs: (Video & { media: Media, episode: Episode | null })[]) {
if (this.OpenSubtitles) {
while (subs.length) {
await this.getSub(subs[0]);
await new Promise<void>(resolve => {
setTimeout(() => {
subs.shift();
resolve();
}, 3000)
})
}
}
}
Example #2
Source File: browseContext.ts From frames with Mozilla Public License 2.0 | 5 votes |
MediaContextAtom = atom<Pick<Media, 'id' | 'type' | 'backdrop' | 'logo' | 'name' | 'genre' | 'release'>[]>({
key: 'MediaContextAtom',
default: [],
})
Example #3
Source File: middleware.ts From frames with Mozilla Public License 2.0 | 5 votes |
/**
* @desc gets a file's location from the request
* @param location - file location
*/
public async getFileAndAndLocation(location: string) {
let res: {location: string, download: boolean, name: string} = {
location: '',
download: false,
name: ''
};
const { data, error } = await this.supabase
.from<(View & {video: Video})>('View')
.select('*,video:Video(*)')
.eq('auth', location)
.single();
if (!error && data) {
const { video } = data;
res = {
location: video.location,
download: false,
name: ''
}
} else {
const { data, error } = await this.supabase
.from<(Download & {view: (View & {episode: Episode, video: (Video & {media: Media})})})>('Download')
.select('*,view:View(*,episode:Episode(*),video:Video(*,media:Media!Video_mediaId_fkey(*)))')
.eq('location', location)
.single();
if (!error && data) {
if (data.view.episode) {
const { episode, video } = data.view;
const { media } = video;
const episodeInfo = await this.getEpisode(media.tmdbId, episode.seasonId, episode.episode);
res = {
location: video.location,
download: true,
name: media.name + (/^Episode \d+/i.test(episodeInfo?.name || 'Episode 0') ? ` Season ${episode.seasonId} - Episode ${episode.episode}` : ` S${episode.seasonId} - E${episode.episode}: ${episodeInfo?.name}`)
}
} else {
const { video } = data.view;
res = {
location: video.location,
download: true,
name: video.media.name
}
}
}
}
return res;
}
Example #4
Source File: scanner.ts From frames with Mozilla Public License 2.0 | 5 votes |
/**
* @desc does the actual scan for the subtitles of a specific video file
* @param video - the video file to be scanned
* @param auth - the authentication object
*/
public async getSub(video: (Video & { media: Media, episode: Episode | null }), auth?: string) {
let returnSubs: { language: string, url: string, label: string, lang: string }[] = [];
if (this.OpenSubtitles) {
const file = await this.drive?.getFile(video.location) || null;
if (file) {
let obj: any = null;
if (video.episode) {
const external = await this.tmdb?.getExternalId(video.media.tmdbId, MediaType.SHOW);
if (external) {
obj = {
season: video.episode.seasonId,
filesize: file.size,
filename: file.name,
episode: video.episode.episode,
imdbid: external.imdb_id
};
}
} else {
const external = await this.tmdb?.getExternalId(video.media.tmdbId, MediaType.MOVIE);
if (external) obj = {filesize: file.size, filename: file.name, imdbid: external.imdb_id};
}
if (obj) {
obj.extensions = ['srt', 'vtt'];
const keys = ['en', 'fr', 'de'];
const lang = ['english', 'french', 'german'];
const labels = ['English', 'Français', 'Deutsch'];
const subs: { [p: string]: string | null } | null = await this.OpenSubtitles.search(obj)
.then((temp: { [x: string]: { url: any; }; } | undefined) => {
if (temp) {
let item: { [key: string]: string } = {};
keys.forEach((value, pos) => {
item[lang[pos]] = temp[value] === undefined ? null : temp[value].url;
});
return item;
} else return null;
}).catch((error: any) => {
console.log(error)
return null;
})
if (subs) {
await this.prisma.video.update({where: {id: video.id}, data: subs});
if (auth)
returnSubs = keys.map((value, pos) => {
return {
language: this.capitalize(lang[pos]),
url: subs[lang[pos]] ? '/api/stream/subtitles?auth=' + auth + '&language=' + lang[pos] : '',
label: labels[pos],
lang: value
}
}).filter(x => x.url !== '');
}
}
}
}
return returnSubs;
}
Example #5
Source File: scanner.ts From frames with Mozilla Public License 2.0 | 5 votes |
/**
* @desc scans a new media item and attempts to add it to the database
* @param item - the show folder to scan
* @param type - the type of media to be scanned
* @param media - the media already in the database
* @param keepOld - whether to keep the old media or not
*/
public async scanMedia(item: drive_v3.Schema$File, type: MediaType, media: Media[], keepOld = true) {
let obj: { name: string, tmdbId: number, year: number };
let {backup, results} = await this.scanMediaHelper(item, type);
if (results.length === 1 || backup.length === 1) {
obj = backup.length ? backup[0] : results[0];
const existing = media.find(e => e.tmdbId === obj.tmdbId && e.type === type);
if (existing !== undefined) {
if (keepOld) {
await this.drive?.deleteFile(item.id!);
return;
}
const video = await this.prisma.folder.findFirst({where: {showId: existing.id}});
if (video) await this.checkAndDelete(video.location, item.id as string, this.moviesLocation === '' || this.showsLocation === '');
return;
}
const imageData = await this.tmdb?.getImagesForAutoScan(obj.tmdbId, obj.name || '', type, obj.year) || {
poster: '',
backdrop: '',
logo: ''
};
const res = await this.buildMediaObj(imageData, obj, type);
if (res) {
await this.addMedia(res.mediaData, res.castCrew, item.id as string);
return;
}
}
console.log(`${item.name} couldn't be added no media found`);
}
Example #6
Source File: browseContext.ts From frames with Mozilla Public License 2.0 | 4 votes |
useBrowseContext = (load = false) => {
const base = useBase();
const router = useRouter();
const [genres, setGenres] = useRecoilState(GenreContextAtom);
const [decade, setDecadeContext] = useRecoilState(DecadeContextAtom);
const [loading, setLoading] = useState(false);
const [media, setMedia] = useRecoilState(MediaContextAtom);
const mediaType = router.asPath.includes('movies') ? 'MOVIE' : 'SHOW';
const setDefaultGenresAndDecades = useSetRecoilState(GenreAndDecadeContextAtom);
const [page, setPage] = useState(1);
const fixGenreAndDecade = async (media: Pick<Media, 'id' | 'type' | 'backdrop' | 'logo' | 'name' | 'genre' | 'release'>[] | null) => {
if (media) {
let string: string = media.map(item => item.genre).join(' ');
let genres = string.replace(/ &|,/g, '').split(' ').map(genre => {
return {genre};
}).filter(item => item.genre !== '');
genres = base.sortArray(base.uniqueId(genres, 'genre'), 'genre', 'asc');
setDefaultGenresAndDecades(prev => ({
...prev,
genres: genres.map(item => item.genre),
}));
} else {
const data = await base.makeRequest<{ genres: string[], decades: string[] }>('/api/load/genresAndDecades', {mediaType: mediaType});
if (data)
setDefaultGenresAndDecades(data);
}
}
const fetchMedia = async () => {
if (load){
setLoading(true);
const media = await base.makeRequest<Pick<Media, 'id' | 'type' | 'backdrop' | 'logo' | 'name' | 'genre' | 'release'>[]>(`/api/media/browse?page=${1}`, {
genres,
decade,
mediaType
}, 'POST');
if (media) {
setMedia(media);
if (genres.length > 0 || decade !== '')
await fixGenreAndDecade(media);
else
await fixGenreAndDecade(null);
setPage(2);
}
setLoading(false);
}
};
const loadMore = async () => {
setLoading(true);
const newMedia = await base.makeRequest<Pick<Media, 'id' | 'type' | 'backdrop' | 'logo' | 'name' | 'genre' | 'release'>[]>(`/api/media/browse?page=${page}`, {
genres,
decade,
mediaType
}, 'POST');
if (newMedia) {
setMedia(prev => [...prev, ...newMedia]);
setPage(page + 1);
if (genres.length > 0 || decade !== '')
await fixGenreAndDecade([...media, ...newMedia]);
else
await fixGenreAndDecade(null);
}
setLoading(false);
}
const reset = () => {
setDefaultGenresAndDecades({
genres: [],
decades: [],
});
setDecadeContext('');
setGenres([]);
setPage(1);
setMedia([]);
}
useEffect(() => {
fetchMedia();
}, [genres, decade, mediaType]);
const handleScroll = async (event: any) => {
const bottom = event.target.scrollHeight - event.target.scrollTop - 3000 <= event.target.clientHeight;
if (bottom && !loading)
await loadMore();
}
return {handleScroll, loading, reset};
}
Example #7
Source File: middleware.ts From frames with Mozilla Public License 2.0 | 4 votes |
/**
* @desc creates the SEO data for the page
* @param type - type of the page
* @param value - value of the page
*/
public async getMetaTags(type: string, value: string) {
if (type === 'movie' || type === 'show') {
const {data} = await this.supabase
.from<Modify<Media, {release: string}>>('Media')
.select('*')
.eq('type', type.toUpperCase())
.ilike('name', `*${value}*`)
if (data) {
const response = data.map(item => {
const year = new Date(item.release).getFullYear();
const drift = item.name.Levenshtein(value);
return {...item, year, drift};
})
const info = this.sortArray(response, ['drift', 'year'], ['asc', 'desc'])[0];
if (info)
return {
overview: info.overview,
name: info.name,
poster: info.poster
}
}
}
if (type === 'watch' || type === 'frame' || type === 'room') {
if (type === 'room') {
const {data} = await this.supabase
.from<Room>('Room')
.select('*')
.eq('roomKey', value)
.single();
value = data ? data.auth: value;
}
if (type === 'frame') {
const {data} = await this.supabase
.from<Frame>('Frame')
.select('*')
.eq('cypher', value)
.single();
value = data ? data.auth: value;
}
const {data} = await this.supabase
.from<(View & {episode: Episode | null, video: (Video & {media: Media})})>('View')
.select('*, episode:Episode(*), video:Video(*, media:Media!Video_mediaId_fkey(*))')
.eq('auth', value)
.single();
if (data) {
const {episode, video} = data;
let {name, overview, poster, tmdbId} = video.media;
if (episode) {
const episodeInfo = await this.getEpisode(tmdbId, episode.seasonId, episode.episode);
name = /^Episode \d+/i.test(episodeInfo?.name || 'Episode') ? `${name}: S${episode.seasonId}, E${episode.episode}` : `S${episode.seasonId}, E${episode.episode}: ${episodeInfo?.name}`;
overview = episodeInfo?.overview || overview;
}
return {
overview,
name,
poster
}
}
}
if (type === 'person') {
const person = await this.findPerson(value);
if (person)
return {
overview: `See all media produced by ${person.name} available on Frames`,
name: person.name,
poster: 'https://image.tmdb.org/t/p/original' + person.profile_path
}
}
/*if (type === 'collection') {
const {data} = await this.supabase
.from('Media')
.select('name, poster, overview, cName:collection->>name')
.ilike('cName', `*${value}*`)
.single();
console.log(data);
}*/
return {
overview: 'Frames is a streaming service that offers a wide variety of TV shows, movies, anime, documentaries, and more on thousands straight to your browser',
name: 'Frames - Watch FREE TV Shows and Movies Online',
poster: '/meta.png'
}
}