-
Notifications
You must be signed in to change notification settings - Fork 9
/
filldb.php
110 lines (85 loc) · 2.26 KB
/
filldb.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
<?php
error_reporting(E_ALL);
$_PATH['classes'] = 'classes/';
include_once($_PATH['classes'].'Artists.class.php');
include_once($_PATH['classes'].'Config.class.php');
$nbInsert = 0;
function artistExist($name) {
$db = Config::$dbInstance;
//Manual query to avoid loading all the column
$sql = "SELECT name ".
"FROM lastfm_artists where name = ?";
$it = $db->execQueryIterator($sql,array($name));
if($line = $it->getNext()) {
return true;
}
else {
return false;
}
}
function loadLogos($dir)
{
if(!is_dir($dir))
{
echo "Invalid directory";
}
else
{
global $nbInsert;
global $_PATH;
if($handle = opendir($dir))
{
while(($file = readdir($handle)) !== false)
{
///---Extraction
$parts = explode('.',$file);
$ext = array_pop($parts);
///---Valid formats
if(!($ext == 'gif' || $ext == 'jpg' || $ext == 'png'))
continue;
///---Name repack
$name = join(".",$parts);
$name = str_replace('__','.',$name);
$name = str_replace('_','%',$name);
///---Extra Validations
//Check for special caracters not encoded
if(strpos($name,'_') !== false || strpos($name,' ') !== false)
{
echo "<b>".$name." sould be rename to ".
str_replace(array('_',' '),array('+','+'),$name).".</b><br/>";
continue;
}
else if(strpos($name,'%') === false){
$nameCheck = urlencode(str_replace(array('+'),array(''),$name)); //Char excludes
//Some caracter are not support yet
if(strpos($nameCheck,'%') !== false){
echo "<b>".$name." is not properly parse.</b><br/>";
continue;
}
}
$prev = $name;
///---Insert in db
if(artistExist($name)) {
continue;
}
echo $name." - ";
$newDate=filemtime(Config::FOLDER_LOGOS.$file); //Date of modification (new file)
$newArtist = new Artist($name,$file,"",-1,$newDate);
Artists::addArtist($newArtist);
$nbInsert++;
}
closedir($handle);
}
}
}
//--Ini
set_time_limit(360);
$start = microtime(true);
//--Empty list
if(isset($_GET['clear']))
Artists::emptyList();
//--Fill db base on the file this folder
loadLogos(Config::FOLDER_LOGOS);
$end = microtime(true);
echo $nbInsert." artists inserted in ".round(($end - $start),3)." sec.";
?>