Skip to content

Commit

Permalink
fix(utils): Improve song name formatting
Browse files Browse the repository at this point in the history
- Remove unnecessary characters from song name based on OS
- Use a more concise format for the return string
- Ensure proper formatting and cleanup of artist and song name
- Closes #811
  • Loading branch information
guanguans committed Oct 10, 2024
1 parent b1937cc commit b82a9e2
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
3 changes: 3 additions & 0 deletions app/Commands/MusicCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,9 @@ protected function initialize(InputInterface $input, OutputInterface $output): v
}

/**
* @psalm-suppress InvalidReturnType
* @psalm-suppress InvalidReturnStatement
*
* @template TValue
*
* @param callable(): TValue $callback
Expand Down
15 changes: 12 additions & 3 deletions app/Support/Utils.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,19 @@ public static function savedPathFor(array $song, ?string $savedDir = null, strin
}

return \sprintf(
'%s%s - %s.%s',
'%s%s.%s',
$savedDir,
implode(',', $song['artist']),
preg_replace('/[\\\|\/|\:|\*|\?|\"|\<|\>|\|| ]+/', ' ', $song['name']),
str(\sprintf('%s - %s', implode(',', $song['artist']), $song['name']))
->replace(
match (\PHP_OS_FAMILY) {
'Windows' => ['<', '>', '/', '\\', '|', ':', '"', '?', '*'],
'Darwin' => [':'],
default => [],
},
'',
)
->ltrim('.')
->toString(),
preg_replace('/\?.*/', '', pathinfo((string) $song['url'], \PATHINFO_EXTENSION)) ?: $defaultExt
);
}
Expand Down

0 comments on commit b82a9e2

Please sign in to comment.