Skip to content

Commit

Permalink
initial version of television series validator
Browse files Browse the repository at this point in the history
reduced number of files examined with exiftool in a single run to 512 because it stalled for me with 3072
  • Loading branch information
marco-schmidt committed Sep 18, 2019
1 parent 72c7447 commit 72d9f92
Show file tree
Hide file tree
Showing 6 changed files with 149 additions and 4 deletions.
9 changes: 7 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
asset manager

## Status
As of July 2019, this tool is in an early development stage, to be used only by the very curious.
As of September 2019, this tool is in an early development stage, to be used only by the very curious.

## Purpose
* Command-line asset manager, managing files, checking their integrity, extracting metadata.
Expand Down Expand Up @@ -60,7 +60,12 @@ Define a movie volume (leave out the last two arguments if your media files are
./am --add-volume /home/johndoe/movies --set-validator MovieValidator
```

The previous call just added a single record about a new volume to the database. Now have am scan that new volume, run exiftool on files, create some hash values:
Alternatively, define a television series volume:
```
./am --add-volume /home/johndoe/tv --set-validator TvSeriesValidator
```

The previous calls just added a single record about a new volume to the database. Now have am scan that new volume, run exiftool on files, create some hash values:
```
./am
```
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/am/app/App.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import am.processor.hashes.HashProcessor;
import am.validators.AbstractValidator;
import am.validators.MovieValidator;
import am.validators.TvSeriesValidator;

/**
* Application's main class.
Expand Down Expand Up @@ -150,6 +151,7 @@ private static void registerValidators()
if (!AbstractValidator.hasRegisteredValidators())
{
AbstractValidator.register(MovieValidator.class);
AbstractValidator.register(TvSeriesValidator.class);
}
}

Expand All @@ -163,6 +165,8 @@ private AbstractValidator createValidator(final AppConfig config, String validat
{
case "MovieValidator":
return new MovieValidator();
case "TvSeriesValidator":
return new TvSeriesValidator();
default:
LOGGER.error(config.msg("init.error.unknown_validator", validatorName, volNr));
return null;
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/am/app/AppConfigLoader.java
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ private static void initExiftool(AppConfig config, Properties props)
config.msg("init.debug.exiftool_setup", path, version.toString(), System.currentTimeMillis() - millis));
config.setExifTool(exifTool);
config.setExifToolPath(path);
config.setExifToolMaxUsage(Long.valueOf(2048));
config.setExifToolMaxUsage(Long.valueOf(512));
}
catch (final UnsupportedFeatureException ex)
{
Expand Down
8 changes: 8 additions & 0 deletions src/main/java/am/validators/AbstractValidator.java
Original file line number Diff line number Diff line change
Expand Up @@ -103,4 +103,12 @@ public boolean containsOnly(String id)
{
return ids.contains(id) && ids.size() == 1;
}

protected void markFilesInvalid(Directory dir, String violationId)
{
for (final File file : dir.getFiles())
{
addViolation(file, violationId);
}
}
}
123 changes: 123 additions & 0 deletions src/main/java/am/validators/TvSeriesValidator.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
/*
* Copyright 2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package am.validators;

import java.util.Calendar;
import java.util.GregorianCalendar;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import am.app.AppConfig;
import am.filesystem.model.Directory;
import am.filesystem.model.Volume;

/**
* Validate a television series volume.
*
* <ul>
* <li>A volume root directory contains only directories, each one named like a year.</li>
* <li>Each year directory contains only directories, each representing and named like one television series that was
* first published during that year.</li>
* <li>Each television series directory contains only directories, each representing a season.</li>
* <li>A season directory has a decimal number as its name, leading zeroes allowed.</li>
* <li>A season directory may contain files only.</li>
* <li>Each file is a video file containing an episode of the season, or metadata (vsmeta, srt, and so on).</li>
* <li>Video files start with the name of the series as written two directories above, followed by a space and the
* episode number in format SxxEyy. Here xx is the season number from the file's directory followed by the number of the
* episode within the season.</li>
* </ul>
*
* @author Marco Schmidt
*/
public class TvSeriesValidator extends AbstractValidator
{
/**
* First year of television, see <a href="https://en.wikipedia.org/wiki/History_of_television">History of
* television</a>.
*/
private static final int MIN_TELEVISION_YEAR = 1926;
private static final String NO_FILES_IN_ROOT = "no_files_in_root_directory";
private static final String NO_FILES_IN_YEAR_DIRECTORY = "no_files_in_year_directory";
private static final String VIOLATION_DIRECTORY_YEAR_TOO_SMALL = "directory_year_too_small";
private static final String VIOLATION_DIRECTORY_YEAR_TOO_LARGE = "directory_year_too_large";
private static final String VIOLATION_DIRECTORY_NOT_A_NUMBER = "directory_not_a_number";
private static final Logger LOGGER = LoggerFactory.getLogger(TvSeriesValidator.class);

@Override
public String getMessagePrefix()
{
return "tvseriesvalidator";
}

@Override
public void validate(AppConfig config, Volume volume)
{
validateRootDirectoryEntries(config, volume.getRoot());
}

private void validateRootDirectoryEntries(AppConfig config, Directory dir)
{
for (final Directory sub : dir.getSubdirectories())
{
validateYearEntries(config, sub);
}

markFilesInvalid(dir, NO_FILES_IN_ROOT);
}

private int findMaxTelevisionYear()
{
final Calendar cal = new GregorianCalendar();
final int maxYear = cal.get(Calendar.YEAR) + 1;
return maxYear;
}

private void validateYearEntries(AppConfig config, Directory dir)
{
Long year;
try
{
year = Long.valueOf(dir.getName());
}
catch (final NumberFormatException nfe)
{
addViolation(dir, VIOLATION_DIRECTORY_NOT_A_NUMBER);
year = null;
}

// make sure that number is a reasonable year
if (year != null)
{
if (year < MIN_TELEVISION_YEAR)
{
addViolation(dir, VIOLATION_DIRECTORY_YEAR_TOO_SMALL);
year = null;
}
else
{
final int maxYear = findMaxTelevisionYear();
if (year > maxYear)
{
addViolation(dir, VIOLATION_DIRECTORY_YEAR_TOO_LARGE);
year = null;
}
}
}

markFilesInvalid(dir, NO_FILES_IN_YEAR_DIRECTORY);

LOGGER.debug("Year=" + (year == null ? "?" : year.toString()));
}
}
7 changes: 6 additions & 1 deletion src/main/resources/Messages_en.properties
Original file line number Diff line number Diff line change
Expand Up @@ -136,4 +136,9 @@ movievalidator.file_dir_year_differ=Year in directory and file name differ.
movievalidator.error.connect_wikidata_failure=Failed to send wikidata query about movie.
movievalidator.info.wikidata_result=For movie query "{0}" retrieved id {1} with description "{2}" and label "{3}" in {4} ms.
movievalidator.warn.wikidata_no_result=No result for movie query "{0}" in {1} ms.
shutdown.info.shutting_down=Shutting down application.
shutdown.info.shutting_down=Shutting down application.
tvseriesvalidator.no_files_in_root_directory=Root directory must not contain files.
tvseriesvalidator.directory_not_a_number=Directory name not a year.
tvseriesvalidator.directory_year_too_small=Directory name too small for a year.
tvseriesvalidator.directory_year_too_large=Directory name too large for a year.
tvseriesvalidator.no_files_in_year_directory=Year directory must not contain files.

0 comments on commit 72d9f92

Please sign in to comment.