Advertisement
Guest User

Untitled

a guest
Feb 17th, 2020
152
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.15 KB | None | 0 0
  1. <?PHP
  2.  
  3. #################################################################################
  4. # #
  5. # _______ __ __ __ __ __ #
  6. # / \ / | / | / |/ | / | #
  7. # $$$$$$$ |$$ | ______ __ __ $$ | $$ |$$/ _$$ |_ _______ #
  8. # $$ |__$$ |$$ | / \ / | / |$$ |__$$ |/ |/ $$ | / | #
  9. # $$ $$/ $$ | $$$$$$ |$$ | $$ |$$ $$ |$$ |$$$$$$/ /$$$$$$$/ #
  10. # $$$$$$$/ $$ | / $$ |$$ | $$ |$$$$$$$$ |$$ | $$ | __$$ \ #
  11. # $$ | $$ |/$$$$$$$ |$$ \__$$ |$$ | $$ |$$ | $$ |/ |$$$$$$ | #
  12. # $$ | $$ |$$ $$ |$$ $$ |$$ | $$ |$$ | $$ $$// $$/ #
  13. # $$/ $$/ $$$$$$$/ $$$$$$$ |$$/ $$/ $$/ $$$$/ $$$$$$$/ #
  14. # / \__$$ | #
  15. # $$ $$/ #
  16. # $$$$$$/ #
  17. # #
  18. # PlayHits CMS - Tous droits reservés #
  19. # Développer par Valentin O. #
  20. #################################################################################
  21. # #
  22. # Version 1 #
  23. # #
  24. #################################################################################
  25.  
  26.  
  27. // Includes
  28. include "../SQL.php";
  29.  
  30. error_reporting(E_ALL);
  31. ini_set('display_errors', 'On');
  32.  
  33. // Configuration et réception des variables du JSON en $_POST
  34. $jsonRes = json_decode(file_get_contents('php://input'), true);
  35. $jsonResArtist = $jsonRes['now_playing']['song']['artist'];
  36. $jsonResTitle = $jsonRes['now_playing']['song']['title'];
  37. $jsonResID = $jsonRes['now_playing']['song']['id'];
  38. $defaultPic = 'assets/images/nocover.png';
  39. $jsonResPlayedLast = $jsonRes['now_playing']['played_at'];
  40. $jsonResLive = $jsonRes['live']['is_live'];
  41. $jsonResLiveName = $jsonRes['live']['streamer_name'];
  42. $jsonResLiveList = $jsonRes['listeners']['current'];
  43.  
  44.  
  45. $title_artist = "".$jsonResTitle." ".$jsonResArtist."";
  46.  
  47. // Enregistrement dans la pochette dans le dossier "photo"
  48. function artwork_save($searchTerm){
  49.  
  50. function album_art_search($searchTerm){
  51.  
  52. // Détermination de l'API
  53. $url = 'https://itunes.apple.com/search?limit=1&term=' . urlencode($searchTerm);
  54.  
  55. // Obtention des données auprès de l'API
  56. $result = file_get_contents($url);
  57.  
  58. // Si un résultat est obtenu
  59. if($result !== false){
  60. // Décodage du résultat JSON
  61. return json_decode($result, true);
  62. }
  63.  
  64. // En cas d'erreur
  65. return false;
  66.  
  67. }
  68.  
  69. // Exécution de la recherche
  70. $search = $searchTerm;
  71. $searchResults = album_art_search($search);
  72.  
  73. // Afficher chaque résultat
  74. foreach($searchResults['results'] as $result){
  75.  
  76. if(isset($result['trackViewUrl'])){
  77.  
  78. $old_url = $result['artworkUrl100'];
  79.  
  80. $new_url = str_replace("100x100bb.jpg", "800x800bb.jpg", $old_url);
  81.  
  82. // Affichage de la pochette en cours de diffusion
  83. $jsonResPic = $new_url;
  84.  
  85. $content = file_get_contents($jsonResPic);
  86. file_put_contents('photo/'.$jsonResID.'.jpg', $content);
  87. }
  88. }
  89. }
  90.  
  91. artwork_save ($title_artist);
  92.  
  93. // Définitions des variables annexes
  94. $picture = $jsonResPic;
  95. $song_id = $jsonResID;
  96. $played_last = $jsonResPlayedLast;
  97.  
  98. // Condition album_art
  99. if ($picture == '') {
  100. $picture = $defaultPic;
  101. }
  102.  
  103. //Vérification existence
  104. $count=$playhits_pdo_connexion->prepare("SELECT song_id FROM musics_data WHERE song_id=:song_id");
  105. $count->bindParam(":song_id",$song_id);
  106. $count->execute();
  107. $no=$count->rowCount();
  108. if($no >0 ){
  109. // Requête
  110. $query = 'UPDATE musics_data SET played_at_last = ? WHERE song_id = ?';
  111. // Préparation
  112. $addindb = $playhits_pdo_connexion->prepare($query);
  113.  
  114. // Execution
  115. $addindb->execute(array($played_last, $song_id));
  116.  
  117. $rowAll = $addindb->fetch(); // fetchAll() car PLUSIEURS LIGNES récupérées
  118. $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.";
  119. echo $msg;
  120. }
  121. else
  122. {
  123. // Requête
  124. $query = 'INSERT INTO musics_data(song_id,artist,title,picture,played_at_last) VALUES("' . $song_id . '", "' . $jsonResArtist . '", "' . $jsonResTitle . '", "' . $picture . '", "' . $played_last . '")';
  125. // Préparation
  126. $addindb = $playhits_pdo_connexion->prepare($query);
  127.  
  128. // Execution
  129. $addindb->execute();
  130.  
  131. $rowAll = $addindb->fetch(); // fetchAll() car PLUSIEURS LIGNES récupérées
  132. $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>";
  133. echo $msg;
  134. }
  135. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement