Skip to content

Commit

Permalink
Merge pull request #243 from phyzical/feature/add-filetype-support
Browse files Browse the repository at this point in the history
Feature/add filetype support
  • Loading branch information
phyzical authored May 8, 2024
2 parents f766951 + 0f5305b commit 458c7fb
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 2 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ spotifydl https://open.spotify.com/track/xyz
| --v | --version | returns current version |
| --h | --help | outputs help text |
| --dl | --download-lyrics | enables downloading of lyrics |
| --oft | --output-file-type | choose which type of file to be output as |
<hr>

## Notes
Expand Down
1 change: 1 addition & 0 deletions config.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ export default {
searchFormat: '',
outputFormat: '{artistName}___{albumName}___{itemName}',
exclusionFilters: '',
outputFileType: 'mp3'
},
spotifyApi: {
clientId: 'acc6302297e040aeb6e4ac1fbdfd62c3',
Expand Down
3 changes: 2 additions & 1 deletion lib/downloader.js
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ const getYoutubeDLConfig = () => {
* @param {string} output path/name of file to be downloaded(songname.mp3)
*/
const downloader = async (youtubeLinks, output) => {
const { outputFileType } = cliInputs();
let attemptCount = 0;
let downloadSuccess = false;
while (attemptCount < youtubeLinks.length && !downloadSuccess) {
Expand All @@ -144,7 +145,7 @@ const downloader = async (youtubeLinks, output) => {
.input(download)
.audioBitrate(256)
.save(`${output}`)
.format('mp3');
.format(outputFileType);
};

try {
Expand Down
13 changes: 13 additions & 0 deletions lib/setup.js
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,18 @@ export function cliInputs() {
'eg. $ spotifydl --ef "live,concert"',
],
},
outputFileType: {
alias: 'oft',
default: flagsConfig.outputFileType,
type: 'string',
choices: ['mp3','flac', 'wav', 'aac'],
helpText: [
'--output-file-type or --oft',
'* lets you decide what type of file to output as',
'* defaults to mp3',
'eg. $ spotifydl --oft "mp3"',
],
},
};

const helpText =
Expand Down Expand Up @@ -368,5 +380,6 @@ export function cliInputs() {
password: inputFlags.password,
downloadLyrics: inputFlags.downloadLyrics,
outputFormat: inputFlags.outputFormat,
outputFileType: inputFlags.outputFileType,
};
}
3 changes: 2 additions & 1 deletion util/runner.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ const {
searchFormat,
exclusionFilters,
outputFormat,
outputFileType
} = cliInputs();

const itemOutputPath = (itemName, albumName, artistName) => {
Expand All @@ -47,7 +48,7 @@ const itemOutputPath = (itemName, albumName, artistName) => {
return `${path.join(
path.normalize(output),
...(outputOnly ? [itemName] : generatedPathSegments),
)}.mp3`;
)}.${outputFileType}`;
};

const downloadList = async list => {
Expand Down

0 comments on commit 458c7fb

Please sign in to comment.