Repository navigation
Expand file tree
/
Copy pathmetadata.php
More file actions
74 lines (66 loc) · 2.13 KB
/
Copy pathmetadata.php
File metadata and controls
74 lines (66 loc) · 2.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
<?php
$songData = file_get_contents('/var/www/roomradio/songtitle.txt');
preg_match('/([a-zA-Z])(.*)(?=\ -)/',$songData, $artist);
$imageQuery=str_replace(' ', '+', $artist[0]);
$imageQuery=$imageQuery."+artwork";
function get_url_contents($url) {
$crl = curl_init();
curl_setopt($crl, CURLOPT_USERAGENT, 'Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; .NET CLR 1.1.4322)');
curl_setopt($crl, CURLOPT_URL, $url);
curl_setopt($crl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($crl, CURLOPT_CONNECTTIMEOUT, 5);
$ret = curl_exec($crl);
curl_close($crl);
return $ret;
}
$imgUrl = '';
$imageLinksArray = [];
$imageExists = false;
if (($h = fopen("/var/www/roomradio/imageLinks.csv", "r")) !== FALSE)
{
while (($data =fgetcsv($h, 1000, ",")) !== FALSE)
{
$imageLinksArray[] = $data;
}
fclose($h);
}
for ($i = 0; $i < count($imageLinksArray); $i++) {
if ($imageQuery == $imageLinksArray[$i][0])
{
$imageExists=true;
$imgUrl = $imageLinksArray[$i][1];
break;
}
}
if ($imageExists == false)
{
$url ='https://www.googleapis.com/customsearch/v1?key=AIzaSyAliM8GjxXcPKMkZiPiDxlGhLI25mZHhsU&cx=016998421560717524457:0bctl8e-qsm&q='. trim($imageQuery).'&searchType=image&fileType=jpg';
function get_url_contents2($url){
$crl = curl_init();
$timeout = 5;
curl_setopt ($crl, CURLOPT_URL,$url);
curl_setopt ($crl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt ($crl, CURLOPT_CONNECTTIMEOUT, $timeout);
$ret = curl_exec($crl);
curl_close($crl);
return $ret;
}
$json = get_url_contents2($url);
$data = json_decode($json);
if ($json!=null){
$i = 0;
if (!empty($data->items[0]->link)) {
$imgUrl = $data->items[0]->link;
}
else {
print("Url not returned");
}
$imageData[0] = $imageQuery;
$imageData[1] = $imgUrl;
$fp = fopen('/var/www/roomradio/imageLinks.csv', 'a');
fputcsv($fp,$imageData,',', '"');
fclose($fp);
}
}
print($imgUrl);
?>