Fixes #4086 -- Don't urldecode playlist rows when importing.

This commit is contained in:
Buster "Silver Eagle" Neece 2021-05-08 05:07:33 -05:00
parent 4195386e86
commit f32eebb6a9
No known key found for this signature in database
GPG Key ID: 6D9E12FF03411F4E
2 changed files with 28 additions and 62 deletions

View File

@ -9,7 +9,6 @@ use App\Environment;
use App\Radio\Adapters;
use App\Radio\Configuration;
use App\Radio\Frontend\AbstractFrontend;
use App\Sync\Task\CheckMediaTask;
use App\Utilities;
use Closure;
use Exception;
@ -21,38 +20,17 @@ use Symfony\Component\Validator\Validator\ValidatorInterface;
class StationRepository extends Repository
{
protected CheckMediaTask $mediaSync;
protected Adapters $adapters;
protected Configuration $configuration;
protected ValidatorInterface $validator;
protected StorageLocationRepository $storageLocationRepo;
protected SettingsRepository $settingsRepo;
public function __construct(
protected SettingsRepository $settingsRepo,
protected StorageLocationRepository $storageLocationRepo,
protected LoggerInterface $logger,
protected Adapters $adapters,
protected Configuration $configuration,
protected ValidatorInterface $validator,
ReloadableEntityManagerInterface $em,
Serializer $serializer,
Environment $environment,
SettingsRepository $settingsRepo,
StorageLocationRepository $storageLocationRepo,
LoggerInterface $logger,
CheckMediaTask $mediaSync,
Adapters $adapters,
Configuration $configuration,
ValidatorInterface $validator
) {
$this->mediaSync = $mediaSync;
$this->adapters = $adapters;
$this->configuration = $configuration;
$this->validator = $validator;
$this->settingsRepo = $settingsRepo;
$this->storageLocationRepo = $storageLocationRepo;
parent::__construct($em, $serializer, $environment, $logger);
}
@ -225,20 +203,9 @@ class StationRepository extends Repository
public function create(Entity\Station $station): Entity\Station
{
$station->generateAdapterApiKey();
$this->configuration->initializeConfiguration($station);
// Scan directory for any existing files.
set_time_limit(600);
$this->mediaSync->importMusic($station->getMediaStorageLocation());
/** @var Entity\Station $station */
$station = $this->em->find(Entity\Station::class, $station->getId());
$this->mediaSync->importPlaylists($station);
/** @var Entity\Station $station */
$station = $this->em->find(Entity\Station::class, $station->getId());
// Create default mountpoints if station supports them.
$frontend_adapter = $this->adapters->getFrontendAdapter($station);
$this->resetMounts($station, $frontend_adapter);

View File

@ -7,33 +7,32 @@ class PlaylistParser
/**
* @return string[]
*/
public static function getSongs($playlist_raw): array
public static function getSongs(string $playlistRaw): array
{
// Process as full PLS if the header is present.
if (str_starts_with($playlist_raw, '[playlist]')) {
$parsed_playlist = (array)parse_ini_string($playlist_raw, true, INI_SCANNER_RAW);
if (str_starts_with($playlistRaw, '[playlist]')) {
$parsed_playlist = (array)parse_ini_string($playlistRaw, true, INI_SCANNER_RAW);
$paths = [];
foreach ($parsed_playlist['playlist'] as $playlist_key => $playlist_line) {
if (str_starts_with(strtolower($playlist_key), 'file')) {
$paths[] = $playlist_line;
}
}
} else {
$filter_line = static function ($line) {
return trim(urldecode($line));
};
// Process as a simple list of files or M3U-style playlist.
$lines = explode("\n", $playlist_raw);
$paths = array_filter(
array_map($filter_line, $lines),
static function ($line) {
return !empty($line) && $line[0] !== '#';
}
return array_filter(
$parsed_playlist['playlist'],
function ($key) {
return str_starts_with(strtolower($key), 'file');
},
ARRAY_FILTER_USE_KEY
);
}
return $paths;
$filter_line = static function ($line) {
return trim($line);
};
// Process as a simple list of files or M3U-style playlist.
$lines = explode("\n", $playlistRaw);
return array_filter(
array_map($filter_line, $lines),
static function ($line) {
return !empty($line) && $line[0] !== '#';
}
);
}
}