-
Notifications
You must be signed in to change notification settings - Fork 16
/
SoundYoutubeSearch
61 lines (55 loc) · 2.91 KB
/
SoundYoutubeSearch
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
/**
* Сценарий для Majordomo
* Голосовой поиск роликов на youtube
* @author Alex Sokolov <[email protected]>
* @copyright Alex Sokolov http://blog.gelezako.com (c)
* @version 0.1 ([April 04, 2017])
**/
// $params['music-artist']
// $params['typemusic'] (ex 'транс');
//проверяем кого хотим слушать, солиста, группу или направление
if($params['typemusic']=='' and $params['music-artist']!='')
$url='http://localhost/modules/SearchYoutube/search.php?q='.$params['music-artist'].'&maxResults='.gg("Youtube.maxCount");
else if($params['music-artist']=='' and $params['typemusic']!='')
$url='http://localhost/modules/SearchYoutube/search.php?q='.$params['typemusic'].'&maxResults='.gg("Youtube.maxCount");
else if($params['state']=='выключить'){
getURL('http://localhost:8080/requests/status.xml?command=pl_stop');
}
else if($params['typemusic']=='' and $params['music-artist']=='' and $params['next']==''){
$url=''; say("Неполучается найти трек на ютубе",2);}
//узнаем была ли команда воспроизвести другой трек,если треков больше чем один, то воспроизводим
if($params['next']!='' and (int)gg("Youtube.maxCount")>1){
$next=(int)gg("Youtube.next");
if($next>1){
say("открываю следующий трек",2);
getURL(BASE_URL.ROOTHTML.'popup/app_player.html?ajax=1&command=refresh&play=https://www.youtube.com/watch?v='.gg("Youtube.videoId".$next),0);
sg("Youtube.next", (int)$next-1);
}
else {
// если проиграли все ролики, то играем по кругу
$next=gg("Youtube.maxCount");
say("открываю следующий трек",2);
getURL(BASE_URL.ROOTHTML.'popup/app_player.html?ajax=1&command=refresh&play=https://www.youtube.com/watch?v='.gg("Youtube.videoId".$next),0);
sg("Youtube.next",$next-1);
}
}
$i=0; // счётчик кол-ва ссылок на ютуб
//libxml_use_internal_errors(true);
if ($url!=''){
$xml = @simplexml_load_file($url);
if (false === $xml) say("Что-то сломалось",2);
else {
foreach($xml->clip as $clip){
$i++;
sg("Youtube.title".$i, $clip->title);
sg("Youtube.videoId".$i, $clip->videoId);
}
}
}
//если удалось распознать артиста или музыкально направление, то открыть ссылку
if($i>0 and $params['next']==''){
say("открываю",2);
getURL(BASE_URL.ROOTHTML.'popup/app_player.html?ajax=1&command=refresh&play=https://www.youtube.com/watch?v='.gg("Youtube.videoId".$i),0);
}
libxml_clear_errors(); //возможно и не надо чистить, но я оставил :)
libxml_use_internal_errors($use_errors);