Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,8 @@
# TIME_TO_KEEP_FILES=8 # Hours. Non-option when REMOVE_FILE_AFTER_RIGHT_DOWNLOAD=false

# File management
# MAX_CACHED_PER_USER=10
# MAX_CACHED_PER_USER=10

# Download format
# ONLY EDIT IF YOU KNOW WHAT YOU ARE DOING! THIS COULD BREAK COMPATIBILITY WITH YOUR DEVICE
# FORCE_ALL_DOWNLOADS_TO_H265=false # Forces all downloads into h265 improving file size
6 changes: 2 additions & 4 deletions src/app.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ export class AppController {
let jellyfinUrl = process.env.JELLYFIN_URL;

let finalUrl: string;

if (jellyfinUrl) {
jellyfinUrl = jellyfinUrl.replace(/\/$/, '');
// If JELLYFIN_URL is set, use it to replace the base of the incoming URL
Expand All @@ -55,7 +54,7 @@ export class AppController {
// If JELLYFIN_URL is not set, use the incoming URL as is
finalUrl = url;
}

const id = await this.appService.downloadAndCombine(
finalUrl,
fileExtension,
Expand Down Expand Up @@ -119,15 +118,14 @@ export class AppController {
}

const stat = fs.statSync(filePath);

res.setHeader('Content-Length', stat.size);
res.setHeader('Content-Type', 'video/mp4');
res.setHeader(
'Content-Disposition',
`attachment; filename=transcoded_${id}.mp4`,
);

const fileStream = fs.createReadStream(filePath);

this.logger.log(`Download started for ${filePath}`)

return new Promise((resolve, reject) => {
Expand Down
23 changes: 19 additions & 4 deletions src/app.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ export class AppService {
private maxCachedPerUser: number;
private cacheDir: string;
private immediateRemoval: boolean;

private forceAllDownloadsToH265: boolean;

constructor(
private logger: Logger,
private configService: ConfigService,
Expand All @@ -58,6 +59,21 @@ export class AppService {
'REMOVE_FILE_AFTER_RIGHT_DOWNLOAD',
true,
);
this.maxCachedPerUser = this.configService.get<number>(
'MAX_CACHED_PER_USER',
10,
);

this.immediateRemoval = this.configService.get<string>('REMOVE_FILE_AFTER_RIGHT_DOWNLOAD', 'false').toLowerCase() === 'true';

this.forceAllDownloadsToH265 = this.configService.get<string>('FORCE_ALL_DOWNLOADS_TO_H265', 'false').toLowerCase() === 'true';
}

urlEditor(url){
if (this.forceAllDownloadsToH265 === true){
url = url.replace(/VideoCodec=h264/g, "VideoCodec=h265");
}
return url
}

async downloadAndCombine(
Expand All @@ -70,10 +86,10 @@ export class AppService {
): Promise<string> {
const jobId = uuidv4();
const outputPath = path.join(this.cacheDir, `combined_${jobId}.mp4`);

this.logger.log(
`Queueing job ${jobId.padEnd(36)} | URL: ${(url.slice(0, 50) + '...').padEnd(53)} | Path: ${outputPath}`,
);
url = this.urlEditor(url)

this.activeJobs.push({
id: jobId,
Expand Down Expand Up @@ -407,7 +423,6 @@ export class AppService {
}

if (code === 0) {

job.status = 'completed';
job.progress = 100;
// Update the file size
Expand Down Expand Up @@ -449,7 +464,7 @@ export class AppService {
}
}


private async getVideoDuration(
inputUrl: string,
jobId: string,
Expand Down
Loading