Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support of nfo when "Import existing series on Disk" #2096

Closed

Conversation

j0nathan33
Copy link

@j0nathan33 j0nathan33 commented Aug 3, 2017

Database Migration

NO

Description

Add some code to read nfo when do "Importing existing series on Disk"

Todos

  • Tests
  • Documentation

Issues Fixed or Closed by this PR

Fix issues #289

Copy link
Member

@markus101 markus101 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for picking this up, the current solution needs some work before we can accept it though. I'm not sure how familiar you are with the codebase or C# in general, but please let us know if you have any questions and we'll try to assist.

@@ -153,7 +154,34 @@ private List<UnmappedFolder> GetUnmappedFolders(string path)
foreach (string unmappedFolder in unmappedFolders)
{
var di = new DirectoryInfo(unmappedFolder.Normalize());
results.Add(new UnmappedFolder { Name = di.Name, Path = di.FullName });
var fileNfoName = String.Format("{0}\\tvshow.nfo", di.FullName);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use Path.Combine to join paths, which works on different operating systems, currently this would break on anything other than Windows.

@@ -153,7 +154,34 @@ private List<UnmappedFolder> GetUnmappedFolders(string path)
foreach (string unmappedFolder in unmappedFolders)
{
var di = new DirectoryInfo(unmappedFolder.Normalize());
results.Add(new UnmappedFolder { Name = di.Name, Path = di.FullName });
var fileNfoName = String.Format("{0}\\tvshow.nfo", di.FullName);
if (File.Exists(fileNfoName))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use DiskProvider.FileExists so it can be mocked for unit tests.

else
{
String tvid = node.InnerText;
results.Add(new UnmappedFolder { Name = String.Format("tvdb:{0}", tvid), Path = di.FullName });
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The name should still be the name, any additional information should be returned via a separate property, which also means the API and UI will need to be updated to pull in that information.

var fileNfoName = String.Format("{0}\\tvshow.nfo", di.FullName);
if (File.Exists(fileNfoName))
{
try
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The logic of pulling the ID from an NFO file should be pulled out to a separate method, possibly another class/interface so additional metadata types could be also be handled. It'd be worth looking at extending the existing metadata handling to be able to check for an existing file and check that file for an ID if the file doesn't exist or doesn't support storing an an ID Sonarr can use for a lookup it would return null.

@j0nathan33
Copy link
Author

I don't know why junit fail when I only edit javascript file

Copy link
Member

@markus101 markus101 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A few more things to address. Extracting the ID from the file in RootFolderServer still seems like the wrong approach, since it puts specific knowledge about the file there, when it otherwise shouldn't care. We'll need tests to validate the behaviour if it's going to stay here in RootFolderServiceFixture.

As for the unit tests failing when you made a change to the JS it's because the whole test suite was re-run (it does that every build regardless of what changed).

@@ -30,9 +30,12 @@ module.exports = Marionette.CompositeView.extend({

if (model) {
var currentIndex = index;
var folderName = model.get('folder').name;
var termSearch = model.get('folder').name;
if (typeof model.get('folder').id !== "undefined") {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

model.get('folder').id != null (instead of the !== you had before as != will catch undefined and null.

@@ -4,5 +4,6 @@ public class UnmappedFolder
{
public string Name { get; set; }
public string Path { get; set; }
public string Id { get; set; }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Id is reserved for the Id of the record, TvdbId would be more accurate since that assumption is being made in the client. It should also be an integer instead of a string. Probably a nullable int so we don't return 0 if it's unknown.

XmlNode node = doc.DocumentElement.SelectSingleNode("/tvshow/id");
if (node != null)
{
returnValue = node.InnerText;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not return directly from here? This should also parse it to an integer to ensure it's valid.

@markus101
Copy link
Member

After talking with @Taloth there are a couple things we want to improve here:

  1. The logic for pulling the TVDB ID needs to be moved outside of the RootFolderService
  2. The host should tell the client what to search for, that is, if it has a TVDB ID, it should set the search term to tvdbid:12345 and if it doesn't it should return the folder name, the client will then use the search term from the server and not decide which to use on it's own

@markus101 markus101 closed this Nov 30, 2018
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jan 23, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants