parent
e1f5495bd2
commit
354a03b34a
File diff suppressed because it is too large
Load Diff
@ -0,0 +1 @@
|
||||
8
|
@ -0,0 +1,31 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace DoctrineMigrations;
|
||||
|
||||
use Doctrine\DBAL\Schema\Schema;
|
||||
use Doctrine\Migrations\AbstractMigration;
|
||||
|
||||
/**
|
||||
* Auto-generated Migration: Please modify to your needs!
|
||||
*/
|
||||
final class Version20211217152806 extends AbstractMigration
|
||||
{
|
||||
public function getDescription(): string
|
||||
{
|
||||
return '';
|
||||
}
|
||||
|
||||
public function up(Schema $schema): void
|
||||
{
|
||||
// this up() migration is auto-generated, please modify it to your needs
|
||||
$this->addSql('CREATE TABLE song (id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, path VARCHAR(2048) NOT NULL, artist VARCHAR(2048) DEFAULT NULL, album VARCHAR(2048) DEFAULT NULL, name VARCHAR(2048) DEFAULT NULL, filehash VARCHAR(2048) NOT NULL, release_year INTEGER DEFAULT NULL)');
|
||||
}
|
||||
|
||||
public function down(Schema $schema): void
|
||||
{
|
||||
// this down() migration is auto-generated, please modify it to your needs
|
||||
$this->addSql('DROP TABLE song');
|
||||
}
|
||||
}
|
@ -0,0 +1,17 @@
|
||||
<?php
|
||||
|
||||
namespace App\Adapter;
|
||||
|
||||
use SplFileInfo;
|
||||
|
||||
class ScannedSong
|
||||
{
|
||||
|
||||
public string $path;
|
||||
public SplFileInfo $file;
|
||||
public string $artist;
|
||||
public string $album;
|
||||
public string $title;
|
||||
public float $duration;
|
||||
|
||||
}
|
@ -0,0 +1,60 @@
|
||||
<?php
|
||||
|
||||
namespace App\Adapter;
|
||||
|
||||
use FilesystemIterator;
|
||||
use RecursiveDirectoryIterator;
|
||||
use RecursiveIteratorIterator;
|
||||
use SplFileInfo;
|
||||
use wapmorgan\Mp3Info\Mp3Info;
|
||||
use function Lambdish\Phunctional\filter;
|
||||
use function Lambdish\Phunctional\map;
|
||||
use function Lambdish\Phunctional\pipe;
|
||||
|
||||
class SongScanner
|
||||
{
|
||||
|
||||
private string $rootDir;
|
||||
|
||||
public function __construct(string $rootDir) {
|
||||
$this->rootDir = $rootDir;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return ScannedSong[]
|
||||
*/
|
||||
public function scanFunctional(): array {
|
||||
$it = new RecursiveDirectoryIterator(
|
||||
$this->rootDir,
|
||||
FilesystemIterator::FOLLOW_SYMLINKS | FilesystemIterator::SKIP_DOTS
|
||||
);
|
||||
|
||||
$pipe = pipe([$this, 'isMp3'], [$this, 'toScannedFile']);
|
||||
return $pipe(new RecursiveIteratorIterator($it));
|
||||
}
|
||||
|
||||
public static function isMp3(iterable $files): iterable {
|
||||
return filter(function (SplFileInfo $file, string $_): bool {
|
||||
echo $_ . "\n";
|
||||
return $file->isFile() && strtolower($file->getExtension()) === 'mp3';
|
||||
}, $files);
|
||||
}
|
||||
|
||||
public static function toScannedFile(iterable $files): iterable {
|
||||
return map(
|
||||
function (SplFileInfo $file, string $path): ScannedSong {
|
||||
$song = new ScannedSong();
|
||||
$song->file = $file;
|
||||
$song->path = $path;
|
||||
|
||||
$id3 = new Mp3Info($path, true);
|
||||
$song->artist = $id3->tags['artist'] ?: '';
|
||||
$song->album = $id3->tags['album'] ?: '';
|
||||
$song->title = $id3->tags['song'] ?: '';
|
||||
$song->duration = $id3->duration ?: 0;
|
||||
|
||||
return $song;
|
||||
}, $files);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,20 @@
|
||||
<?php
|
||||
|
||||
namespace App\Controller;
|
||||
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\Routing\Annotation\Route;
|
||||
|
||||
class Home extends AbstractController
|
||||
{
|
||||
|
||||
#[Route(path: '/home')]
|
||||
public function home(): Response {
|
||||
return $this->render(
|
||||
'home.html.twig',
|
||||
[]
|
||||
);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,97 @@
|
||||
<?php
|
||||
|
||||
namespace App\Entity;
|
||||
|
||||
use App\Repository\SongRepository;
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
|
||||
#[ORM\Entity(repositoryClass: SongRepository::class)]
|
||||
class Song
|
||||
{
|
||||
#[ORM\Id]
|
||||
#[ORM\GeneratedValue]
|
||||
#[ORM\Column(type: 'integer')]
|
||||
private int $id;
|
||||
|
||||
#[ORM\Column(type: 'string', length: 2048)]
|
||||
private string $path;
|
||||
|
||||
#[ORM\Column(type: 'string', length: 2048, nullable: true)]
|
||||
private ?string $artist;
|
||||
|
||||
#[ORM\Column(type: 'string', length: 2048, nullable: true)]
|
||||
private ?string $album;
|
||||
|
||||
#[ORM\Column(type: 'string', length: 2048, nullable: true)]
|
||||
private ?string $name;
|
||||
|
||||
#[ORM\Column(type: 'string', length: 2048)]
|
||||
private string $filehash;
|
||||
|
||||
#[ORM\Column(type: 'integer', nullable: true)]
|
||||
private int $releaseYear;
|
||||
|
||||
public function getId(): ?int {
|
||||
return $this->id;
|
||||
}
|
||||
|
||||
public function getPath(): ?string {
|
||||
return $this->path;
|
||||
}
|
||||
|
||||
public function setPath(string $path): self {
|
||||
$this->path = $path;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getArtist(): ?string {
|
||||
return $this->artist;
|
||||
}
|
||||
|
||||
public function setArtist(?string $artist): self {
|
||||
$this->artist = $artist;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getAlbum(): ?string {
|
||||
return $this->album;
|
||||
}
|
||||
|
||||
public function setAlbum(?string $album): self {
|
||||
$this->album = $album;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getName(): ?string {
|
||||
return $this->name;
|
||||
}
|
||||
|
||||
public function setName(?string $name): self {
|
||||
$this->name = $name;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getFilehash(): ?string {
|
||||
return $this->filehash;
|
||||
}
|
||||
|
||||
public function setFilehash(string $filehash): self {
|
||||
$this->filehash = $filehash;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getReleaseYear(): ?int {
|
||||
return $this->releaseYear;
|
||||
}
|
||||
|
||||
public function setReleaseYear(?int $releaseYear): self {
|
||||
$this->releaseYear = $releaseYear;
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
@ -0,0 +1,49 @@
|
||||
<?php
|
||||
|
||||
namespace App\Repository;
|
||||
|
||||
use App\Entity\Song;
|
||||
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
|
||||
use Doctrine\Persistence\ManagerRegistry;
|
||||
|
||||
/**
|
||||
* @method Song|null find($id, $lockMode = null, $lockVersion = null)
|
||||
* @method Song|null findOneBy(array $criteria, array $orderBy = null)
|
||||
* @method Song[] findAll()
|
||||
* @method Song[] findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null)
|
||||
*/
|
||||
class SongRepository extends ServiceEntityRepository
|
||||
{
|
||||
public function __construct(ManagerRegistry $registry) {
|
||||
parent::__construct($registry, Song::class);
|
||||
}
|
||||
|
||||
// /**
|
||||
// * @return Song[] Returns an array of Song objects
|
||||
// */
|
||||
/*
|
||||
public function findByExampleField($value)
|
||||
{
|
||||
return $this->createQueryBuilder('s')
|
||||
->andWhere('s.exampleField = :val')
|
||||
->setParameter('val', $value)
|
||||
->orderBy('s.id', 'ASC')
|
||||
->setMaxResults(10)
|
||||
->getQuery()
|
||||
->getResult()
|
||||
;
|
||||
}
|
||||
*/
|
||||
|
||||
/*
|
||||
public function findOneBySomeField($value): ?Song
|
||||
{
|
||||
return $this->createQueryBuilder('s')
|
||||
->andWhere('s.exampleField = :val')
|
||||
->setParameter('val', $value)
|
||||
->getQuery()
|
||||
->getOneOrNullResult()
|
||||
;
|
||||
}
|
||||
*/
|
||||
}
|
@ -0,0 +1 @@
|
||||
olla D:
|
Binary file not shown.
@ -0,0 +1,16 @@
|
||||
<?php
|
||||
|
||||
namespace App\Tests\Adapter;
|
||||
|
||||
use App\Adapter\SongScanner;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
class SongScannerTest extends TestCase
|
||||
{
|
||||
|
||||
function testDefaultBehaviourFunctional() {
|
||||
$scanner = new SongScanner(__DIR__);
|
||||
$songs = $scanner->scanFunctional();
|
||||
var_dump($songs);
|
||||
}
|
||||
}
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading…
Reference in new issue