Conditions | 6 |
Paths | 2 |
Total Lines | 36 |
Code Lines | 22 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
1 | <?php |
||
51 | public function getTrackUrl($term, $album = '', $artist = '') |
||
52 | { |
||
53 | try { |
||
54 | return Cache::remember(md5("itunes_track_url_{$term}{$album}{$artist}"), 24 * 60 * 7, |
||
55 | function () use ($term, $album, $artist) { |
||
56 | $params = [ |
||
57 | 'term' => $term.($album ? " $album" : '').($artist ? " $artist" : ''), |
||
58 | 'media' => 'music', |
||
59 | 'entity' => 'song', |
||
60 | 'limit' => 1, |
||
61 | ]; |
||
62 | |||
63 | $response = (string) $this->client->get($this->endPoint, ['query' => $params])->getBody(); |
||
64 | $response = json_decode($response); |
||
65 | |||
66 | if (!$response->resultCount) { |
||
67 | return false; |
||
68 | } |
||
69 | |||
70 | $trackUrl = $response->results[0]->trackViewUrl; |
||
71 | |||
72 | if (parse_url($trackUrl, PHP_URL_QUERY)) { |
||
73 | $trackUrl .= '&at='.config('koel.itunes.affiliate_id'); |
||
74 | } else { |
||
75 | $trackUrl .= '?at='.config('koel.itunes.affiliate_id'); |
||
76 | } |
||
77 | |||
78 | return $trackUrl; |
||
79 | } |
||
80 | ); |
||
81 | } catch (Exception $e) { |
||
82 | Log::error($e); |
||
83 | |||
84 | return false; |
||
85 | } |
||
86 | } |
||
87 | } |
||
88 |