mirror of
https://github.com/devfake/flox.git
synced 2024-11-15 06:32:34 +01:00
parent
ec42cd5c65
commit
447c79ca9e
@ -59,11 +59,21 @@
|
|||||||
return $query->where('src', $src);
|
return $query->where('src', $src);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function scopeFindByFPName($query, $item)
|
||||||
|
{
|
||||||
|
$changed = isset($item->changed->name) ? $item->changed->name : $item->name;
|
||||||
|
|
||||||
|
return $query->where('fp_name', $item->name)->orWhere('fp_name', $changed);
|
||||||
|
}
|
||||||
|
|
||||||
public function scopeFindSpecificEpisode($query, $tmdbId, $episode)
|
public function scopeFindSpecificEpisode($query, $tmdbId, $episode)
|
||||||
{
|
{
|
||||||
|
$season = isset($episode->changed->season_number) ? $episode->changed->season_number : $episode->season_number;
|
||||||
|
$episode = isset($episode->changed->episode_number) ? $episode->changed->episode_number : $episode->episode_number;
|
||||||
|
|
||||||
return $query->where('tmdb_id', $tmdbId)
|
return $query->where('tmdb_id', $tmdbId)
|
||||||
->where('season_number', $episode->season_number)
|
->where('season_number', $season)
|
||||||
->where('episode_number', $episode->episode_number);
|
->where('episode_number', $episode);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function scopeFindSeason($query, $tmdbId, $season)
|
public function scopeFindSeason($query, $tmdbId, $season)
|
||||||
|
@ -18,7 +18,7 @@
|
|||||||
const REMOVED = 'removed';
|
const REMOVED = 'removed';
|
||||||
const UPDATED = 'updated';
|
const UPDATED = 'updated';
|
||||||
|
|
||||||
// [localfile => database]
|
// [field in local file => field in database]
|
||||||
const SUPPORTED_FIELDS = ['src' => 'src', 'subtitles' => 'subtitles', 'name' => 'fp_name'];
|
const SUPPORTED_FIELDS = ['src' => 'src', 'subtitles' => 'subtitles', 'name' => 'fp_name'];
|
||||||
|
|
||||||
private $itemService;
|
private $itemService;
|
||||||
@ -142,7 +142,7 @@
|
|||||||
private function validateUpdate($item)
|
private function validateUpdate($item)
|
||||||
{
|
{
|
||||||
// See if file is already in our database.
|
// See if file is already in our database.
|
||||||
if($found = $this->itemService->findBy('fp_name', $item, $this->itemCategory)) {
|
if($found = $this->findItemByFPName($item)) {
|
||||||
if( ! $found->tmdb_id) {
|
if( ! $found->tmdb_id) {
|
||||||
return $this->searchTmdbAndUpdateEmptyItem($found, $item);
|
return $this->searchTmdbAndUpdateEmptyItem($found, $item);
|
||||||
}
|
}
|
||||||
@ -258,12 +258,15 @@
|
|||||||
* Iterate over all changed properties and update them in our database.
|
* Iterate over all changed properties and update them in our database.
|
||||||
*
|
*
|
||||||
* @param $item
|
* @param $item
|
||||||
* @param $model
|
* @param $tmdbId
|
||||||
* @return mixed
|
* @return mixed
|
||||||
*/
|
*/
|
||||||
private function update($item, $tmdbId)
|
private function update($item, $tmdbId)
|
||||||
{
|
{
|
||||||
if($model = $this->findItem($item, $tmdbId)) {
|
if($model = $this->findItem($item, $tmdbId)) {
|
||||||
|
// Remove all fields, so we can start from scratch.
|
||||||
|
$this->remove($item);
|
||||||
|
|
||||||
foreach($item->changed as $field => $value) {
|
foreach($item->changed as $field => $value) {
|
||||||
if(array_key_exists($field, self::SUPPORTED_FIELDS)) {
|
if(array_key_exists($field, self::SUPPORTED_FIELDS)) {
|
||||||
$model->{self::SUPPORTED_FIELDS[$field]} = $value;
|
$model->{self::SUPPORTED_FIELDS[$field]} = $value;
|
||||||
@ -320,6 +323,26 @@
|
|||||||
return $this->itemService->findBy('tmdb_id', $tmdbId);
|
return $this->itemService->findBy('tmdb_id', $tmdbId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param $item
|
||||||
|
* @return mixed
|
||||||
|
*/
|
||||||
|
private function findItemByFPName($item)
|
||||||
|
{
|
||||||
|
$found = $this->itemService->findBy('fp_name', $item, $this->itemCategory);
|
||||||
|
|
||||||
|
// Search against episodes if no empty item for a tv show was found.
|
||||||
|
if( ! $found && $this->itemCategory == 'tv') {
|
||||||
|
$episode = $this->episodeService->findBy('fp_name', $item);
|
||||||
|
|
||||||
|
if($episode) {
|
||||||
|
$found = $this->itemService->findBy('tmdb_id', $episode->tmdb_id);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $found;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param $item
|
* @param $item
|
||||||
* @return \Illuminate\Support\Collection|mixed
|
* @return \Illuminate\Support\Collection|mixed
|
||||||
@ -329,6 +352,7 @@
|
|||||||
if($this->itemCategory == 'tv') {
|
if($this->itemCategory == 'tv') {
|
||||||
return $this->episodeService->findBy('src', $item->src);
|
return $this->episodeService->findBy('src', $item->src);
|
||||||
}
|
}
|
||||||
|
|
||||||
return $this->itemService->findBy('src', $item->src);
|
return $this->itemService->findBy('src', $item->src);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -103,6 +103,8 @@
|
|||||||
switch($type) {
|
switch($type) {
|
||||||
case 'src':
|
case 'src':
|
||||||
return $this->model->findBySrc($value)->first();
|
return $this->model->findBySrc($value)->first();
|
||||||
|
case 'fp_name':
|
||||||
|
return $this->model->findByFPName($value)->first();
|
||||||
case 'tmdb_id':
|
case 'tmdb_id':
|
||||||
return $this->model->findByTmdbId($value)->first();
|
return $this->model->findByTmdbId($value)->first();
|
||||||
case 'episode':
|
case 'episode':
|
||||||
|
@ -279,6 +279,30 @@
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** @test */
|
||||||
|
public function it_should_update_proper_fields_for_episodes_if_season_and_episode_number_changed()
|
||||||
|
{
|
||||||
|
$this->createTv(['fp_name' => 'Game of Thrones']);
|
||||||
|
|
||||||
|
$this->episode->get()->each(function($episode) {
|
||||||
|
$episode->update(['src' => $this->getTvSrc()]);
|
||||||
|
});
|
||||||
|
|
||||||
|
$episodes = $this->episode->get();
|
||||||
|
$this->parser->updateDatabase($this->fpFixtures('tv/updated_one'));
|
||||||
|
$updatedEpisodes = $this->episode->get();
|
||||||
|
|
||||||
|
$this->assertNotNull($episodes[0]->src);
|
||||||
|
$this->assertNotNull($episodes[0]->src);
|
||||||
|
$this->assertNull($updatedEpisodes[0]->src);
|
||||||
|
$this->assertNull($updatedEpisodes[0]->src);
|
||||||
|
|
||||||
|
$this->assertNotEquals('NEW SRC UPDATED', $episodes[1]->src);
|
||||||
|
$this->assertNotEquals('NEW SUB UPDATED', $episodes[1]->subtitles);
|
||||||
|
$this->assertEquals('NEW SRC UPDATED', $updatedEpisodes[1]->src);
|
||||||
|
$this->assertEquals('NEW SUB UPDATED', $updatedEpisodes[1]->subtitles);
|
||||||
|
}
|
||||||
|
|
||||||
/** @test */
|
/** @test */
|
||||||
public function it_should_nothing_update_for_episodes_if_changed_is_empty()
|
public function it_should_nothing_update_for_episodes_if_changed_is_empty()
|
||||||
{
|
{
|
||||||
|
22
backend/tests/fixtures/fp/tv/updated_one.json
vendored
Normal file
22
backend/tests/fixtures/fp/tv/updated_one.json
vendored
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
{
|
||||||
|
"tv": [
|
||||||
|
{
|
||||||
|
"name": "Game of Thrones",
|
||||||
|
"season_number": 1,
|
||||||
|
"episode_number": 1,
|
||||||
|
"status": "updated",
|
||||||
|
"extension": "mkv",
|
||||||
|
"tags": [],
|
||||||
|
"year": null,
|
||||||
|
"filename": "1",
|
||||||
|
"subtitles": null,
|
||||||
|
"src": "/tv/Game of Thrones/S1/1.mkv",
|
||||||
|
"changed": {
|
||||||
|
"src": "NEW SRC UPDATED",
|
||||||
|
"subtitles": "NEW SUB UPDATED",
|
||||||
|
"season_number": 1,
|
||||||
|
"episode_number": 2
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user