Recent Posts

Pages: 1 ... 4 5 6 7 8 [9]
81
Hi jesper,

So, you made the switch to the new forum. A warm welcome - again  ;)

I've just been looking/scanning the improvements you made, - looks absolutely great!
...and will be included in the next release (I'll try the hacks out in real life against my own collection in the meantime).

Thanks again, - the stuff you make is highly appreciated.

82
Change a few lines in disp_images.php
(Changes marked with //jesperts->)

Code: [Select]


<?php
// New in 0.8.1: Suggest images for an album or performer/artist based on API's from last.fm and Microsoft Bing.
require('logincheck.php');
if (!isset(
$_SESSION['admin']) || ($_SESSION['admin']<>'1')) {
header("Location: logout.php");
}

require_once(
"sql.php");
require_once(
"set_td_colors.php");
require_once(
"disp.php");
require_once(
'lastfm_lib.php');
// require_once('bing_lib.php'); 0.8.6: Abandoned M$ Bing (low free meter usage, too complex => simple not good enough!) :(
require_once('google_lib.php'); // 0.8.6: Introduced
require_once('configuration.php');

$special=only_digits($special); 
if ((
$type<>'album') && ($type<>'performer')) {
die();
}

if (!isset(
$act)) {
$act='suggest';
}



function 
store_it($url,$dir,$id) {
$data=file_get_contents($url);
$handle=fopen($dir.$id.'.jpg''w');
fwrite($handle,$data);
fclose($handle);
}


if (
$act=='replace') {
$dir='./covers/';
if ($type<>'album') {
$dir='./lastfm/';
}
store_it($new_img,$dir,$special);
$ref_url=$_SESSION['referer'];
unset($_SESSION['referer']);
echo '<script type="text/javascript" language="javascript">'
echo 'window.location.replace("'.$ref_url.'");';
echo '</script>';
die('<a href="'.$ref_url.'">'.$ref_url.'</a>');
}

if (
$act=='suggest') {
// We need to remember where we came from
$_SESSION['referer']=$_SERVER["HTTP_REFERER"];

// Build+execute query:
//jesperts ->
//$qry="SELECT * FROM ".$type." WHERE ";
$qry="SELECT * FROM album,performer WHERE album.aperformer_id = performer.pid and ";
//jesperts <-
$tid='aid';
if ($type=='performer') {
$tid='pid';
}
$qry.=$tid."=".$special// complete query: select * from (album|performer) where (aid|pid)='special'
$result=execute_sql($qry,0,1,$dummy); 
$row=mysql_fetch_array($result); // There's always just one row in this resultset.

print "\n\n\n <!-- CONTENT TABLE START --> \n\n\n";
echo '<table class="ampjuke_actions_table"><tr><td>';
// 0.8.4: Add a LINK BACK to the album we're trying to get a new image for:
// 0.8.5: Adjusted so this also works for PERFORMERS/ARTISTS:
$alink=$base_http_prog_dir.'/?what=albumid&start=0&count=15&special=';
if ($type=='performer') {
$alink=$base_http_prog_dir.'/?what=performerid&start=0&count=15&special='// 0.8.5
}

if ($type=='performer') {
$alink.=$row['pid'];
} else {
$alink.=$row['aid'];
}
// ...0.8.4 (cont): and use the link ($alink) next:
if ($type=='performer') {
echo 'Search results for the <b class="note"><a href="'.$alink.'">'.$type.': '.$row['pname'].'</a></b>. ';
} else {
echo 'Search results for the <b class="note"><a href="'.$alink.'">'.$type.': '.$row['aname'].'</a></b>. ';
}
echo 'Click on the image below you want to use</b></td></tr></table>';

// Grab some images from last.fm:
$a=lastfm_suggest_images($type,$row,$total_found);
if ($total_found>0) { // Found some piccies @ last.fm, - print 'em:
$x=0;
echo std_table("ampjuke_content_table","ampjuke_content");
echo '<tr>';
echo '<td colspan="8" align="center"><i>Search results powered by: <a href="http://www.last.fm/api/intro" target="_blank">';
echo 'Last.fm Web Services</td></tr><tr>';
while ($x<count($a)) {
echo '<td align="center">';
echo '<a href="index.php?what=images&type='.$type.'&special='.$special.'&act=replace&new_img='.$a[$x].'">';
echo '<img src="'.$a[$x].'" border="0" title="Click on this image to use it"></a><br>';
echo '</td>';
$x++;
}
echo '</tr></table>';
}





if (
$type=='performer') {
$q=urlencode($row['pname']);
} else {
//jesperts ->
//$q=urlencode($row['aname'].' ');
$q=urlencode($row['pname'].' ' .$row['aname'].' cover');
//jesperts <-

}
$g=google_construct_query($q);

$result=google_image_search($g);

$table2=1;
google_suggest_images($result,$type,$special);


// 0.8.6: M$ Bing: Not used anymore  - see above :(
// If we have a bing appid, then also suggest something from Bing:
/*
if (get_configuration('bing_appid')<>'') {
if ($type=='album') {
$bing_search=get_performer_name($row['aperformer_id']).' - '.$row['aname'];
}
if ($type=='performer') {
$bing_search='"'.$row['pname'].'" "artist"';
}
$a=bing_suggest_images($type,$row,get_configuration('bing_appid'),get_configuration('bing_preferred_size'),$bing_search,$total_found);
if ($total_found>0) { // Found pictures @ BING!. Print 'em:
$x=0;
echo std_table("ampjuke_content_table","ampjuke_content2"); 
$table2=1;
echo '<tr>';
echo '<td colspan="8" align="center"><i>Search results powered by: <a href="http://www.bing.com/developers" target="_blank">';
echo 'Microsoft Bing API 2.0</td></tr><tr>';
while ($x<count($a)) {
echo '<td align="center">';
echo '<a href="index.php?what=images&type='.$type.'&special='.$special.'&act=replace&new_img='.$a[$x].'">';
echo '<img src="'.$a[$x].'" border="0" title="Click on this image to use it"></a><br>';
echo '</td>';
$x++;
}
echo '</tr></table>';
}
}
*/

// Finally, always suggest the _blank images:
echo std_table("ampjuke_content_table","ampjuke_content3"); // Print'em:
$table3=1;
echo '<tr><td colspan="8" align="center">';
echo '<a href="index.php?what=images&type='.$type.'&special='.$special.'&act=replace&new_img=';
echo $base_http_prog_dir.'/covers/_blank.jpg">';
echo '<img src="'.$base_http_prog_dir.'/covers/_blank.jpg" border="0"></a><br>';
echo '</td></table>';

// Type an url - Jesper S 31.03.2010
echo std_table("ampjuke_content_table","ampjuke_content4");
$table4=1;
echo '<FORM name="replce_img" method="get" action="index.php?what=images&type='.$type.'&special='.$special.'&act=replace">';   
echo '<input type="hidden" name="what" value="images">';
echo '<input type="hidden" name="type" value="'.$type.'">';
echo '<input type="hidden" name="special" value="'.$special.'">';
echo '<input type="hidden" name="act" value="replace">';
echo '<tr><td>Url:</td><td colspan="3"><input type="text" class="tfield" name="new_img" size="60"></td></tr>';
echo '<tr><td align="center" colspan="4"><input type="submit" value="Use Url"></td></tr>';
echo '</FORM></table>';

// act==suggest

?>



83
Hacks, tips & tricks / Better search results from "scan metadata"
« Last post by jesperts on 29-08-2012 22:01 »
Change a few lines in scanmeta.php

Code: [Select]

<?php
// scanmeta.php: Scan+update "meta" information (ie. pictures) using M$ Bing!

require('logincheck.php');
if (!isset(
$_SESSION['admin']) || ($_SESSION['admin']<>'1')) {
header("Location: logout.php");
}

echo 
'<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/transitional.dtd">'
;
echo 
'<html xmlns="http://www.w3.org/1999/xhtml" lang="EN">';
echo 
'<head>';
require_once(
'db.php');

echo 
'<title>Scan+import metadata [AmpJuke...and YOUR hits keep on coming!]</title>';
echo 
'<meta http-equiv="Content-Type" content="text/html; charset="'.$charset.'" />';
//echo '<meta http-equiv="Refresh" content="1" />';
echo '<link rel="stylesheet" type="text/css" href="./css/'.$_SESSION['cssfile'].'" />'
echo 
'<script type="text/javascript" src="rowcols.js"></script>';
require_once(
'translate.php');
require_once(
'disp.php');
require_once(
'sql.php');
require_once(
'sql.php');
require_once(
'configuration.php'); 
require_once(
'set_td_colors.php');
require_once(
'tbl_header.php');
//require_once('bing_lib.php'); 0.8.6: M$ Bing! not used anymore: Low free meter usage + too complex.
require_once('google_lib.php');

// ***** CRON-SETTINGS:
// Want to run this using cron ?
// If yes, read on and uncomment+modify entries below:
/*
$_POST['get_album_images']='1'; // Uncomment if covers should be fetched.
$_POST['delete_album_images_wo_reference']='1'; // Uncomment to delete album-images wo. any reference in the database.
$_POST['album_preferred_dimension']=200; // Uncomment+change to whatever preferred size you want to look for.

$_POST['get_performer_images']='1'; // Uncomment if artist/performer images should be fetched.
$_POST['delete_performer_images_wo_reference']='1'; // Uncomment to delete performer images wo. any reference in the database.
$_POST['performer_preferred_dimension']=200; // Uncomment+change to whatever preferred size you want to look for.

$details='2'; // Uncomment+set a value of 1-4. 1=minimal output, 2=normal, 4=most.
$_POST['simulate_import']='1'; // Uncomment if you're a sissy :-) Well: doesnt make sense to simulate something in a CRON-script, right ?

$path_to_covers='/absolute/path/to/covers/WITH/slash/'; // Uncomment+set the absolute path to covers. Remember last slash...
$path_to_performers='/absolute/path/to/performers/WITH/slash/';  // Uncomment+set absolute path to performers. Remember last slash
*/
// ***** CRON-SETTINGS ends.

parse_str($_SERVER["QUERY_STRING"]);
if (!isset(
$act)) {
$act='setup';
}
$tdnorm='';
$tdalt='';
$tdhighlight='';
$count=0;
echo 
'<body>';
/*
******************************
SCAN (support functions below)
******************************
*/
function get_bing_id() {
return get_configuration('bing_appid');
}

function 
update_status($level,$details,$msg) {
 
if ($details>=$level) {
echo '<tr><td>'.$msg.'</td>';
print "</tr> \n";
@flush(); 
@ob_flush();
}
}



function 
store_it($url,$dir,$id,$details) {
$data=file_get_contents($url);
update_status('4',$details,'Storing data... From:'.$url.' To:'.$dir.$id.'.jpg');
$handle=fopen($dir.$id.'.jpg''w');
fwrite($handle,$data);
fclose($handle);
update_status('4',$details,'Stored!');
}


/*


ACTUAL PROCESSING:
*/


// "Generic" function to remove "what" (album or performer) images from "where" (=foldername):
function process_stuff_wo_reference($simulate_import,$details,$what,$where) {
// Read all images from "where", store in array:
update_status('2',$details,'Read all existing <b>'.$what.'</b> images from <b>'.$where.'</b>...');
$cover=array();
$i=0;
$d opendir($where);
while(($f readdir($d)) !== false) {
if(ereg('.jpg$'$f)) {
$cover[$i]=$f;
$i++;
}
}
closedir($d);
update_status('2',$details,'Number of existing <b>'.$what.'</b> images found: '.$i.' in '.$where);

// Process array, compare with id's in database, if id is not in database then delete the corresponding .jpg from the filesystem.
// Optional: If what=performer then try to delete XML file as well:
$victims=0;
$n=0;
while ($n<$i) {
$c=explode('.',$cover[$n]);
if (is_numeric($c[0])) {
if ($what=='album') {
$qry="SELECT aid FROM album WHERE aid=".$c[0];
}
if ($what=='performer') {
$qry="SELECT pid FROM performer WHERE pid=".$c[0];
}
$found=0;
$result=execute_sql($qry,0,1,$found);
update_status('4',$details,'QRY='.$qry.' FOUND='.$found);
if ($found==0) {
$victims++;
if (!is_writable($where.$c[0].'.jpg')) {
update_status('3',$details,'<b>Cannot remove '.$what.' image: '.$where.$c[0].'.</b> Not enough permission');
} else {
if ($simulate_import==0) {
unlink($where.$c[0].'.jpg');
}
update_status('3',$details,'Removed '.$what.' image: '.$c[0]);
}
// Optional: Remove XML-file associated with this performer:
if ($what=='performer') {
if (!is_writable($where.$c[0].'.xml')) {
update_status('3',$details,'<b>Cannot remove XML-file: '.$where.$c[0].'.xml.</b> Not enough permission');
} else {
if ($simulate_import==0) {
unlink($where.$c[0].'.xml');
}
update_status('3',$details.'Removed XML-file: '.$where.$c[0].'.xml');
}
}
}
}
$n++;
}
update_status('2',$details,'Number of <b>'.$what.'</b> images without reference: '.$victims);
}



function 
process_album_images($simulate_import,$details,$album_preferred_dimension,$path_to_covers,$use_blank_album_cover) {
$qry="SELECT * FROM album ORDER BY aname";
$result=execute_sql($qry,0,1000000,$dummy);
update_status('1',$details,'Number of albums to be scanned: '.$dummy);
while ($row=mysql_fetch_array($result)) {
update_status('4',$details,'Check: '.$row['aid'].' - '.$row['aname']);
if (!file_exists($path_to_covers.$row['aid'].'.jpg')) {
//jesperts->
//$s='"'.get_performer_name($row['aperformer_id']).' - '.$row['aname'].'"';
$s='"'.get_performer_name($row['aperformer_id']).' '.$row['aname'].'" +Cover';
//jesperts<-
update_status('3',$details,'No cover found for: '.$s.'. Ask Google...'); // 0.8.6
//$cover_url=bing_search(get_bing_id(),$s,3,$album_preferred_dimension,$album_preferred_dimension);
$cover_url=google_get_image_url($s);
update_status('3',$details,'Google returned: '.$cover_url);
if ($simulate_import==0) { // We're not kiddin': Do it:
if ($cover_url<>'') {
store_it($cover_url,$path_to_covers,$row['aid'],$details);
update_status('2',$details,'Found image for:'.$row['aname'].' at:'.$cover_url);
} else {
update_status('3',$details,'Nothing found - use blank image...');
store_it($path_to_covers.'_blank.jpg',$path_to_covers,$row['aid'],$details);
}
}
}
}
update_status('2',$details,'Done processing album images');
}


function 
process_performer_images($simulate_import,$details,$performer_preferred_dimension,$path_to_performers,
$use_blank_performer_cover) {
$qry="SELECT pid,pname FROM performer ORDER BY pname";
$result=execute_sql($qry,0,1000000,$dummy);
update_status('1',$details,'Number of performers to be scanned: '.$dummy);
while ($row=mysql_fetch_array($result)) {
if (strlen($row['pname'])>2) {
update_status('4',$details,'Check: '.$row['pid'].' - '.$row['pname']);
if (!file_exists($path_to_performers.$row['pid'].'.jpg')) {
//jesperts->
//$s='"'.$row['pname'].'" "artist"';
$s='"'.$row['pname'].'"';
//jesperts<-
update_status('3',$details,'No image found for: '.$row['pname'].'. Ask Google...');
//$cover_url=bing_search(get_bing_id(),$s,3,$performer_preferred_dimension,$performer_preferred_dimension);
$cover_url=google_get_image_url($s);
update_status('3',$details,'Google returned: '.$cover_url);
if ($simulate_import==0) {
if ($cover_url<>'') {
store_it($cover_url,$path_to_performers,$row['pid'],$details);
update_status('2',$details,'Found image for:'.$row['pname'].' at: '.$cover_url);
} else {
update_status('3',$details,'Nothing found - use blank image...');
store_it($path_to_performers.'_blank.jpg',$path_to_performers,$row['pid'],$details);
}
}
}
}
}
update_status('2',$details,'Done processing performer images');
}
/*
******************************
SCAN
******************************
*/
if ($act=='scan') {
set_time_limit(0); // Believe me: you want this !
error_reporting(0); // Believe me: you also want this ! Unfortunately...
$starttimer time()+microtime(); // Used to calc. the total duration

echo headline('','Scan+import meta data','');
echo std_table("ampjuke_content_table","ampjuke_content");
?>

<th colspan="3">Status</th>
<tr><td width="50%" valign="top"><p class="note">
Note: Bery very, very patient ! This might take a long time.</p>
<?php

// Setup what's POST'ed, display settings:
$details=$_POST['details'];
update_status('1',$details,'Detail level (1-4): '.$details);

update_status('1',$details,'Settings (1=activated, 0=not activated):');
$get_album_images=0;
if (isset($_POST['get_album_images'])) {
$get_album_images=1;
}
update_status('1',$details,'Lookup and store album images: '.$get_album_images);

$delete_album_images_wo_reference=0;
if (isset($_POST['delete_album_images_wo_reference'])) {
$delete_album_images_wo_reference=1;
}
update_status('1',$details,'Delete album images without any reference in the database: '.$delete_album_images_wo_reference);

$use_blank_album_cover=0;
if (isset($_POST['use_blank_album_cover'])) {
$use_blank_album_cover=1;
}
update_status('1',$details,'If no album cover is found, use a blank one: '.$use_blank_album_cover);

$get_performer_images=0;
if (isset($_POST['get_performer_images'])) {
$get_performer_images=1;
}
update_status('1',$details,'Lookup and store performer images: '.$get_performer_images);

$delete_performer_images_wo_reference=0;
if (isset($_POST['delete_performer_images_wo_reference'])) {
$delete_performer_images_wo_reference=1;
}
update_status('1',$details,'Delete performer images without any reference in the database: '.$delete_performer_images_wo_reference);

$use_blank_performer_cover=0;
if (isset($_POST['use_blank_performer_cover'])) {
$use_blank_performer_cover=1;
}
update_status('1',$details,'If no performer cover is found, use a blank one: '.$use_blank_performer_cover);

$simulate_import=0;
if (isset($_POST['simulate_import'])) {
$simulate_import=1;
update_status('1',$details,'<b>Note:</b> Simulation is turned on. Nothing will be changed.');
}
// Sets paths, unless already specified in CRON-settings above:
if (!isset($path_to_covers)) {
$path_to_covers='./covers/';
}
update_status('1',$details,'Path (absolute or relative) to album covers: '.$path_to_covers);

if (!isset($path_to_performers)) {
$path_to_performers='./lastfm/';
}
update_status('1',$details,'Path (absolute or relative) to performer images: '.$path_to_performers);

update_status('1',$details,'Start scan+import of metadata...');


// **************************************
//  GO !!!!!!
// **************************************
if ($get_album_images==1) {
update_status('2',$details,'Get album images checked...');
process_album_images($simulate_import,$details,$album_preferred_dimension,$path_to_covers);
}
if ($delete_album_images_wo_reference==1) {
update_status('2',$details,'Delete album images wo. reference...');
process_stuff_wo_reference($simulate_import,$details,'album',$path_to_covers);
}
if ($get_performer_images==1) {
update_status('2',$details,'Get performer images checked...');
process_performer_images($simulate_import,$details,$performer_preferred_dimension,$path_to_performers);
}
if ($delete_performer_images_wo_reference==1) {
update_status('2',$details,'Delete performer images wo. reference...');
process_stuff_wo_reference($simluate_import,$details,'performer',$path_to_performers);
}

update_status('1',$details,'Done');

$stoptimer time()+microtime();
$timer round($stoptimer-$starttimer,2);
    
$msg='<br><p>Scan+import finished after '.$timer.' seconds<br>';
    
$msg.='<a href="'.$base_http_prog_dir.'/';
$msg.='">Click here to go back to the "Welcome" page.</a>';
echo $msg;
update_status('1',$details,$msg);
}
/*
******************************
SET UP
******************************
*/
if ($act=='setup') {

// Setup: Options
 
echo '<FORM NAME="scanform" method="POST" action="scanmeta.php?act=scan">';
echo std_table("ampjuke_content_table","ampjuke_content");
echo '<th colspan="2">Scan metadata</th>';
echo '<tr><td align="left">';
echo '<a href="http://www.ampjuke.org/faq.php?q_id=77" target="_blank">';
echo 'Click here to see the FAQ-entry explaining this (will open in a new window)</a>';
echo '<td align="right"><i>Note:Search is powered by the <a href="http://www.google.com/" target="_blank">';
echo 'Google Search</a></i></td></tr>';

// General options:
// Bing! appid:
fancy_tr($tmpcount,$tdnorm,$tdalt,$tdhighlight);
echo '<td colspan=2" align="center"><b>Options</b></td></tr>';
// Write status messages to screen:
fancy_tr($tmpcount,$tdnorm,$tdalt,$tdhighlight);
echo '<td>Show details during scan+import:</td><td>';
echo '<SELECT NAME="details" class="tfield">';
echo add_select_option('1','Minimal: Very little ','');
echo add_select_option('2','Normal: Status on new albums,performers','1');
echo add_select_option('3','Detailed: Like "normal" plus more info.','');
echo add_select_option('4','Very detailed: A LOT of things will be shown. Really.','');
echo '</SELECT></td></tr>';
// Simulate:
fancy_tr($tmpcount,$tdnorm,$tdalt,$tdhighlight);
echo "<td>Simulate import (don't change/alter anything):</td><td>";
echo add_checkbox('simluate_import','').'</td></tr>';

// Get album images ?
fancy_tr($tmpcount,$tdnorm,$tdalt,$tdhighlight);
echo '<td colspan=2" align="center"><b>Album options</b></td></tr>';
fancy_tr($tmpcount,$tdnorm,$tdalt,$tdhighlight);
echo '<td>Get album images:</td>';
echo '<td>'.add_checkbox('get_album_images','1');
echo '</td></tr>';
// If none found, use _blank.jpg:
fancy_tr($tmpcount,$tdnorm,$tdalt,$tdhighlight);
echo '<td>If no cover image is found, use a blank one:</td>';
echo '<td>'.add_checkbox('use_blank_album_cover','').'</td></tr>';
// Delete album images without reference:
fancy_tr($tmpcount,$tdnorm,$tdalt,$tdhighlight);
echo '<td>Delete album images without a reference:</td>';
echo '<td>'.add_checkbox('delete_album_images_wo_reference','').'</td></tr>';

// Get performer images, preferred size:
fancy_tr($tmpcount,$tdnorm,$tdalt,$tdhighlight);
echo '<td colspan=2" align="center"><b>Performer options</b></td></tr>';
fancy_tr($tmpcount,$tdnorm,$tdalt,$tdhighlight);
echo '<td>Get performer images:</td>';
echo '<td>'.add_checkbox('get_performer_images','1');
echo '</td></tr>';
// If none found, use _blank.jpg:
fancy_tr($tmpcount,$tdnorm,$tdalt,$tdhighlight);
echo '<td>If no performer image is found, use a blank one:</td>';
echo '<td>'.add_checkbox('use_blank_performer_cover','').'</td></tr>';
// Delete performer images without reference:
fancy_tr($tmpcount,$tdnorm,$tdalt,$tdhighlight);
echo '<td>Delete performer images without a reference:</td>';
echo '<td>'.add_checkbox('delete_performer_images_wo_reference','').'</td></tr>';

// 
fancy_tr($tmpcount,$tdnorm,$tdalt,$tdhighlight);
echo '<td colspan="2" align="center">';
echo '<input type="submit" value="Start scan+import"></td></tr>';
// Jump back -> "Welcome":
fancy_tr($tmpcount,$tdnorm,$tdalt,$tdhighlight);
echo '<td colspan="2"><a href="index.php?what=welcome">';
echo '<img src="./ampjukeicons/mnu_arr.gif" border="0"> ';
echo 'Do not do anything, just step back to the "Welcome" page</a>';
echo '</td></tr>';
echo '</table></form>';
}



?>

<script type="text/javascript">
addTableRolloverEffect('ampjuke_content','tableRollOverEffect','');
</script>
</body></html>


84
Announcements / Finally (finally!) got a new community up&running!
« Last post by Michael on 22-08-2012 20:08 »
After a rather long time with the old forum left in an in-active state, I have - finally - found the time (and the code) to start a new AmpJuke community (forum).
The old forum is still available for reference here.

If you've registered in the old forum, you need to register again. Sorry for the inconvenience.

//Michael.
Pages: 1 ... 4 5 6 7 8 [9]