From 76e5b24bdca0aa33eb3039c2ac3e5f879583b820 Mon Sep 17 00:00:00 2001 From: buttle Date: Sun, 27 Jun 2021 13:31:31 +0200 Subject: [PATCH] adds thumbnail download to media ingester --- README.md | 2 ++ src/Media/Ingester/ArchiveOrgMediaIngester.php | 17 +++++++++++++++-- .../Media/Ingester/ArchiveOrgMediaFactory.php | 5 ++++- 3 files changed, 21 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 537f98a..411fd2a 100644 --- a/README.md +++ b/README.md @@ -9,6 +9,8 @@ video and audio media. cd ./modules https://git.hangar.org/arcHIVE-tech/ArchiveOrg/archive/main.zip unzip main.zip +mv archiveorg/ ArchiveOrg +rm main.zip ``` ## LISENCE diff --git a/src/Media/Ingester/ArchiveOrgMediaIngester.php b/src/Media/Ingester/ArchiveOrgMediaIngester.php index 8801982..03fdf3f 100644 --- a/src/Media/Ingester/ArchiveOrgMediaIngester.php +++ b/src/Media/Ingester/ArchiveOrgMediaIngester.php @@ -5,16 +5,20 @@ use Omeka\Api\Request; use Omeka\Entity\Media; use Omeka\Media\Ingester\IngesterInterface; use Omeka\Stdlib\ErrorStore; +use Omeka\File\Downloader; use Zend\Form\Element\Text; use Zend\Http\Client; use Zend\View\Renderer\PhpRenderer; class ArchiveOrgMediaIngester implements IngesterInterface { + protected $downloader; protected $client; - public function __construct($client) + + public function __construct($client, Downloader $downloader) { $this->client = $client; + $this->downloader = $downloader; } public function getLabel() { @@ -43,7 +47,16 @@ class ArchiveOrgMediaIngester implements IngesterInterface $errorStore->addError('o:identifier', 'No identifier specified'); return; } - $url = 'https://archive.org/embed/' . $data['o:identifier']; + $identifier = trim($data['o:identifier']); + $mediaData = ['identifier' => $identifier]; + + $url = 'https://archive.org/embed/' . $identifier; + $thumbnail_url = 'https://archive.org/services/img/' . $identifier; + $tempFile = $this->downloader->download($thumbnail_url); + if ($tempFile) { + $tempFile->mediaIngestFile($media, $request, $errorStore, false); + } + $media->setData($mediaData); $media->setSource($url); } } diff --git a/src/Service/Media/Ingester/ArchiveOrgMediaFactory.php b/src/Service/Media/Ingester/ArchiveOrgMediaFactory.php index 63df9a2..9286c75 100644 --- a/src/Service/Media/Ingester/ArchiveOrgMediaFactory.php +++ b/src/Service/Media/Ingester/ArchiveOrgMediaFactory.php @@ -11,6 +11,9 @@ class ArchiveOrgMediaFactory implements FactoryInterface $requestedName, array $options = null) { - return new ArchiveOrgMediaIngester($services->get('Omeka\HttpClient')); + return new ArchiveOrgMediaIngester( + $services->get('Omeka\HttpClient'), + $services->get('Omeka\File\Downloader') + ); } }