Skip to content

Commit

Permalink
Merge pull request #67 from ShaquilleSadiq/main
Browse files Browse the repository at this point in the history
  • Loading branch information
joshunrau authored Aug 25, 2024
2 parents 72c989e + d666387 commit 8473738
Show file tree
Hide file tree
Showing 7 changed files with 1,461 additions and 2,168 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ Options:
-o --output-dir <path> path to output directory
-n --no-get-tags skip extracting/applying id3 tags
-v --verify-tags verify id3 tags fetched from itunes
-s --silent-mode skip console output
-h, --help display help for command
```

Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,11 @@
"test:coverage": "vitest --coverage"
},
"dependencies": {
"@distube/ytdl-core": "^4.14.4",
"axios": "^1.7.2",
"commander": "^12.1.0",
"ffmpeg-static": "^5.2.0",
"node-id3": "^0.2.6",
"ytdl-core": "4.11.5"
"node-id3": "^0.2.6"
},
"devDependencies": {
"@commitlint/cli": "^19.3.0",
Expand Down
3,602 changes: 1,443 additions & 2,159 deletions pnpm-lock.yaml

Large diffs are not rendered by default.

17 changes: 12 additions & 5 deletions src/Downloader.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import os from 'os';
import path from 'path';

import ytdl from '@distube/ytdl-core';
import type { videoInfo as VideoInfo } from '@distube/ytdl-core';
import NodeID3 from 'node-id3';
import ytdl from 'ytdl-core';
import type { videoInfo as VideoInfo } from 'ytdl-core';

import { FormatConverter } from './FormatConverter';
import { SongTagsSearch } from './SongTagsSearch';
Expand All @@ -12,6 +12,7 @@ import { YtdlMp3Error, isDirectory, removeParenthesizedText } from './utils';
export type DownloaderOptions = {
getTags?: boolean;
outputDir?: string;
silentMode?: boolean;
verifyTags?: boolean;
};

Expand All @@ -20,11 +21,13 @@ export class Downloader {

getTags: boolean;
outputDir: string;
silentMode: boolean;
verifyTags: boolean;

constructor({ getTags, outputDir, verifyTags }: DownloaderOptions) {
constructor({ getTags, outputDir, silentMode, verifyTags }: DownloaderOptions) {
this.outputDir = outputDir ?? Downloader.defaultDownloadsDir;
this.getTags = Boolean(getTags);
this.silentMode = Boolean(silentMode);
this.verifyTags = Boolean(verifyTags);
}

Expand All @@ -42,15 +45,19 @@ export class Downloader {
const songTagsSearch = new SongTagsSearch(videoInfo.videoDetails);

const outputFile = this.getOutputFile(videoInfo.videoDetails.title);
const videoData = await this.downloadVideo(videoInfo);
const videoData = await this.downloadVideo(videoInfo).catch((error) => {
throw new YtdlMp3Error('Failed to download video', {
cause: error
});
});

formatConverter.videoToAudio(videoData, outputFile);
if (this.getTags) {
const songTags = await songTagsSearch.search(this.verifyTags);
NodeID3.write(songTags, outputFile);
}

console.log(`Done! Output file: ${outputFile}`);
if (!this.silentMode) console.log(`Done! Output file: ${outputFile}`);
return outputFile;
}

Expand Down
2 changes: 1 addition & 1 deletion src/SongTagsSearch.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { MoreVideoDetails } from '@distube/ytdl-core';
import axios, { type AxiosError } from 'axios';
import type { MoreVideoDetails } from 'ytdl-core';

import { YtdlMp3Error, removeParenthesizedText, userInput } from './utils';

Expand Down
2 changes: 1 addition & 1 deletion src/__tests__/Downloader.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ import fs from 'fs';
import path from 'path';
import { PassThrough } from 'stream';

import ytdl from '@distube/ytdl-core';
import NodeID3 from 'node-id3';
import { afterAll, beforeAll, beforeEach, describe, expect, it, vi } from 'vitest';
import type { Mock } from 'vitest';
import ytdl from 'ytdl-core';

import { Downloader } from '../Downloader';
import { FormatConverter } from '../FormatConverter';
Expand Down
1 change: 1 addition & 0 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export async function main() {
program.option('-o --output-dir <path>', 'path to output directory', Downloader.defaultDownloadsDir);
program.option('-n --no-get-tags', 'skip extracting/applying id3 tags');
program.option('-v --verify-tags', 'verify id3 tags fetched from itunes');
program.option('-s --silent-mode', 'skip console output');
program.option('--verbose', 'enable verbose mode');
program.parse();

Expand Down

0 comments on commit 8473738

Please sign in to comment.