mirror of
https://github.com/sakaljurgis/kodi-api-server.git
synced 2026-07-08 20:37: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);
|
return this.allFilesService.getListOfTitles(TitleTypeEnum.movie);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Get('play')
|
@Get('play/:fileId')
|
||||||
play() {
|
play(@Param('fileId') fileId: string) {
|
||||||
return { will: 'return a playable stream' };
|
return { will: 'return a playable stream of ' + fileId };
|
||||||
}
|
}
|
||||||
|
|
||||||
@Get(':titleId/:seasonId?')
|
@Get(':titleId/:seasonId?')
|
||||||
getTitle(
|
getTitle(
|
||||||
@Param('titleId') titleId: number,
|
@Param('titleId') titleId: string, //actually a number, how to cast?
|
||||||
@Param('seasonId') seasonId: number,
|
@Param('seasonId') seasonId: string, //actually a number, how to cast?
|
||||||
) {
|
): Promise<ApiResponse> {
|
||||||
return {
|
return this.allFilesService.loadTitle(
|
||||||
will: 'show title videos list title ' + titleId + ', season ' + seasonId,
|
parseInt(titleId),
|
||||||
};
|
parseInt(seasonId),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -48,9 +48,81 @@ export class AllFilesService {
|
|||||||
.createItem()
|
.createItem()
|
||||||
.setLabel(entity.title)
|
.setLabel(entity.title)
|
||||||
.setToFolder()
|
.setToFolder()
|
||||||
.setPlot(entity.files.length + ' files');
|
.setPlot(entity.files.length + ' files')
|
||||||
|
.setPath('all/' + entity.id);
|
||||||
});
|
});
|
||||||
|
|
||||||
return response;
|
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