-
Notifications
You must be signed in to change notification settings - Fork 0
/
import.php
89 lines (70 loc) · 2.56 KB
/
import.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
<?php
use MagicObject\Database\PicoDatabase;
use MagicObject\Database\PicoDatabaseQueryBuilder;
use MusicProductionManager\Data\Entity\SongDraft;
use MusicProductionManager\File\FileMp3;
use MusicProductionManager\Utility\SongFileUtil;
require_once "inc/app.php";
/**
* Insert song draft
*
* @param PicoDatabase $database
* @param string $path
* @return PicoDatabaseQueryBuilder
*/
function insertSongDraft($database, $path)
{
$baseName = basename($path);
$withoutExt = preg_replace('/\.\w+$/', '', $baseName);
$arr = explode("_", $withoutExt);
if(count($arr) > 5)
{
$timestamp = strtotime($arr[0]."-".$arr[1]."-".$arr[2]." ".$arr[3].":".$arr[4].":".$arr[5]);
$now = date("Y-m-d H:i:s", $timestamp);
$songDraftId = SongFileUtil::generateNewId($timestamp);
$filePath = "/var/www/html/studio/production/files/draft/$songDraftId/$songDraftId".".mp3";
$tempMath = __DIR__ . "/files/draft/$songDraftId/$songDraftId".".mp3";
$songDraft = new SongDraft(null, $database);
$randomId = $timestamp * 1000;
try
{
$songDraft->findOneByRandomId($randomId);
$query = $songDraft->saveQuery();
//copy($path, $tempMath);
return $query;
}
catch(Exception $e)
{
$songDraft = new SongDraft(null, $database);
$songDraft->setSongDraftId($songDraftId);
$songDraft->setRandomId($randomId);
$songDraft->setName($now);
$songDraft->setTimeCreate($now);
$songDraft->setTimeEdit($now);
$songDraft->setFileSize(filesize($path));
$songDraft->setFilePath($filePath);
$songDraft->setSha1File(sha1_file($path));
// get MP3 duration
$mp3file = new FileMp3($path);
$duration = $mp3file->getDuration();
$songDraft->setDuration($duration);
$songDraft->setActive(true);
$query = $songDraft->insertQuery();
$database->execute($query);
/*
if(!file_exists(dirname($tempMath)))
{
mkdir(dirname($tempMath), 0755, true);
}
copy($path, $tempMath);
*/
return $query;
}
}
return new PicoDatabaseQueryBuilder($database);
}
$files = glob(dirname(__DIR__)."/raw/*.mp3");
foreach($files as $file)
{
echo insertSongDraft($database, $file)."\r\n\r\n";
}