This repository has been archived by the owner on Apr 7, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
450 additions
and
85 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<?php | ||
|
||
namespace Utvarp\MusicHelper\Exceptions; | ||
|
||
use Exception; | ||
|
||
class MusicException extends Exception | ||
{ | ||
public static function unsupportedSource() | ||
{ | ||
return new static('One or all of the given sources are unsupported.'); | ||
} | ||
|
||
public static function sourceNotFoundInResults() | ||
{ | ||
return new static("We could not find the requested source in the results."); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<?php | ||
|
||
namespace Utvarp\MusicHelper; | ||
|
||
use Illuminate\Support\Collection; | ||
|
||
class Helpers | ||
{ | ||
public static function collect($value = []) | ||
{ | ||
return new Collection($value); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
<?php | ||
|
||
namespace Utvarp\MusicHelper\Models; | ||
|
||
use Illuminate\Support\Collection; | ||
use Utvarp\MusicHelper\Models\Result; | ||
|
||
class DeezerResult | ||
{ | ||
|
||
public $count; | ||
|
||
public function __construct($results, $searchedTrack = null, $searchedArtist = null) | ||
{ | ||
$this->searchStrings = (object) [ | ||
'track' => $searchedTrack, | ||
'artist' => $searchedArtist, | ||
]; | ||
|
||
$this->count = count($results); | ||
$this->formatResults($results); | ||
} | ||
|
||
public function formatResults($results) | ||
{ | ||
$this->results = collect($results)->map(function ($result) { | ||
$model = new Result('deezer'); | ||
$model->setTrack($result->id, $result->title); | ||
$model->setArtist($result->artist->id, $result->artist->name); | ||
$model->setAlbum($result->album->id, $result->album->title); | ||
$model->calculateSimilarities($this->searchStrings); | ||
|
||
return $model; | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
<?php | ||
|
||
namespace Utvarp\MusicHelper\Models; | ||
|
||
use Atomescrochus\StringSimilarities\Compare; | ||
|
||
class Result | ||
{ | ||
|
||
public function __construct($source) | ||
{ | ||
$this->source = $source; | ||
} | ||
|
||
public function setTrack($id, $name = null) | ||
{ | ||
$this->track = (object) [ | ||
'id' => $id, | ||
'name' => $name, | ||
]; | ||
} | ||
|
||
public function setArtist($id, $name = null) | ||
{ | ||
$this->artist = (object) [ | ||
'id' => $id, | ||
'name' => $name, | ||
]; | ||
} | ||
|
||
public function setAlbum($id, $name = null) | ||
{ | ||
$this->album = (object) [ | ||
'id' => $id, | ||
'name' => $name, | ||
]; | ||
} | ||
|
||
public function calculateSimilarities($searchedStrings) | ||
{ | ||
if (!is_null($searchedStrings->track)) { | ||
$compare = new Compare(); | ||
$this->track->similarityScores = (object) $compare->all($this->track->name, $searchedStrings->track); | ||
} else { | ||
$this->track->similarityScores = null; | ||
} | ||
|
||
if (!is_null($searchedStrings->artist)) { | ||
$compare = new Compare(); | ||
$this->artist->similarityScores = (object) $compare->all($this->artist->name, $searchedStrings->artist); | ||
} else { | ||
$this->track->similarityScores = null; | ||
} | ||
|
||
$this->album->similarityScores = null; | ||
} | ||
} |
Oops, something went wrong.