-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsam-reconstruct.php
More file actions
76 lines (54 loc) · 1.87 KB
/
sam-reconstruct.php
File metadata and controls
76 lines (54 loc) · 1.87 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
75
76
<?php
require_once("CONFIG.php");
require_once("helpers.php");
require_once("buildscript.php");
//above script reads $target_db_name and populates $creation_script
$error = '';
$start_time = time();
$result = execute_sql($db, $creation_script);
if ($result == '') {
echo "database '".$target_db_name."' created succesfully! Now adding music...<hr>";
} else {
$error .= "An error occurred during db creation! ".mysqli_error($db);
}
is_dir($library_root)? : $error .= "source directory cannot be found. Looking for '".$library_root."'. ";
is_readable($library_root)? : $error .= "source directory not readable: '".$library_root."'. ";
// writeable test returns false positive (returns true when it is actually writeable)
// is_writable($destination)? : $error .= "destination directory cannot be written to. Trying to write to '".$destination."'. ";
$count = 0;
if($error == '') {
$start_time = time();
$file_list = [];
process_dir($library_root); //populates file_list array
foreach ($file_list as $k => $file){
$song = extractFromTags($file);
$arr = mbStringToArray($file);
echo '<pre>';
echo mb_detect_encoding($file);
print_r($arr);
echo'</pre>';
$song['filename'] = $file;
$result = ingest_song($db, $song);
if ( $result == 1 ){
echo $song['artist']." - ".$song['title']." ingested successfully <br/>";
} else {
echo mysqli_error($db);
}
}
$end_time = time();
$diff = $end_time - $start_time;
echo 'took '.$diff.' seconds to scan '.$count.' files';
} else {
echo $error;
}
function mbStringToArray ($string) {
$array = [];
$strlen = strlen($string);
while ($strlen) {
$array[] = substr($string,0,1);
$string = substr($string,1,$strlen);
$strlen = strlen($string);
}
return $array;
}