Allow "prevent duplicates" selection on a per-playlist basis.

This commit is contained in:
Buster "Silver Eagle" Neece 2020-06-04 04:00:35 -05:00
parent f2f15d2597
commit 234e2ce587
No known key found for this signature in database
GPG Key ID: 6D9E12FF03411F4E
7 changed files with 88 additions and 11 deletions

View File

@ -79,6 +79,7 @@
'play_per_hour_minute': {},
'include_in_requests': {},
'include_in_automation': {},
'avoid_duplicates': {},
'backend_options': {},
'schedule_items': {
$each: {
@ -110,6 +111,7 @@
'play_per_hour_minute': 0,
'include_in_requests': true,
'include_in_automation': false,
'avoid_duplicates': true,
'backend_options': [],
'schedule_items': []
};
@ -147,6 +149,7 @@
'play_per_hour_minute': d.play_per_hour_minute,
'include_in_requests': d.include_in_requests,
'include_in_automation': d.include_in_automation,
'avoid_duplicates': d.avoid_duplicates,
'backend_options': d.backend_options,
'schedule_items': d.schedule_items
};

View File

@ -27,7 +27,7 @@
</b-form-invalid-feedback>
</b-form-group>
<b-form-group class="col-md-12" label-for="form_edit_is_enabled">
<b-form-group class="col-md-6" label-for="form_edit_is_enabled">
<template v-slot:description>
<translate>If disabled, the playlist will not be included in radio playback, but can still be managed.</translate>
</template>
@ -36,6 +36,15 @@
</b-form-checkbox>
</b-form-group>
<b-form-group class="col-md-6" label-for="form_edit_avoid_duplicates">
<template v-slot:description>
<translate>Whether the AutoDJ should attempt to avoid duplicate artists and track titles when playing media from this playlist.</translate>
</template>
<b-form-checkbox id="form_edit_avoid_duplicates" v-model="form.avoid_duplicates.$model">
<translate>Avoid Duplicate Artists/Titles</translate>
</b-form-checkbox>
</b-form-group>
<b-form-group class="col-md-12" label-for="form_edit_include_in_on_demand">
<template v-slot:description>
<translate>If this station has on-demand streaming and downloading enabled, only songs that are in playlists with this setting enabled will be visible.</translate>

View File

@ -0,0 +1,42 @@
<?php
declare(strict_types=1);
namespace App\Entity\Migration;
use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;
/**
* Auto-generated Migration: Please modify to your needs!
*/
final class Version20200604075356 extends AbstractMigration
{
public function getDescription(): string
{
return 'Add per-playlist "avoid duplicates" flag.';
}
public function up(Schema $schema): void
{
// this up() migration is auto-generated, please modify it to your needs
$this->abortIf($this->connection->getDatabasePlatform()->getName() !== 'mysql',
'Migration can only be executed safely on \'mysql\'.');
$this->addSql('ALTER TABLE station_playlists ADD avoid_duplicates TINYINT(1) NOT NULL');
}
public function postUp(Schema $schema): void
{
$this->connection->executeUpdate('UPDATE station_playlists SET avoid_duplicates=1');
}
public function down(Schema $schema): void
{
// this down() migration is auto-generated, please modify it to your needs
$this->abortIf($this->connection->getDatabasePlatform()->getName() !== 'mysql',
'Migration can only be executed safely on \'mysql\'.');
$this->addSql('ALTER TABLE station_playlists DROP avoid_duplicates');
}
}

View File

@ -232,6 +232,15 @@ class StationPlaylist
*/
protected $backend_options = '';
/**
* @ORM\Column(name="avoid_duplicates", type="boolean")
*
* @OA\Property(example=true)
*
* @var bool
*/
protected $avoid_duplicates = true;
/**
* @ORM\Column(name="played_at", type="integer")
* @AuditLog\AuditIgnore
@ -467,6 +476,16 @@ class StationPlaylist
$this->include_in_automation = $include_in_automation;
}
public function getAvoidDuplicates(): bool
{
return $this->avoid_duplicates;
}
public function setAvoidDuplicates(bool $avoid_duplicates): void
{
$this->avoid_duplicates = $avoid_duplicates;
}
public function getPlayedAt(): int
{
return $this->played_at;

View File

@ -494,18 +494,22 @@ class AutoDJ implements EventSubscriberInterface
}
}
if ($allowDuplicates) {
$mediaId = $this->preventDuplicates($mediaQueue, $recentSongHistory, false);
if ($playlist->getAvoidDuplicates()) {
if ($allowDuplicates) {
$mediaId = $this->preventDuplicates($mediaQueue, $recentSongHistory, false);
if (null === $mediaId) {
$this->logger->warning('Duplicate prevention yielded no playable song; resetting song queue.');
if (null === $mediaId) {
$this->logger->warning('Duplicate prevention yielded no playable song; resetting song queue.');
// Pull the entire shuffled playlist if a duplicate title can't be avoided.
$mediaQueue = $this->spmRepo->getPlayableMedia($playlist);
$mediaId = $this->preventDuplicates($mediaQueue, $recentSongHistory, true);
// Pull the entire shuffled playlist if a duplicate title can't be avoided.
$mediaQueue = $this->spmRepo->getPlayableMedia($playlist);
$mediaId = $this->preventDuplicates($mediaQueue, $recentSongHistory, true);
}
} else {
$mediaId = $this->preventDuplicates($mediaQueue, $recentSongHistory, false);
}
} else {
$mediaId = $this->preventDuplicates($mediaQueue, $recentSongHistory, false);
$mediaId = array_key_first($mediaQueue);
}
if (null !== $mediaId) {

View File

@ -52,7 +52,7 @@
"dist/radio_player.js": "dist/radio_player-562bd0b7db.js",
"dist/station_media.js": "dist/station_media-6c7c24370f.js",
"dist/station_on_demand.js": "dist/station_on_demand-83b1d61083.js",
"dist/station_playlists.js": "dist/station_playlists-821b66e79c.js",
"dist/station_playlists.js": "dist/station_playlists-0da5329257.js",
"dist/station_streamers.js": "dist/station_streamers-b57da17301.js",
"dist/vue_gettext.js": "dist/vue_gettext-2d25ba9686.js",
"dist/webcaster.js": "dist/webcaster-09a0e0221a.js",

File diff suppressed because one or more lines are too long