configurable audio formats
This commit is contained in:
@@ -30,7 +30,9 @@
|
||||
"@nestjs/serve-static": "^4.0.2",
|
||||
"@nestjs/typeorm": "^10.0.2",
|
||||
"@nestjs/websockets": "^10.3.10",
|
||||
"@types/fluent-ffmpeg": "^2.1.24",
|
||||
"@types/yt-search": "^2.10.3",
|
||||
"fluent-ffmpeg": "^2.1.3",
|
||||
"isomorphic-unfetch": "^4.0.2",
|
||||
"reflect-metadata": "^0.2.0",
|
||||
"rxjs": "^7.8.1",
|
||||
|
||||
@@ -26,9 +26,10 @@ export class TrackController {
|
||||
@Get('download/:id')
|
||||
async getFile(@Res({ passthrough: true }) res: Response, @Param('id') id: number): Promise<StreamableFile> {
|
||||
const track = await this.service.findOne(id);
|
||||
const file = createReadStream(resolve(__dirname, '..', this.configService.get<string>('DOWNLOADS'), `${track.artist} - ${track.song}.mp3`));
|
||||
res.set({'Content-Disposition': `attachment; filename="${track.artist} - ${track.song}.mp3"`,});
|
||||
return new StreamableFile(file);
|
||||
const fileName = `${track.artist} - ${track.song}.${this.configService.get<string>('FORMAT')}`;
|
||||
const filePath = createReadStream(resolve(__dirname, '..', this.configService.get<string>('DOWNLOADS'), fileName));
|
||||
res.set({'Content-Disposition': `attachment; filename="${fileName}`});
|
||||
return new StreamableFile(filePath);
|
||||
}
|
||||
|
||||
@Delete(':id')
|
||||
|
||||
@@ -13,6 +13,7 @@ import {ConfigService} from "@nestjs/config";
|
||||
import {resolve} from "path";
|
||||
import {WebSocketGateway, WebSocketServer} from "@nestjs/websockets";
|
||||
import {Server} from "socket.io";
|
||||
import * as ffmpeg from 'fluent-ffmpeg';
|
||||
|
||||
@WebSocketGateway()
|
||||
@Injectable()
|
||||
@@ -102,13 +103,19 @@ export class TrackService {
|
||||
}
|
||||
|
||||
private youtubeDownload(track: TrackEntity): Promise<void> {
|
||||
return new Promise((res, reject) =>
|
||||
ytdl(track.youtubeUrl, {quality: "highestaudio", filter: "audioonly"})
|
||||
.on('error', (err) => reject(err)).pipe(
|
||||
fs.createWriteStream(resolve(__dirname, '..', this.configService.get<string>('DOWNLOADS'), `${track.artist} - ${track.song.replace('/', '')}.mp3`))
|
||||
.on('finish', () => res())
|
||||
.on('error', (err) => reject(err))
|
||||
)
|
||||
);
|
||||
return new Promise((res, reject) => {
|
||||
const audio = ytdl(track.youtubeUrl, {quality: "highestaudio", filter: "audioonly"})
|
||||
.on('error', (err) => reject(err));
|
||||
ffmpeg(audio).format(this.configService.get<string>('FORMAT'))
|
||||
.on('error', (err) => reject(err))
|
||||
.pipe(
|
||||
fs.createWriteStream(
|
||||
resolve(
|
||||
__dirname, '..', this.configService.get<string>('DOWNLOADS'),
|
||||
`${track.artist} - ${track.song.replace('/', '')}.${this.configService.get<string>('FORMAT')}`
|
||||
)
|
||||
).on('finish', () => res()).on('error', (err) => reject(err))
|
||||
);
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user