1
0
mirror of https://github.com/devfake/flox.git synced 2024-11-15 06:32:34 +01:00

Update genre (#28)

* remove update genre info text

* update genre for all movies and tv shows

* fix method comment
This commit is contained in:
Viktor Geringer 2017-01-25 11:17:46 +01:00 committed by Tim Meier
parent 96cb94f2ed
commit 42f9acd327
13 changed files with 281 additions and 25 deletions

View File

@ -93,8 +93,9 @@
return version_compare($this->version, $lastestVersion, '<') ? 'true' : 'false'; return version_compare($this->version, $lastestVersion, '<') ? 'true' : 'false';
} }
/** /**
* Parse full genre list of all movies in database and save them. * Parse full genre list of all movies and tv shows in our database and save them.
* *
* @param TMDB $tmdb * @param TMDB $tmdb
*/ */
@ -104,18 +105,13 @@
$items = $this->item->all(); $items = $this->item->all();
foreach($items as $item) { $items->each(function($item) use ($tmdb) {
if( ! $item->genre) { $genres = $tmdb->details($item->tmdb_id, $item->media_type)->genres;
$data = []; $data = collect($genres)->pluck('name')->all();
$genres = $tmdb->movie($item->tmdb_id)->genres;
foreach($genres as $genre) {
$data[] = $genre->name;
}
$item->genre = implode($data, ', '); $item->genre = implode($data, ', ');
$item->save(); $item->save();
} });
}
} }
/** /**

View File

@ -163,14 +163,15 @@
} }
/** /**
* Get full movie details. * Get full movie or tv details.
* *
* @param $tmdb_id * @param $tmdbId
* @param $mediaType
* @return mixed * @return mixed
*/ */
public function movie($tmdb_id) public function details($tmdbId, $mediaType)
{ {
$response = $this->client->get($this->base . '/3/movie/' . $tmdb_id, [ $response = $this->client->get($this->base . '/3/' . $mediaType . '/' . $tmdbId, [
'query' => [ 'query' => [
'api_key' => $this->apiKey, 'api_key' => $this->apiKey,
'language' => strtolower($this->translation) 'language' => strtolower($this->translation)
@ -183,7 +184,7 @@
// After 10 seconds the TMDB request limit is resetted. // After 10 seconds the TMDB request limit is resetted.
sleep(10); sleep(10);
return $this->movie($tmdb_id); return $this->details($tmdbId, $mediaType);
} }
/** /**

View File

@ -1,6 +1,11 @@
<?php <?php
use App\Item;
use App\Setting; use App\Setting;
use GuzzleHttp\Client;
use GuzzleHttp\Handler\MockHandler;
use GuzzleHttp\HandlerStack;
use GuzzleHttp\Psr7\Response;
use Illuminate\Foundation\Testing\DatabaseMigrations; use Illuminate\Foundation\Testing\DatabaseMigrations;
class SettingTest extends TestCase { class SettingTest extends TestCase {
@ -65,4 +70,44 @@
$this->assertEquals(0, $setting2->show_date); $this->assertEquals(0, $setting2->show_date);
$this->assertEquals(0, $setting2->episode_spoiler_protection); $this->assertEquals(0, $setting2->episode_spoiler_protection);
} }
/** @test */
public function it_should_update_genre_for_a_movie()
{
$this->createMovie();
$this->createGuzzleMock($this->tmdbFixtures('movie_details'));
$withoutGenre = Item::find(1);
$this->actingAs($this->user)->json('PATCH', 'api/update-genre');
$withGenre = Item::find(1);
$this->assertEmpty($withoutGenre->genre);
$this->assertNotEmpty($withGenre->genre);
}
/** @test */
public function it_should_update_genre_for_a_tv_show()
{
$this->createTv();
$this->createGuzzleMock($this->tmdbFixtures('tv_details'));
$withoutGenre = Item::find(1);
$this->actingAs($this->user)->json('PATCH', 'api/update-genre');
$withGenre = Item::find(1);
$this->assertEmpty($withoutGenre->genre);
$this->assertNotEmpty($withGenre->genre);
}
private function createGuzzleMock($fixture)
{
$mock = new MockHandler([
new Response(200, ['X-RateLimit-Remaining' => [40]], $fixture),
]);
$handler = HandlerStack::create($mock);
$this->app->instance(Client::class, new Client(['handler' => $handler]));
}
} }

View File

@ -0,0 +1,79 @@
{
"adult": false,
"backdrop_path": "/5SX2rgKXZ7NVmAJR5z5LprqSXKa.jpg",
"belongs_to_collection": null,
"budget": 160000000,
"genres": [
{
"id": 12,
"name": "Adventure"
},
{
"id": 14,
"name": "Fantasy"
},
{
"id": 28,
"name": "Action"
}
],
"homepage": "http://www.warcraft-themovie.com/",
"id": 68735,
"imdb_id": "tt0803096",
"original_language": "en",
"original_title": "Warcraft",
"overview": "The peaceful realm of Azeroth stands on the brink of war as its civilization faces a fearsome race of invaders: orc warriors fleeing their dying home to colonize another. As a portal opens to connect the two worlds, one army faces destruction and the other faces extinction. From opposing sides, two heroes are set on a collision course that will decide the fate of their family, their people, and their home.",
"popularity": 4.823419,
"poster_path": "/ckrTPz6FZ35L5ybjqvkLWzzSLO7.jpg",
"production_companies": [
{
"name": "Universal Pictures",
"id": 33
},
{
"name": "Atlas Entertainment",
"id": 507
},
{
"name": "Blizzard Entertainment",
"id": 16028
},
{
"name": "Legendary Entertainment",
"id": 84419
}
],
"production_countries": [
{
"iso_3166_1": "CA",
"name": "Canada"
},
{
"iso_3166_1": "CN",
"name": "China"
},
{
"iso_3166_1": "JP",
"name": "Japan"
},
{
"iso_3166_1": "US",
"name": "United States of America"
}
],
"release_date": "2016-05-25",
"revenue": 433537548,
"runtime": 123,
"spoken_languages": [
{
"iso_639_1": "en",
"name": "English"
}
],
"status": "Released",
"tagline": "Two worlds. One home.",
"title": "Warcraft",
"video": false,
"vote_average": 6.2,
"vote_count": 1265
}

View File

@ -0,0 +1,143 @@
{
"backdrop_path": "/aKz3lXU71wqdslC1IYRC3yHD6yw.jpg",
"created_by": [
{
"id": 9813,
"name": "David Benioff",
"profile_path": "/8CuuNIKMzMUL1NKOPv9AqEwM7og.jpg"
},
{
"id": 228068,
"name": "D. B. Weiss",
"profile_path": "/caUAtilEe06OwOjoQY3B7BgpARi.jpg"
}
],
"episode_run_time": [
60
],
"first_air_date": "2011-04-17",
"genres": [
{
"id": 10759,
"name": "Action & Adventure"
},
{
"id": 18,
"name": "Drama"
},
{
"id": 10765,
"name": "Sci-Fi & Fantasy"
}
],
"homepage": "http://www.hbo.com/game-of-thrones",
"id": 1399,
"in_production": true,
"languages": [
"es",
"en",
"de"
],
"last_air_date": "2017-06-25",
"name": "Game of Thrones",
"networks": [
{
"id": 49,
"name": "HBO"
}
],
"number_of_episodes": 61,
"number_of_seasons": 7,
"origin_country": [
"US"
],
"original_language": "en",
"original_name": "Game of Thrones",
"overview": "Seven noble families fight for control of the mythical land of Westeros. Friction between the houses leads to full-scale war. All while a very ancient evil awakens in the farthest north. Amidst the war, a neglected military order of misfits, the Night's Watch, is all that stands between the realms of men and icy horrors beyond.",
"popularity": 35.712295,
"poster_path": "/jIhL6mlT7AblhbHJgEoiBIOUVl1.jpg",
"production_companies": [
{
"name": "Home Box Office (HBO)",
"id": 3268
},
{
"name": "Generator Entertainment",
"id": 5820
},
{
"name": "Television 360",
"id": 12525
},
{
"name": "Bighead Littlehead",
"id": 12526
},
{
"name": "Revolution Sun Studios",
"id": 76043
}
],
"seasons": [
{
"air_date": "2010-12-05",
"episode_count": 13,
"id": 3627,
"poster_path": "/kMTcwNRfFKCZ0O2OaBZS0nZ2AIe.jpg",
"season_number": 0
},
{
"air_date": "2011-04-17",
"episode_count": 10,
"id": 3624,
"poster_path": "/olJ6ivXxCMq3cfujo1IRw30OrsQ.jpg",
"season_number": 1
},
{
"air_date": "2012-04-01",
"episode_count": 10,
"id": 3625,
"poster_path": "/3U8IVLqitMHMuEAgkuz8qReguHd.jpg",
"season_number": 2
},
{
"air_date": "2013-03-31",
"episode_count": 10,
"id": 3626,
"poster_path": "/eVWAat0GqF6s5LLThrI7ClpKr96.jpg",
"season_number": 3
},
{
"air_date": "2014-04-06",
"episode_count": 10,
"id": 3628,
"poster_path": "/dniQ7zw3mbLJkd1U0gdFEh4b24O.jpg",
"season_number": 4
},
{
"air_date": "2015-04-12",
"episode_count": 10,
"id": 62090,
"poster_path": "/yKOltUHsp9X7dXWIm0hNGcIQa4G.jpg",
"season_number": 5
},
{
"air_date": "2016-04-24",
"episode_count": 10,
"id": 71881,
"poster_path": "/zvYrzLMfPIenxoq2jFY4eExbRv8.jpg",
"season_number": 6
},
{
"air_date": "2017-06-25",
"episode_count": 1,
"id": 81266,
"poster_path": null,
"season_number": 7
}
],
"status": "Returning Series",
"type": "Scripted",
"vote_average": 7.9,
"vote_count": 1528
}

View File

@ -32,7 +32,6 @@
<div class="settings-box"> <div class="settings-box">
<span class="nothing-found">{{ lang('headline misc') }}</span> <span class="nothing-found">{{ lang('headline misc') }}</span>
<button @click="updateGenre()" class="export-btn">{{ lang('update genre') }}</button> <button @click="updateGenre()" class="export-btn">{{ lang('update genre') }}</button>
<span class="userdata-info">{{ lang('genre message') }}</span>
<span class="import-info">{{ lang('or divider') }}</span> <span class="import-info">{{ lang('or divider') }}</span>
<button @click="updateAlternativeTitles()" class="export-btn">Update alternative titles</button> <button @click="updateAlternativeTitles()" class="export-btn">Update alternative titles</button>
<span class="import-info">{{ lang('or divider') }}</span> <span class="import-info">{{ lang('or divider') }}</span>

View File

@ -37,7 +37,6 @@
"display date": "عرض التاريخ", "display date": "عرض التاريخ",
"success import": "تم استراد الأفلام بناجاح", "success import": "تم استراد الأفلام بناجاح",
"import warn": "سيتم استبدال جميع الأفلام. تأكد من أنك قد قدمت نسخة احتياطية!", "import warn": "سيتم استبدال جميع الأفلام. تأكد من أنك قد قدمت نسخة احتياطية!",
"genre message": "لتحديث نسخة قديمة من flox",
"current version": "النسخة الحالية:", "current version": "النسخة الحالية:",
"new update": "هناك تحديثا جديدا لflox!", "new update": "هناك تحديثا جديدا لflox!",
"no update": "لا شيء لتحديث", "no update": "لا شيء لتحديث",

View File

@ -37,7 +37,6 @@
"display date": "Vis dato", "display date": "Vis dato",
"success import": "Film succesfuldt importeret", "success import": "Film succesfuldt importeret",
"import warn": "Alle film vil blive erstattet. Vær sikker på du laver en sikkerhedskopi!", "import warn": "Alle film vil blive erstattet. Vær sikker på du laver en sikkerhedskopi!",
"genre message": "Til at opdatere en gammel version af flox",
"current version": "Nuværende version:", "current version": "Nuværende version:",
"new update": "Der er en ny opdatering til flox!", "new update": "Der er en ny opdatering til flox!",
"no update": "Intet at opdatere", "no update": "Intet at opdatere",

View File

@ -37,7 +37,6 @@
"display date": "Datum anzeigen", "display date": "Datum anzeigen",
"success import": "Filme wurden erfolgreich importiert", "success import": "Filme wurden erfolgreich importiert",
"import warn": "Durch den Import werden alle Filme ersetzt. Erstelle vorher ein Backup!", "import warn": "Durch den Import werden alle Filme ersetzt. Erstelle vorher ein Backup!",
"genre message": "Um eine alte Version von Flox zu aktualisieren",
"current version": "Aktuelle Version:", "current version": "Aktuelle Version:",
"new update": "Ein neues Update ist vorhanden", "new update": "Ein neues Update ist vorhanden",
"no update": "Kein Update vorhanden", "no update": "Kein Update vorhanden",

View File

@ -37,7 +37,6 @@
"display date": "Εμφάνιση ημερομηνίας", "display date": "Εμφάνιση ημερομηνίας",
"success import": "Επιτυχής εισαγωγή ταινιών", "success import": "Επιτυχής εισαγωγή ταινιών",
"import warn": "Όλες οι ταινίες θα αντικατασταθούν. Σιγουρέψου ότι έχεις κρατήσει αντίγραφο ασφαλείας!", "import warn": "Όλες οι ταινίες θα αντικατασταθούν. Σιγουρέψου ότι έχεις κρατήσει αντίγραφο ασφαλείας!",
"genre message": "Για να αναβαθμίσεις μία παλιά έκδοση του flox",
"current version": "Τρέχουσα έκδοση:", "current version": "Τρέχουσα έκδοση:",
"new update": "Υπάρχει μια νέα ενημερωμένη έκδοση για Flox!", "new update": "Υπάρχει μια νέα ενημερωμένη έκδοση για Flox!",
"no update": "Τίποτα για να ενημερώσετε", "no update": "Τίποτα για να ενημερώσετε",

View File

@ -37,7 +37,6 @@
"display date": "Display date", "display date": "Display date",
"success import": "Movies successful imported", "success import": "Movies successful imported",
"import warn": "All movies will be replaced. Be sure you have made an backup!", "import warn": "All movies will be replaced. Be sure you have made an backup!",
"genre message": "For updating an old version of flox",
"current version": "Current version:", "current version": "Current version:",
"new update": "There is a new update for flox!", "new update": "There is a new update for flox!",
"no update": "Nothing to update", "no update": "Nothing to update",

View File

@ -37,7 +37,6 @@
"display date": "Afficher date", "display date": "Afficher date",
"success import": "Films importés avec succès", "success import": "Films importés avec succès",
"import warn": "Tous les films seront remplacés. Il est recommandé de faire une sauvegarde avant de continuer", "import warn": "Tous les films seront remplacés. Il est recommandé de faire une sauvegarde avant de continuer",
"genre message": "Pour actualiser une ancienne version de Flox",
"current version": "Version actuelle:", "current version": "Version actuelle:",
"new update": "Il existe une nouvelle mise à jour pour flox!", "new update": "Il existe une nouvelle mise à jour pour flox!",
"no update": "Rien à mettre à jour", "no update": "Rien à mettre à jour",

View File

@ -37,7 +37,6 @@
"display date": "Weergeef datum", "display date": "Weergeef datum",
"success import": "Films successful geïmporteerd", "success import": "Films successful geïmporteerd",
"import warn": "Alle films worden vervangen. Zorg dat je een backup hebt!", "import warn": "Alle films worden vervangen. Zorg dat je een backup hebt!",
"genre message": "Om een oude versie van Flox te updaten",
"current version": "Huidige versie:", "current version": "Huidige versie:",
"new update": "Er is een nieuwe update voor Flox!", "new update": "Er is een nieuwe update voor Flox!",
"no update": "Niets te actualiseren", "no update": "Niets te actualiseren",