Skip to content

Commit

Permalink
MiczFlor#1309, MiczFlor#1451, MiczFlor#1691 Add user-agent to avoid 4…
Browse files Browse the repository at this point in the history
…00-bad-requests from open.spotify.com.
  • Loading branch information
mbaumelerSBB committed Dec 30, 2021
1 parent b3e91ae commit 159a0fb
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions htdocs/inc.viewFolderTree.php
Original file line number Diff line number Diff line change
Expand Up @@ -116,18 +116,19 @@
// this is a new and easier way for loading spotify informations!
$uri = file_get_contents($subfolder."/spotify.txt");
$url = "https://open.spotify.com/oembed/?url=".trim($uri)."&format=json";
$headers = stream_context_create(array('http'=>array('method'=>'GET', 'header'=>'user-agent:Phoniebox')));

if (!file_exists($coverfile)) {
$str = file_get_contents($url);
$str = file_get_contents($url, false, $headers);
$json = json_decode($str, true);

$cover = $json['thumbnail_url'];
$coverdl = file_get_contents($cover);
$coverdl = file_get_contents($cover, false, $headers);
file_put_contents($coverfile, $coverdl);
}

if (!file_exists($titlefile)) {
$str = file_get_contents($url);
$str = file_get_contents($url, false, $headers);
$json = json_decode($str, true);

$title = $json['title'];
Expand Down

0 comments on commit 159a0fb

Please sign in to comment.