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
|
|
|
/* this hack id or name */ |
37
|
|
|
$music = '-' . substr(strrchr('-' .$music, '-'), 1); |
38
|
|
|
|
39
|
|
|
$response = $this->getResponse($this->url.$music); |
40
|
|
|
|
41
|
|
|
return $response; |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* @param int $id |
46
|
|
|
* @param int|null $count |
47
|
|
|
* @param int|null $cursor |
48
|
|
|
* @return array |
49
|
|
|
*/ |
50
|
|
|
public function getMusicApi($id, $count = 30, $cursor = 0) |
51
|
|
|
{ |
52
|
|
|
/* add settings */ |
53
|
|
|
$this->ModelSettings(); |
54
|
|
|
|
55
|
|
|
$body = [ |
56
|
|
|
$this->api_field => $id, |
57
|
|
|
'count' => $count, |
58
|
|
|
'cursor' => $cursor, |
59
|
|
|
]; |
60
|
|
|
|
61
|
|
|
$body = array_merge($body, config('tiktok.primary_body_api')); |
62
|
|
|
|
63
|
|
|
$response = $this->getResponse($this->url_api, $body); |
64
|
|
|
|
65
|
|
|
return $response; |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* @param string $music |
70
|
|
|
* @return array |
71
|
|
|
*/ |
72
|
|
|
public function getMusicInfo($music) |
73
|
|
|
{ |
74
|
|
|
$data = $this->getMusic($music); |
75
|
|
|
|
76
|
|
|
$result = []; |
77
|
|
|
$result['success'] = $data['success']; |
78
|
|
|
|
79
|
|
|
if ($data['success'] && isset($data['result']['statusCode']) && $data['result']['statusCode'] == 0) { |
80
|
|
|
if (isset($data['result'][$this->arrayPrimary])) { |
81
|
|
|
$result['primary'] = $data['result'][$this->arrayPrimary]; |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
if ($this->arraySecondary && isset($data['result'][$this->arrayPrimary])) { |
85
|
|
|
$result['secondary'] = $data['result'][$this->arraySecondary]; |
86
|
|
|
} |
87
|
|
|
} else { |
88
|
|
|
$result['info'] = __('tiktok::tiktok.music_no_found'); |
89
|
|
|
$result['success'] = false; |
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
return $result; |
93
|
|
|
} |
94
|
|
|
} |
95
|
|
|
|