G1sms/_CopyLaRadio/libradio/FIP autour de llectro.php

76 lines
2.5 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 = "FIP Electro";
$referer = "https://www.fip.fr/";
$radiourl = 'https://www.fip.fr/latest/api/graphql?operationName=Now&variables=%7B%22bannerPreset%22%3A%221400x1400%22%2C%22stationId%22%3A74%7D&extensions=%7B%22persistedQuery%22%3A%7B%22version%22%3A1%2C%22sha256Hash%22%3A%229551487ee4a6810ec4afa35e70dd1c204fa84db3519d39eb3176e5a3a8b0e482%22%7D%7D';
// 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
$current = $obj['data']['now']['playing_item'];
// GET TRACK INFO
if ( $current ) {
// ADPAPT HERE
$artist = ucwords(strtolower($current['title']));
$title = ucwords(strtolower($current['subtitle']));
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);
}
}
?>