mirror of https://github.com/Radarr/Radarr
New: Cleanup Alternative Title model and code
This commit is contained in:
parent
c1a3a8249b
commit
c70ce92ee9
|
@ -2,7 +2,6 @@ import PropTypes from 'prop-types';
|
|||
import React, { Component } from 'react';
|
||||
import TableRowCell from 'Components/Table/Cells/TableRowCell';
|
||||
import TableRow from 'Components/Table/TableRow';
|
||||
import MovieLanguage from 'Movie/MovieLanguage';
|
||||
import titleCase from 'Utilities/String/titleCase';
|
||||
|
||||
class MovieTitlesRow extends Component {
|
||||
|
@ -13,13 +12,9 @@ class MovieTitlesRow extends Component {
|
|||
render() {
|
||||
const {
|
||||
title,
|
||||
language,
|
||||
sourceType
|
||||
} = this.props;
|
||||
|
||||
// TODO - Fix languages to all take arrays
|
||||
const languages = [language];
|
||||
|
||||
return (
|
||||
<TableRow>
|
||||
|
||||
|
@ -27,12 +22,6 @@ class MovieTitlesRow extends Component {
|
|||
{title}
|
||||
</TableRowCell>
|
||||
|
||||
<TableRowCell>
|
||||
<MovieLanguage
|
||||
languages={languages}
|
||||
/>
|
||||
</TableRowCell>
|
||||
|
||||
<TableRowCell>
|
||||
{titleCase(sourceType)}
|
||||
</TableRowCell>
|
||||
|
@ -45,7 +34,6 @@ class MovieTitlesRow extends Component {
|
|||
MovieTitlesRow.propTypes = {
|
||||
id: PropTypes.number.isRequired,
|
||||
title: PropTypes.string.isRequired,
|
||||
language: PropTypes.object.isRequired,
|
||||
sourceType: PropTypes.string.isRequired
|
||||
};
|
||||
|
||||
|
|
|
@ -13,11 +13,6 @@ const columns = [
|
|||
label: () => translate('AlternativeTitle'),
|
||||
isVisible: true
|
||||
},
|
||||
{
|
||||
name: 'language',
|
||||
label: () => translate('Language'),
|
||||
isVisible: true
|
||||
},
|
||||
{
|
||||
name: 'sourceType',
|
||||
label: () => translate('Type'),
|
||||
|
|
|
@ -2,7 +2,6 @@ using FizzWare.NBuilder;
|
|||
using FluentAssertions;
|
||||
using NUnit.Framework;
|
||||
using NzbDrone.Core.Housekeeping.Housekeepers;
|
||||
using NzbDrone.Core.Languages;
|
||||
using NzbDrone.Core.Movies;
|
||||
using NzbDrone.Core.Movies.AlternativeTitles;
|
||||
using NzbDrone.Core.Test.Framework;
|
||||
|
@ -17,7 +16,6 @@ namespace NzbDrone.Core.Test.Housekeeping.Housekeepers
|
|||
{
|
||||
var altTitle = Builder<AlternativeTitle>.CreateNew()
|
||||
.With(h => h.MovieMetadataId = default)
|
||||
.With(h => h.Language = Language.English)
|
||||
.BuildNew();
|
||||
|
||||
Db.Insert(altTitle);
|
||||
|
@ -34,7 +32,6 @@ namespace NzbDrone.Core.Test.Housekeeping.Housekeepers
|
|||
|
||||
var altTitle = Builder<AlternativeTitle>.CreateNew()
|
||||
.With(h => h.MovieMetadataId = default)
|
||||
.With(h => h.Language = Language.English)
|
||||
.With(b => b.MovieMetadataId = movieMetadata.Id)
|
||||
.BuildNew();
|
||||
|
||||
|
|
|
@ -1,32 +0,0 @@
|
|||
using FizzWare.NBuilder;
|
||||
using FluentAssertions;
|
||||
using NUnit.Framework;
|
||||
using NzbDrone.Core.Movies.AlternativeTitles;
|
||||
using NzbDrone.Core.Test.Framework;
|
||||
|
||||
namespace NzbDrone.Core.Test.MovieTests.AlternativeTitleServiceTests
|
||||
{
|
||||
[TestFixture]
|
||||
public class AlternativeTitleFixture : CoreTest
|
||||
{
|
||||
private AlternativeTitle CreateFakeTitle(SourceType source, int votes)
|
||||
{
|
||||
return Builder<AlternativeTitle>.CreateNew().With(t => t.SourceType = source).With(t => t.Votes = votes)
|
||||
.Build();
|
||||
}
|
||||
|
||||
[TestCase(SourceType.TMDB, -1, true)]
|
||||
[TestCase(SourceType.TMDB, 1000, true)]
|
||||
[TestCase(SourceType.Mappings, 0, false)]
|
||||
[TestCase(SourceType.Mappings, 4, true)]
|
||||
[TestCase(SourceType.Mappings, -1, false)]
|
||||
[TestCase(SourceType.Indexer, 0, true)]
|
||||
[TestCase(SourceType.User, 0, true)]
|
||||
public void should_be_trusted(SourceType source, int votes, bool trusted)
|
||||
{
|
||||
var fakeTitle = CreateFakeTitle(source, votes);
|
||||
|
||||
fakeTitle.IsTrusted().Should().Be(trusted);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,17 @@
|
|||
using FluentMigrator;
|
||||
using NzbDrone.Core.Datastore.Migration.Framework;
|
||||
|
||||
namespace NzbDrone.Core.Datastore.Migration
|
||||
{
|
||||
[Migration(216)]
|
||||
public class clean_alt_titles : NzbDroneMigrationBase
|
||||
{
|
||||
protected override void MainDbUpgrade()
|
||||
{
|
||||
Delete.Column("Language").FromTable("AlternativeTitles");
|
||||
Delete.Column("Votes").FromTable("AlternativeTitles");
|
||||
Delete.Column("VoteCount").FromTable("AlternativeTitles");
|
||||
Delete.Column("SourceId").FromTable("AlternativeTitles");
|
||||
}
|
||||
}
|
||||
}
|
|
@ -571,8 +571,7 @@ namespace NzbDrone.Core.MetadataSource.SkyHook
|
|||
{
|
||||
Title = arg.Title,
|
||||
SourceType = SourceType.TMDB,
|
||||
CleanTitle = arg.Title.CleanMovieTitle(),
|
||||
Language = IsoLanguages.Find(arg.Language.ToLower())?.Language ?? Language.English
|
||||
CleanTitle = arg.Title.CleanMovieTitle()
|
||||
};
|
||||
|
||||
return newAlternativeTitle;
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
using NzbDrone.Core.Datastore;
|
||||
using NzbDrone.Core.Languages;
|
||||
using NzbDrone.Core.Parser;
|
||||
|
||||
namespace NzbDrone.Core.Movies.AlternativeTitles
|
||||
|
@ -10,33 +9,16 @@ namespace NzbDrone.Core.Movies.AlternativeTitles
|
|||
public int MovieMetadataId { get; set; }
|
||||
public string Title { get; set; }
|
||||
public string CleanTitle { get; set; }
|
||||
public int SourceId { get; set; }
|
||||
public int Votes { get; set; }
|
||||
public int VoteCount { get; set; }
|
||||
public Language Language { get; set; }
|
||||
|
||||
public AlternativeTitle()
|
||||
{
|
||||
}
|
||||
|
||||
public AlternativeTitle(string title, SourceType sourceType = SourceType.TMDB, int sourceId = 0, Language language = null)
|
||||
public AlternativeTitle(string title, SourceType sourceType = SourceType.TMDB, int sourceId = 0)
|
||||
{
|
||||
Title = title;
|
||||
CleanTitle = title.CleanMovieTitle();
|
||||
SourceType = sourceType;
|
||||
SourceId = sourceId;
|
||||
Language = language ?? Language.English;
|
||||
}
|
||||
|
||||
public bool IsTrusted(int minVotes = 4)
|
||||
{
|
||||
switch (SourceType)
|
||||
{
|
||||
case SourceType.Mappings:
|
||||
return Votes >= minVotes;
|
||||
default:
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
public override bool Equals(object obj)
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using NzbDrone.Core.Datastore;
|
||||
using NzbDrone.Core.Messaging.Events;
|
||||
|
||||
|
@ -7,8 +6,6 @@ namespace NzbDrone.Core.Movies.AlternativeTitles
|
|||
{
|
||||
public interface IAlternativeTitleRepository : IBasicRepository<AlternativeTitle>
|
||||
{
|
||||
AlternativeTitle FindBySourceId(int sourceId);
|
||||
List<AlternativeTitle> FindBySourceIds(List<int> sourceIds);
|
||||
List<AlternativeTitle> FindByMovieMetadataId(int movieId);
|
||||
void DeleteForMovies(List<int> movieIds);
|
||||
}
|
||||
|
@ -20,16 +17,6 @@ namespace NzbDrone.Core.Movies.AlternativeTitles
|
|||
{
|
||||
}
|
||||
|
||||
public AlternativeTitle FindBySourceId(int sourceId)
|
||||
{
|
||||
return Query(x => x.SourceId == sourceId).FirstOrDefault();
|
||||
}
|
||||
|
||||
public List<AlternativeTitle> FindBySourceIds(List<int> sourceIds)
|
||||
{
|
||||
return Query(x => sourceIds.Contains(x.SourceId));
|
||||
}
|
||||
|
||||
public List<AlternativeTitle> FindByMovieMetadataId(int movieId)
|
||||
{
|
||||
return Query(x => x.MovieMetadataId == movieId);
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using NzbDrone.Core.Languages;
|
||||
using NzbDrone.Core.Movies.AlternativeTitles;
|
||||
using Radarr.Http.REST;
|
||||
|
||||
|
@ -15,10 +14,6 @@ namespace Radarr.Api.V3.Movies
|
|||
public int MovieMetadataId { get; set; }
|
||||
public string Title { get; set; }
|
||||
public string CleanTitle { get; set; }
|
||||
public int SourceId { get; set; }
|
||||
public int Votes { get; set; }
|
||||
public int VoteCount { get; set; }
|
||||
public Language Language { get; set; }
|
||||
|
||||
// TODO: Add series statistics as a property of the series (instead of individual properties)
|
||||
}
|
||||
|
@ -37,11 +32,7 @@ namespace Radarr.Api.V3.Movies
|
|||
Id = model.Id,
|
||||
SourceType = model.SourceType,
|
||||
MovieMetadataId = model.MovieMetadataId,
|
||||
Title = model.Title,
|
||||
SourceId = model.SourceId,
|
||||
Votes = model.Votes,
|
||||
VoteCount = model.VoteCount,
|
||||
Language = model.Language
|
||||
Title = model.Title
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -57,11 +48,7 @@ namespace Radarr.Api.V3.Movies
|
|||
Id = resource.Id,
|
||||
SourceType = resource.SourceType,
|
||||
MovieMetadataId = resource.MovieMetadataId,
|
||||
Title = resource.Title,
|
||||
SourceId = resource.SourceId,
|
||||
Votes = resource.Votes,
|
||||
VoteCount = resource.VoteCount,
|
||||
Language = resource.Language
|
||||
Title = resource.Title
|
||||
};
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue