Skip to content

Commit

Permalink
Fix uploading thumbnails to YouTube
Browse files Browse the repository at this point in the history
  • Loading branch information
Martin de Keijzer committed May 7, 2020
1 parent eeb265d commit 4f67ad1
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 12 deletions.
4 changes: 2 additions & 2 deletions EventListener/ThumbnailUploadListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,11 @@ public function postLoad(LifecycleEventArgs $args): void
return;
}

$thumbnail = $entity->getThumbnail();
$thumbnail = (string) $entity->getThumbnail();

if (null !== $thumbnail) {
$entity->setThumbnail(
new File($this->uploadService->getTargetDirectory().DIRECTORY_SEPARATOR.$thumbnail, false)
new File($thumbnail, false)
);
}
}
Expand Down
2 changes: 1 addition & 1 deletion Service/ChannelApi/Client/YouTubeClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ public function addThumbnailToBroadcast(\Google_Service_YouTube_LiveBroadcast $y
}

$chunkSizeBytes = (1 * 1024 * 1024);
$client = $this->googleClient->getClient();
$client = $this->youTubeClient->getClient();

if (!$client) {
return false;
Expand Down
6 changes: 1 addition & 5 deletions Tests/EventListener/ThumbnailUploadListenerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -135,11 +135,7 @@ public function testPostLoad(): void
$objectManager = $this->createMock(ObjectManager::class);
$liveBroadcast = new LiveBroadcast();

$liveBroadcast->setThumbnail('thumbnail.jpg');

$this->uploadService->expects(static::once())
->method('getTargetDirectory')
->willReturn('/tmp/dir');
$liveBroadcast->setThumbnail('/tmp/dir/thumbnail.jpg');

$args = new LifecycleEventArgs($liveBroadcast, $objectManager);
$this->eventListener->postLoad($args);
Expand Down
7 changes: 3 additions & 4 deletions Tests/Service/ChannelApi/Client/YouTubeClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -414,17 +414,16 @@ public function testAddThumbnailToBroadcast(): void
->method('execute')
->willReturn(new Response(200, ['location' => 'test']));

$this->google->expects(self::atLeastOnce())
->method('getClient')
->willReturn($googleClient);

$thumbnails = $this->createMock(\Google_Service_YouTube_Resource_Thumbnails::class);
$thumbnails->expects(self::atLeastOnce())
->method('set')
->with('youtube.id')
->willReturn(new Request('get', 'test_upload'));

$client = $this->createMock(\Google_Service_YouTube::class);
$client->expects(self::atLeastOnce())
->method('getClient')
->willReturn($googleClient);
$client->thumbnails = $thumbnails;

$youtube = new YouTubeClient($this->config, $this->google);
Expand Down

0 comments on commit 4f67ad1

Please sign in to comment.