mirror of
https://github.com/sakaljurgis/kodi-api-server.git
synced 2026-07-09 04:47:41 +00:00
all files: add titles, seasons and files list
This commit is contained in:
@@ -22,18 +22,19 @@ export class AllFilesController {
|
||||
return this.allFilesService.getListOfTitles(TitleTypeEnum.movie);
|
||||
}
|
||||
|
||||
@Get('play')
|
||||
play() {
|
||||
return { will: 'return a playable stream' };
|
||||
@Get('play/:fileId')
|
||||
play(@Param('fileId') fileId: string) {
|
||||
return { will: 'return a playable stream of ' + fileId };
|
||||
}
|
||||
|
||||
@Get(':titleId/:seasonId?')
|
||||
getTitle(
|
||||
@Param('titleId') titleId: number,
|
||||
@Param('seasonId') seasonId: number,
|
||||
) {
|
||||
return {
|
||||
will: 'show title videos list title ' + titleId + ', season ' + seasonId,
|
||||
};
|
||||
@Param('titleId') titleId: string, //actually a number, how to cast?
|
||||
@Param('seasonId') seasonId: string, //actually a number, how to cast?
|
||||
): Promise<ApiResponse> {
|
||||
return this.allFilesService.loadTitle(
|
||||
parseInt(titleId),
|
||||
parseInt(seasonId),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -48,9 +48,81 @@ export class AllFilesService {
|
||||
.createItem()
|
||||
.setLabel(entity.title)
|
||||
.setToFolder()
|
||||
.setPlot(entity.files.length + ' files');
|
||||
.setPlot(entity.files.length + ' files')
|
||||
.setPath('all/' + entity.id);
|
||||
});
|
||||
|
||||
return response;
|
||||
}
|
||||
|
||||
async loadTitle(titleId: number, seasonId: number): Promise<ApiResponse> {
|
||||
const titleEntity = await this.titleRepository.findOne({
|
||||
relations: { files: true },
|
||||
where: { id: titleId },
|
||||
});
|
||||
|
||||
if (titleEntity === null) {
|
||||
return this.koiApiResponseFactory
|
||||
.createApiResponse()
|
||||
.setTitle('Not found ' + titleId);
|
||||
}
|
||||
|
||||
if (titleEntity.type === TitleTypeEnum.movie) {
|
||||
return this.buildFilesResponse(titleEntity.title, titleEntity.files);
|
||||
}
|
||||
|
||||
if (seasonId) {
|
||||
return this.buildFilesResponse(
|
||||
titleEntity.title,
|
||||
titleEntity.files.filter(
|
||||
(fileEntity) => fileEntity.season === seasonId,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
return this.buildSeasonsResponse(titleEntity);
|
||||
}
|
||||
|
||||
private buildFilesResponse(
|
||||
title: string,
|
||||
fileEntities: Array<FileEntity>,
|
||||
): ApiResponse {
|
||||
const apiResponse = this.koiApiResponseFactory.createApiResponse();
|
||||
apiResponse.setTitle(title);
|
||||
for (const fileEntity of fileEntities) {
|
||||
apiResponse
|
||||
.createItem()
|
||||
.setLabel(fileEntity.fileName)
|
||||
.setPath('/api?path=all/play/' + fileEntity.id)
|
||||
.setToPlayable()
|
||||
.setPlot('Size ' + fileEntity.size)
|
||||
.setSize(fileEntity.size)
|
||||
.setDuration(fileEntity.duration);
|
||||
}
|
||||
|
||||
return apiResponse;
|
||||
}
|
||||
|
||||
private buildSeasonsResponse(titleEntity: TitleEntity): ApiResponse {
|
||||
const apiResponse = this.koiApiResponseFactory.createApiResponse();
|
||||
apiResponse.setTitle(titleEntity.title);
|
||||
|
||||
//todo - add num files count
|
||||
const seasons = [];
|
||||
for (const fileEntity of titleEntity.files) {
|
||||
if (seasons.indexOf(fileEntity.season) === -1) {
|
||||
seasons.push(fileEntity.season);
|
||||
}
|
||||
}
|
||||
|
||||
for (const season of seasons) {
|
||||
apiResponse
|
||||
.createItem()
|
||||
.setLabel(season + ' Sezonas')
|
||||
.setToFolder()
|
||||
.setPath(`all/${titleEntity.id}/${season}`);
|
||||
}
|
||||
|
||||
return apiResponse;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user