Switch to composer getID3 lib. Add SIMULATE arg/mode. Add vim modeline.
This commit is contained in:
		
							parent
							
								
									d3d8e6c421
								
							
						
					
					
						commit
						7ad5c67a77
					
				| 
						 | 
					@ -1,8 +1,14 @@
 | 
				
			||||||
<?php
 | 
					<?php
 | 
				
			||||||
 | 
					
 | 
				
			||||||
require_once 'getid3/getid3.php';
 | 
					//require_once 'getid3/getid3.php';
 | 
				
			||||||
 | 
					require_once '../vendor/autoload.php';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
$ini = parse_ini_file("/etc/homeaudio.ini");
 | 
					$ini = parse_ini_file("/etc/homeaudio.ini");
 | 
				
			||||||
 | 
					if ( isset($argv[1]) && ($argv[1] == "simulate") ) {
 | 
				
			||||||
 | 
					   define("SIMULATE", true);
 | 
				
			||||||
 | 
					} else {
 | 
				
			||||||
 | 
					   define("SIMULATE", false);
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
define("MP3ROOTDIR", $ini['MP3DIR']);
 | 
					define("MP3ROOTDIR", $ini['MP3DIR']);
 | 
				
			||||||
define("ARTDIR", $ini['ARTDIR']);
 | 
					define("ARTDIR", $ini['ARTDIR']);
 | 
				
			||||||
| 
						 | 
					@ -40,7 +46,11 @@ function pruneDB() {
 | 
				
			||||||
      if ( !file_exists(MP3ROOTDIR . $row['path'] . $row['song']) ) {
 | 
					      if ( !file_exists(MP3ROOTDIR . $row['path'] . $row['song']) ) {
 | 
				
			||||||
         $fieldsdel = array();
 | 
					         $fieldsdel = array();
 | 
				
			||||||
         $fieldsdel[':id'] = $row['id'];
 | 
					         $fieldsdel[':id'] = $row['id'];
 | 
				
			||||||
 | 
					         if ( SIMULATE ) {
 | 
				
			||||||
 | 
					            echo "Would have removed: {$row['song']}\n";
 | 
				
			||||||
 | 
					         } else {
 | 
				
			||||||
            $sthdel->execute($fieldsdel);
 | 
					            $sthdel->execute($fieldsdel);
 | 
				
			||||||
 | 
					         }
 | 
				
			||||||
         $prunecount++;
 | 
					         $prunecount++;
 | 
				
			||||||
      }
 | 
					      }
 | 
				
			||||||
   }
 | 
					   }
 | 
				
			||||||
| 
						 | 
					@ -59,16 +69,24 @@ function addNewSongs($path = "") {
 | 
				
			||||||
         if ( substr($entry, -3) != "mp3" ) continue;
 | 
					         if ( substr($entry, -3) != "mp3" ) continue;
 | 
				
			||||||
         $song = $path . $entry;
 | 
					         $song = $path . $entry;
 | 
				
			||||||
         $fields = array();
 | 
					         $fields = array();
 | 
				
			||||||
         $fields[':path'] = $path;
 | 
					         $fields[':path'] = mb_convert_encoding($path, "UTF-8");
 | 
				
			||||||
         $fields[':song'] = $entry;
 | 
					         $fields[':song'] = mb_convert_encoding($entry, "UTF-8");
 | 
				
			||||||
 | 
					         try {
 | 
				
			||||||
            $sth_exists->execute($fields);
 | 
					            $sth_exists->execute($fields);
 | 
				
			||||||
 | 
					         } catch ( Exception $e ) {
 | 
				
			||||||
 | 
					            echo "Could not query database for song: {$path}/{$entry}\n";
 | 
				
			||||||
 | 
					         }
 | 
				
			||||||
         if ( $sth_exists->fetchColumn() == 0 ) {
 | 
					         if ( $sth_exists->fetchColumn() == 0 ) {
 | 
				
			||||||
            $newcount++;
 | 
					            $newcount++;
 | 
				
			||||||
            if ( ($newcount % 1000) == 0 ) echo ".";
 | 
					            if ( ($newcount % 1000) == 0 ) echo ".";
 | 
				
			||||||
 | 
					            if ( SIMULATE ) {
 | 
				
			||||||
 | 
					               echo "Would have added: {$fields[':path']}/{$fields[':song']}\n";
 | 
				
			||||||
 | 
					            } else {
 | 
				
			||||||
               $sth_addnew->execute($fields);
 | 
					               $sth_addnew->execute($fields);
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
         }
 | 
					         }
 | 
				
			||||||
      }
 | 
					      }
 | 
				
			||||||
 | 
					   }
 | 
				
			||||||
   closedir($fh);
 | 
					   closedir($fh);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -118,12 +136,14 @@ function parseSongs() {
 | 
				
			||||||
            $fields[':artfile'] = $artmd5 . "." . $extbymimetypes[$mimetype];
 | 
					            $fields[':artfile'] = $artmd5 . "." . $extbymimetypes[$mimetype];
 | 
				
			||||||
         }
 | 
					         }
 | 
				
			||||||
      }
 | 
					      }
 | 
				
			||||||
 | 
					      if ( !SIMULATE ) {
 | 
				
			||||||
         if ( ($fields[':artfile'] != "") && !file_exists(ARTDIR . $fields[':artfile']) ) {
 | 
					         if ( ($fields[':artfile'] != "") && !file_exists(ARTDIR . $fields[':artfile']) ) {
 | 
				
			||||||
            file_put_contents(ARTDIR . $fields[':artfile'], $info['comments']['picture'][0]['data']);
 | 
					            file_put_contents(ARTDIR . $fields[':artfile'], $info['comments']['picture'][0]['data']);
 | 
				
			||||||
         }
 | 
					         }
 | 
				
			||||||
 | 
					         $sth_info->execute($fields);
 | 
				
			||||||
 | 
					      }
 | 
				
			||||||
      $parsecount++;
 | 
					      $parsecount++;
 | 
				
			||||||
      if ( ($parsecount % 1000) == 0 ) echo ".";
 | 
					      if ( ($parsecount % 1000) == 0 ) echo ".";
 | 
				
			||||||
      $sth_info->execute($fields);
 | 
					 | 
				
			||||||
   }
 | 
					   }
 | 
				
			||||||
   return $parsecount;
 | 
					   return $parsecount;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
| 
						 | 
					@ -157,7 +177,7 @@ addNewSongs();
 | 
				
			||||||
echo " ", $newcount, " songs added.\n";
 | 
					echo " ", $newcount, " songs added.\n";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
echo "Parsing ID3 tags...";
 | 
					echo "Parsing ID3 tags...";
 | 
				
			||||||
$parsecount = parseSongs();
 | 
					//$parsecount = parseSongs();
 | 
				
			||||||
echo " ", $parsecount, " tags parsed.\n";
 | 
					//echo " ", $parsecount, " tags parsed.\n";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
?>
 | 
					// vim: set et ts=3 sw=3 ai mouse-=a:
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue
	
	Block a user