-
Notifications
You must be signed in to change notification settings - Fork 0
/
cddblookup.php
169 lines (144 loc) · 6.09 KB
/
cddblookup.php
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
<?php require("verify.php");
#### User has logged in and been verified ####
header("Cache-Control: no-cache");
header("Pragma: no-cache");
header("Expires: 0");?>
<HTML>
<head>
<TITLE>ThreeD - MusicDB FreeDB Lookup</TITLE>
<LINK REL="StyleSheet" HREF="style.css" TYPE="text/css">
<META HTTP-EQUIV="Expires" CONTENT="Fri, Jun 12 1981 08:20:00 GMT">
<META HTTP-EQUIV="Pragma" CONTENT="no-cache">
<META HTTP-EQUIV="Cache-Control" CONTENT="no-cache">
</head>
<BODY>
<?php
if (!$admin && $user[cdeditor] != "t") {
echo "<p><font color=red><b>You do not have the necessary privilages to do that!</b></font><p>";
echo "</BODY></HTML>";
exit;
}
if ($xadd) {
$xartist = addslashes(urldecode($xartist));
$xartist = preg_replace ("/ +/", " ", trim($xartist));
$xtitle = addslashes(urldecode($xtitle));
$xtitle = preg_replace ("/ +/", " ", trim($xtitle));
settype ($xnumtracks, "integer"); if ($xnumtracks < 0) { $xnumtracks = 0; }
settype ($xyear, "integer"); if ($xyear < 1000 || $xyear > 2100) { $xyear = 0; }
$xgenre = addslashes(urldecode($xgenre));
$xgenre = preg_replace ("/ +/", " ", trim($xgenre));
$timenow = time();
$a = date ("Y-m-d");
$query = "INSERT INTO cd (artist, title, year, genre, arrivaldate,
createwho, createwhen, modifywho, modifywhen, copies, format)
VALUES ($q$xartist$q, $q$xtitle$q,
$q$xyear$q, $q$xgenre$q, '$a', $q$cid$q, $q$timenow$q, $q$cid$q, $q$timenow$q, 1, 1);";
echo $query;
$result = pg_query($db, $query);
$lastoid = pg_last_oid($result);
$kquery = "SELECT id FROM cd WHERE OID = $q$lastoid$q;";
$kresult = pg_query($db, $kquery);
$r = pg_fetch_array($kresult, 0, PGSQL_ASSOC);
$xref = $r[id];
$trackcount = count($xtrackartist);
for ($i=0;$i<$trackcount;$i++) {
$ii = $i+1;
$tracktitle = addslashes(urldecode($xtracktitle[$i]));
$trackartist = addslashes(urldecode($xtrackartist[$i]));
$tracklength = urldecode($xtracklength[$i]);
if (preg_match("|(.*)[:\.;,](.*)[:\.;,](.*)|", $tracklength, $matches)) {
settype ($matches[1], "integer");
settype ($matches[2], "integer");
settype ($matches[3], "integer");
$seconds = $matches[1] * 60 * 60 + $matches[2] * 60 + $matches[3];
$tracklength = $seconds;
}
elseif (preg_match("|(.*)[:\.;,](.*)|", $tracklength, $matches)) {
settype ($matches[1], "integer");
settype ($matches[2], "integer");
$seconds = $matches[1] * 60 + $matches[2];
$tracklength = $seconds;
}
else { settype ($tracklength, "integer"); }
$tracktitle = preg_replace ("/ +/", " ", trim($tracktitle));
$trackartist = preg_replace ("/ +/", " ", trim($trackartist));
$ttquery = "INSERT INTO cdtrack (cdid, tracknum, tracktitle, trackartist, tracklength)
VALUES ($xref, $ii,
$q$tracktitle$q,
$q$trackartist$q,
$q$tracklength$q);";
$ttresult = pg_query($db, $ttquery);
}
if ($kresult) { header("Location: http://".$_SERVER['HTTP_HOST'] .dirname($_SERVER['PHP_SELF']) ."/cdedit.php?xref=".$xref); }
}
?>
<form action=cddblookup.php method=post>
<B>MUSIC CATALOGUE - NEW ENTRY FROM FREEDB</B>
<p>If this is the CD you want then
<input type=submit name=xadd value="Add it to the Database">
<p><hr>
<?php
if ($id) {
$url = "http://www.gracenote.com/search/album_details.php?tui_id=".$id;
$ch = curl_init ($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
curl_setopt ($ch, CURLOPT_HEADER, 0);
if ($webproxy) { curl_setopt ($ch, CURLOPT_PROXY, $webproxy); }
$aa = curl_exec ($ch);
curl_close ($ch);
$aa = preg_replace("/[\n\r]/"," ",$aa);
preg_match ("|<h2>(.*)</h2>|i", $aa, $out);
$titletemp = $out[1];
preg_match ("| *(.*) *\/ *(.*) *|", $titletemp, $out1);
if (count($out1) == 3) { $artist = $out1[1]; $title = $out1[2]; }
else { $artist = $titletemp; $title = ""; }
preg_match ("|<div class=\"album-name\"><strong>Album</strong> > (.*?)</div>|i", $aa, $out);
$title = $out[1];
preg_match ("|<div class=\"artist-name\"><strong>Artist</strong> > <span name=\".*?\"><a.*?>(.*?)</a></span></div>|i", $aa, $out);
$artist = $out[1];
preg_match ("|tracks: *(.*)<br>|i", $aa, $out);
$tracks = $out[1];
preg_match ("|total time: *(.*)<br>|i", $aa, $out);
$totaltime = $out[1];
preg_match ("|<div class=\"year\"><strong>Year of Release</strong> > (.*?)</div>|i", $aa, $out);
$year = $out[1];
preg_match ("|genre: *(.*)<br>|i", $aa, $out);
$genre = $out[1];
preg_match_all ("|<div class=\"track_name\">(.*?)</div>|i", $aa, $tout);
$tracks = count($tout[1]);
echo "<p><table border=1 cellspacing=0 cellpadding=2>";
echo "<tr><td>Artist</td><td>$artist</td></tr>";
echo "<tr><td>Title</td><td>$title</td></tr>";
echo "<tr><td>Tracks</td><td>$tracks</td></tr>";
echo "<tr><td>Total Time</td><td>$totaltime</td></tr>";
echo "<tr><td>Year</td><td>$year</td></tr>";
echo "<tr><td>Genre</td><td>$genre</td></tr>";
echo "</table>";
echo "<input type=hidden name=xartist value=".urlencode($artist).">";
echo "<input type=hidden name=xtitle value=".urlencode($title).">";
echo "<input type=hidden name=xnumtracks value=".urlencode($tracks).">";
echo "<input type=hidden name=xyear value=".urlencode($year).">";
echo "<input type=hidden name=xgenre value=".urlencode($genre).">";
#preg_match_all ("|<tr><td valign=top> *(.*?)\.</td><td valign=top> *(.*?)</td><td><b>(.*?)</b>|i", $aa, $tout);
if (count($tout[1])) {
echo "\n<p><table border=1 cellspacing=0 cellpadding=2>\n";
echo "<tr><td><b>Track</b></td><td><b>Length</b></td><td><b>Artist</b></td><td><b>Title</b></td></tr>";
for ($i=0;$i<count($tout[1]);$i++) {
#$tracktemp = $tout[3][$i];
#preg_match ("| *(.*) *\/ *(.*) *|", $tracktemp, $out1);
#if (count($out1) == 3) { $trackartist = $out1[1]; $tracktitle = $out1[2]; }
#else { $tracktitle = $tracktemp; $trackartist = ""; }
#$tracklength = $tout[2][$i];
$tracktitle = $tout[1][$i];
echo "\n<tr><td>".($i+1)."</td><td>".$tracklength."</td><td>".$trackartist."</td><td>".$tracktitle."</td>";
echo "<input type=hidden name=xtrackartist[] value=".urlencode($trackartist).">";
echo "<input type=hidden name=xtracktitle[] value=".urlencode($tracktitle).">";
echo "<input type=hidden name=xtracklength[] value=".urlencode($tracklength).">";
}
echo "\n</table>\n";
}
}
?>
</form>
</BODY>
</HTML>