1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Daaner\TikTok\Models; |
4
|
|
|
|
5
|
|
|
use Daaner\TikTok\TikTok; |
6
|
|
|
|
7
|
|
|
class MusicInfo extends TikTok |
8
|
|
|
{ |
9
|
|
|
protected $url; |
10
|
|
|
protected $url_api; |
11
|
|
|
protected $api_field; |
12
|
|
|
protected $arrayPrimary; |
13
|
|
|
protected $arraySecondary; |
14
|
|
|
|
15
|
|
|
/** |
16
|
|
|
* @return $this |
17
|
|
|
*/ |
18
|
|
|
public function ModelSettings() |
19
|
|
|
{ |
20
|
|
|
$this->url = config('tiktok.music_info.link'); |
21
|
|
|
$this->url_api = config('tiktok.music_info.link_api'); |
22
|
|
|
$this->api_field = config('tiktok.music_info.api_field'); |
23
|
|
|
$this->arrayPrimary = config('tiktok.music_info.array_primary'); |
24
|
|
|
$this->arraySecondary = config('tiktok.music_info.array_secondary'); |
25
|
|
|
} |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* @param string $music |
29
|
|
|
* @return array |
30
|
|
|
*/ |
31
|
|
|
public function getMusic($music) |
32
|
|
|
{ |
33
|
|
|
//add settings |
34
|
|
|
$this->ModelSettings(); |
35
|
|
|
|
36
|
|
|
$response = $this->getResponse($this->url.$music); |
37
|
|
|
|
38
|
|
|
return $response; |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* @param int $id |
43
|
|
|
* @return array |
44
|
|
|
*/ |
45
|
|
|
public function getMusicApi($id, $count = 30, $cursor = 0) |
46
|
|
|
{ |
47
|
|
|
//add settings |
48
|
|
|
$this->ModelSettings(); |
49
|
|
|
|
50
|
|
|
$body = [ |
51
|
|
|
$this->api_field => $id, |
52
|
|
|
'count' => $count, |
53
|
|
|
'cursor' => $cursor, |
54
|
|
|
]; |
55
|
|
|
|
56
|
|
|
$body = array_merge($body, config('tiktok.primary_body_api')); |
57
|
|
|
|
58
|
|
|
$response = $this->getResponse($this->url_api, $body); |
59
|
|
|
|
60
|
|
|
return $response; |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
/** |
64
|
|
|
* @param string $music |
65
|
|
|
* @return array |
66
|
|
|
*/ |
67
|
|
|
public function getMusicInfo($music) |
68
|
|
|
{ |
69
|
|
|
$data = $this->getMusic($music); |
70
|
|
|
|
71
|
|
|
$result = []; |
72
|
|
|
$result['success'] = $data['success']; |
73
|
|
|
|
74
|
|
|
if ($data['success'] && isset($data['result']['statusCode']) && $data['result']['statusCode'] == 0) { |
75
|
|
|
if (isset($data['result'][$this->arrayPrimary])) { |
76
|
|
|
$result['primary'] = $data['result'][$this->arrayPrimary]; |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
if ($this->arraySecondary && isset($data['result'][$this->arrayPrimary])) { |
80
|
|
|
$result['secondary'] = $data['result'][$this->arraySecondary]; |
81
|
|
|
} |
82
|
|
|
} else { |
83
|
|
|
$result['info'] = __('tiktok::tiktok.music_no_found'); |
84
|
|
|
$result['success'] = false; |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
return $result; |
88
|
|
|
} |
89
|
|
|
} |
90
|
|
|
|