G1sms/_CopyLaRadio/libradio/radionova.php

75 lines
2.2 KiB
PHP

<?php
/*
################################################################################
# FROM CopyLaRadio MODULE_TEMPLATE_0.1
# Author: Fred (support@qo-op.com)
# Date: 2019 04 01
# License: AGPL-3.0 (https://choosealicense.com/licenses/agpl-3.0/)
################################################################################
*/
// VARS INIT
$obj=$title=$artist=$emission=$ERR=$ontheair="";
///////////////////////////
// SET TO 1 DURING DEVLT
$debug=0;
///////////////////////////
// MODULE RADIO PARAMETERS
///////////////////////////
$RADIO = "RADIO NOVA";
$referer = "http://www.nova.fr/";
$radiourl = 'http://www.nova.fr/radio/19577/player';
// TWEEK CLIENT & REFERER
ini_set('user_agent', 'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:64.0) Gecko/20100101 Firefox/64.0');
$ctx = stream_context_create(array(
'http' => array(
'header'=>array("Referer: ".$referer.PHP_EOL),
'timeout' => 5
)
)
);
///////////////////////////
// LOAD RADIO PAGE INTO PARSER
$ontheair = file_get_contents($radiourl); // JSON CONTENT
$ontheair = utf8_encode($ontheair);
$obj = json_decode($ontheair, true);
// GET TRACK INFO: ADAPT WITH DATA STRUCTURE
// ADPAPT HERE
if ( $obj['currentTrack'] ) {
// ADPAPT HERE
$title = ucwords(strtolower($obj['currentTrack']['title']));
$artist = ucwords(strtolower($obj['currentTrack']['artist']));
if ( $debug != 0 ) $ERR .= "\nTITRE = ".print_r($title, true);
if ( $debug != 0 ) $ERR .= "\nARTISTE = ".print_r($artist, true);
}
///////////////////////////
// PREPARE COPY COMMAND
$cmd = $RADIO.'|'.$artist.'|'.$title;
///////////////////////////
// DEBUG OR PROD
if($debug == 1) {
print_r($obj);
print_r($cmd);
} else {
if( $artist != "" && $title != "" ) {
// TODO Clean strings?!
if (! exec('grep '.escapeshellarg($cmd).' /tmp/ytdl.list')) {
file_put_contents("/tmp/youtube-dl.log", "ARTIST: ".$artist.". SONG: ".$title, FILE_APPEND);
file_put_contents("/tmp/ytdl.list","$cmd\n", FILE_APPEND);
} else {
file_put_contents("/tmp/youtube-dl.log", "ALREADY THERE!", FILE_APPEND);
file_put_contents("/tmp/ytdl.list","||".PHP_EOL, FILE_APPEND);
}
} else {
file_put_contents("/tmp/youtube-dl.log", "NO TRACK. TRY PODCAST!", FILE_APPEND);
file_put_contents("/tmp/ytdl.list","||".PHP_EOL, FILE_APPEND);
}
}
?>