Skip to content

Commit

Permalink
Merge pull request #12 from MarkWasley/fix-issue-11
Browse files Browse the repository at this point in the history
Fixes #11 -- Split artist and title on first delimiter
  • Loading branch information
BusterNeece authored Aug 16, 2023
2 parents 4924297 + 472dfe4 commit c19dad4
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 9 deletions.
6 changes: 2 additions & 4 deletions src/Adapter/Icecast.php
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,7 @@ private function processJsonNowPlaying(
$np->currentSong = new CurrentSong(
$row['yp_currently_playing'] ?? '',
$row['title'] ?? '',
$row['artist'] ?? '',
' - '
$row['artist'] ?? ''
);

$bitrate = $row['audio_bitrate'] ?? $row['bitrate'] ?? null;
Expand Down Expand Up @@ -176,8 +175,7 @@ private function processXmlNowPlaying(
$np->currentSong = new CurrentSong(
'',
$title,
$artist,
' - '
$artist
);

$bitrate = max(
Expand Down
5 changes: 4 additions & 1 deletion src/Adapter/Shoutcast1.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,10 @@ private function processNowPlaying(

// Increment listener counts in the now playing data.
$np = new Result;
$np->currentSong = new CurrentSong($title);
$np->currentSong = new CurrentSong(
text: $title,
delimiter: '-'
);
$np->listeners = new Listeners((int)$total_listeners, (int)$unique_listeners);
$np->meta = new Meta(
!empty($np->currentSong->text),
Expand Down
5 changes: 4 additions & 1 deletion src/Adapter/Shoutcast2.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,10 @@ private function handleNowPlayingPayload(?string $payload): ?Result
$currentSongText = str_replace(' ', ' - ', $currentSongText);

$np = new Result;
$np->currentSong = new CurrentSong($currentSongText);
$np->currentSong = new CurrentSong(
text: $currentSongText,
delimiter: '-'
);
$np->listeners = new Listeners(
(int)$xml->CURRENTLISTENERS,
(int)$xml->UNIQUELISTENERS
Expand Down
6 changes: 3 additions & 3 deletions src/Result/CurrentSong.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public function __construct(
string $text = '',
string $title = '',
string $artist = '',
string $delimiter = '-'
string $delimiter = ' - '
) {
$text = $this->cleanUpString($text);
$title = $this->cleanUpString($title);
Expand All @@ -35,8 +35,8 @@ public function __construct(
if (\count($string_parts) === 1) {
$title = $text;
} else {
$title = trim(array_pop($string_parts));
$artist = trim(implode($delimiter, $string_parts));
$title = trim(implode($delimiter, array_slice($string_parts, 1)));
$artist = trim($string_parts[0]);
}
}

Expand Down

0 comments on commit c19dad4

Please sign in to comment.