Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?PHP
- #################################################################################
- # #
- # _______ __ __ __ __ __ #
- # / \ / | / | / |/ | / | #
- # $$$$$$$ |$$ | ______ __ __ $$ | $$ |$$/ _$$ |_ _______ #
- # $$ |__$$ |$$ | / \ / | / |$$ |__$$ |/ |/ $$ | / | #
- # $$ $$/ $$ | $$$$$$ |$$ | $$ |$$ $$ |$$ |$$$$$$/ /$$$$$$$/ #
- # $$$$$$$/ $$ | / $$ |$$ | $$ |$$$$$$$$ |$$ | $$ | __$$ \ #
- # $$ | $$ |/$$$$$$$ |$$ \__$$ |$$ | $$ |$$ | $$ |/ |$$$$$$ | #
- # $$ | $$ |$$ $$ |$$ $$ |$$ | $$ |$$ | $$ $$// $$/ #
- # $$/ $$/ $$$$$$$/ $$$$$$$ |$$/ $$/ $$/ $$$$/ $$$$$$$/ #
- # / \__$$ | #
- # $$ $$/ #
- # $$$$$$/ #
- # #
- # PlayHits CMS - Tous droits reservés #
- # Développer par Valentin O. #
- #################################################################################
- # #
- # Version 1 #
- # #
- #################################################################################
- // Includes
- include "../SQL.php";
- error_reporting(E_ALL);
- ini_set('display_errors', 'On');
- // Configuration et réception des variables du JSON en $_POST
- $jsonRes = json_decode(file_get_contents('php://input'), true);
- $jsonResArtist = $jsonRes['now_playing']['song']['artist'];
- $jsonResTitle = $jsonRes['now_playing']['song']['title'];
- $jsonResID = $jsonRes['now_playing']['song']['id'];
- $defaultPic = 'assets/images/nocover.png';
- $jsonResPlayedLast = $jsonRes['now_playing']['played_at'];
- $jsonResLive = $jsonRes['live']['is_live'];
- $jsonResLiveName = $jsonRes['live']['streamer_name'];
- $jsonResLiveList = $jsonRes['listeners']['current'];
- $title_artist = "".$jsonResTitle." ".$jsonResArtist."";
- // Enregistrement dans la pochette dans le dossier "photo"
- function artwork_save($searchTerm){
- function album_art_search($searchTerm){
- // Détermination de l'API
- $url = 'https://itunes.apple.com/search?limit=1&term=' . urlencode($searchTerm);
- // Obtention des données auprès de l'API
- $result = file_get_contents($url);
- // Si un résultat est obtenu
- if($result !== false){
- // Décodage du résultat JSON
- return json_decode($result, true);
- }
- // En cas d'erreur
- return false;
- }
- // Exécution de la recherche
- $search = $searchTerm;
- $searchResults = album_art_search($search);
- // Afficher chaque résultat
- foreach($searchResults['results'] as $result){
- if(isset($result['trackViewUrl'])){
- $old_url = $result['artworkUrl100'];
- $new_url = str_replace("100x100bb.jpg", "800x800bb.jpg", $old_url);
- // Affichage de la pochette en cours de diffusion
- $jsonResPic = $new_url;
- $content = file_get_contents($jsonResPic);
- file_put_contents('photo/'.$jsonResID.'.jpg', $content);
- }
- }
- }
- artwork_save ($title_artist);
- // Définitions des variables annexes
- $picture = $jsonResPic;
- $song_id = $jsonResID;
- $played_last = $jsonResPlayedLast;
- // Condition album_art
- if ($picture == '') {
- $picture = $defaultPic;
- }
- //Vérification existence
- $count=$playhits_pdo_connexion->prepare("SELECT song_id FROM musics_data WHERE song_id=:song_id");
- $count->bindParam(":song_id",$song_id);
- $count->execute();
- $no=$count->rowCount();
- if($no >0 ){
- // Requête
- $query = 'UPDATE musics_data SET played_at_last = ? WHERE song_id = ?';
- // Préparation
- $addindb = $playhits_pdo_connexion->prepare($query);
- // Execution
- $addindb->execute(array($played_last, $song_id));
- $rowAll = $addindb->fetch(); // fetchAll() car PLUSIEURS LIGNES récupérées
- $msg="<font color=\"orange\"><br><br><br><br><br><br>La musique " . $jsonResTitle . " de <b>" . $jsonResArtist . "</b> existe déjà dans la base avec l'ID suivant: " . $song_id . "</font><br>Les données de lectures ont été actualisées.";
- echo $msg;
- }
- else
- {
- // Requête
- $query = 'INSERT INTO musics_data(song_id,artist,title,picture,played_at_last) VALUES("' . $song_id . '", "' . $jsonResArtist . '", "' . $jsonResTitle . '", "' . $picture . '", "' . $played_last . '")';
- // Préparation
- $addindb = $playhits_pdo_connexion->prepare($query);
- // Execution
- $addindb->execute();
- $rowAll = $addindb->fetch(); // fetchAll() car PLUSIEURS LIGNES récupérées
- $msg="<font color=\"darkgreen\"><br><br><br><br><br><br>La musique " . $jsonResTitle . " de <b>" . $jsonResArtist . "</b> a bien été ajouté dans la base avec l'ID suivant: " . $song_id . "</font>";
- echo $msg;
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement