List of usage examples for org.apache.commons.lang3 StringUtils isNumeric
public static boolean isNumeric(final CharSequence cs)
Checks if the CharSequence contains only Unicode digits.
From source file:org.yamj.core.service.metadata.online.TheMovieDbScanner.java
private String getMovieId(VideoData videoData, boolean throwTempError) { String tmdbId = videoData.getSourceDbId(SCANNER_ID); if (StringUtils.isNumeric(tmdbId)) { return tmdbId; }//from w w w. j ava 2s . com String imdbId = videoData.getSourceDbId(ImdbScanner.SCANNER_ID); if (StringUtils.isNotBlank(imdbId)) { // Search based on IMDb ID LOG.debug("Using IMDb id {} for '{}'", imdbId, videoData.getTitle()); MovieInfo movieDb = tmdbApiWrapper.getMovieInfoByIMDB(imdbId, throwTempError); if (movieDb != null && movieDb.getId() != 0) { tmdbId = String.valueOf(movieDb.getId()); } } if (!StringUtils.isNumeric(tmdbId)) { LOG.debug("No TMDb id found for '{}', searching title with year {}", videoData.getTitle(), videoData.getPublicationYear()); tmdbId = tmdbApiWrapper.getMovieDbId(videoData.getTitle(), videoData.getPublicationYear(), throwTempError); videoData.setSourceDbId(SCANNER_ID, tmdbId); } if (!StringUtils.isNumeric(tmdbId) && StringUtils.isNotBlank(videoData.getTitleOriginal())) { LOG.debug("No TMDb id found for '{}', searching original title with year {}", videoData.getTitleOriginal(), videoData.getPublicationYear()); tmdbId = tmdbApiWrapper.getMovieDbId(videoData.getTitleOriginal(), videoData.getPublicationYear(), throwTempError); videoData.setSourceDbId(SCANNER_ID, tmdbId); } if (StringUtils.isNumeric(tmdbId)) { videoData.setSourceDbId(SCANNER_ID, tmdbId); return tmdbId; } return null; }
From source file:org.yamj.core.service.metadata.online.TheMovieDbScanner.java
@Override public ScanResult scan(VideoData videoData) { MovieInfo movieDb = null;// w w w . j a v a 2 s. c o m MediaCreditList movieCasts = null; try { boolean throwTempError = configServiceWrapper .getBooleanProperty("themoviedb.throwError.tempUnavailable", Boolean.TRUE); String tmdbId = getMovieId(videoData, throwTempError); if (!StringUtils.isNumeric(tmdbId)) { LOG.debug("TMDb id not available '{}'", videoData.getTitle()); return ScanResult.MISSING_ID; } movieDb = tmdbApiWrapper.getMovieInfoByTMDB(Integer.parseInt(tmdbId), throwTempError); movieCasts = tmdbApiWrapper.getMovieCredits(movieDb.getId(), throwTempError); } catch (TemporaryUnavailableException ex) { // check retry int maxRetries = configServiceWrapper.getIntProperty("themoviedb.maxRetries.movie", 0); if (videoData.getRetries() < maxRetries) { return ScanResult.RETRY; } } if (movieDb == null || movieCasts == null) { LOG.error("Can't find informations for movie '{}'", videoData.getTitle()); return ScanResult.ERROR; } // fill in data videoData.setSourceDbId(ImdbScanner.SCANNER_ID, StringUtils.trim(movieDb.getImdbID())); if (OverrideTools.checkOverwriteTitle(videoData, SCANNER_ID)) { videoData.setTitle(StringUtils.trim(movieDb.getTitle()), SCANNER_ID); } if (OverrideTools.checkOverwritePlot(videoData, SCANNER_ID)) { videoData.setPlot(StringUtils.trim(movieDb.getOverview()), SCANNER_ID); } if (OverrideTools.checkOverwriteOutline(videoData, SCANNER_ID)) { videoData.setOutline(StringUtils.trim(movieDb.getOverview()), SCANNER_ID); } if (OverrideTools.checkOverwriteTagline(videoData, SCANNER_ID)) { videoData.setOutline(StringUtils.trim(movieDb.getTagline()), SCANNER_ID); } if (OverrideTools.checkOverwriteCountries(videoData, SCANNER_ID)) { Set<String> countryNames = new LinkedHashSet<>(); for (ProductionCountry country : movieDb.getProductionCountries()) { countryNames.add(country.getName()); } videoData.setCountryNames(countryNames, SCANNER_ID); } String releaseDateString = movieDb.getReleaseDate(); if (StringUtils.isNotBlank(releaseDateString) && !"1900-01-01".equals(releaseDateString)) { Date releaseDate = MetadataTools.parseToDate(releaseDateString); if (releaseDate != null) { if (OverrideTools.checkOverwriteReleaseDate(videoData, SCANNER_ID)) { videoData.setReleaseDate(releaseDate, SCANNER_ID); } if (OverrideTools.checkOverwriteYear(videoData, SCANNER_ID)) { videoData.setPublicationYear(MetadataTools.extractYearAsInt(releaseDate), SCANNER_ID); } } } if (CollectionUtils.isNotEmpty(movieDb.getGenres())) { if (OverrideTools.checkOverwriteGenres(videoData, SCANNER_ID)) { Set<String> genreNames = new HashSet<>(); for (com.omertron.themoviedbapi.model.Genre genre : movieDb.getGenres()) { if (StringUtils.isNotBlank(genre.getName())) { genreNames.add(StringUtils.trim(genre.getName())); } } videoData.setGenreNames(genreNames, SCANNER_ID); } } if (CollectionUtils.isNotEmpty(movieDb.getProductionCompanies())) { if (OverrideTools.checkOverwriteStudios(videoData, SCANNER_ID)) { Set<String> studioNames = new HashSet<>(); for (ProductionCompany company : movieDb.getProductionCompanies()) { if (StringUtils.isNotBlank(company.getName())) { studioNames.add(StringUtils.trim(company.getName())); } } videoData.setStudioNames(studioNames, SCANNER_ID); } } // CAST if (!this.configServiceWrapper.isCastScanEnabled(JobType.ACTOR)) { for (MediaCreditCast person : movieCasts.getCast()) { CreditDTO credit = new CreditDTO(SCANNER_ID, String.valueOf(person.getId()), JobType.ACTOR, person.getName(), person.getCharacter()); videoData.addCreditDTO(credit); } } // GUEST STARS if (!this.configServiceWrapper.isCastScanEnabled(JobType.GUEST_STAR)) { for (MediaCreditCast person : movieCasts.getGuestStars()) { CreditDTO credit = new CreditDTO(SCANNER_ID, String.valueOf(person.getId()), JobType.GUEST_STAR, person.getName(), person.getCharacter()); videoData.addCreditDTO(credit); } } // CREW for (MediaCreditCrew person : movieCasts.getCrew()) { JobType jobType = retrieveJobType(person.getDepartment()); if (!this.configServiceWrapper.isCastScanEnabled(jobType)) { // scan not enabled for that job continue; } CreditDTO credit = new CreditDTO(SCANNER_ID, String.valueOf(person.getId()), jobType, person.getName(), person.getJob()); videoData.addCreditDTO(credit); } return ScanResult.OK; }
From source file:org.yamj.core.service.metadata.online.TheMovieDbScanner.java
private String getPersonId(Person person, boolean throwTempError) { String tmdbId = person.getSourceDbId(SCANNER_ID); if (StringUtils.isNumeric(tmdbId)) { return tmdbId; }/*from w w w.j ava2s .c om*/ if (StringUtils.isNotBlank(person.getName())) { tmdbId = tmdbApiWrapper.getPersonId(person.getName(), throwTempError); person.setSourceDbId(SCANNER_ID, tmdbId); } return tmdbId; }
From source file:org.yamj.core.service.metadata.online.TheMovieDbScanner.java
@Override public ScanResult scan(Person person) { PersonInfo tmdbPerson = null;/*from ww w .j ava 2 s .c om*/ try { boolean throwTempError = configServiceWrapper .getBooleanProperty("themoviedb.throwError.tempUnavailable", Boolean.TRUE); String tmdbId = getPersonId(person, throwTempError); if (!StringUtils.isNumeric(tmdbId)) { LOG.debug("TMDb id not available '{}'", person.getName()); return ScanResult.MISSING_ID; } tmdbPerson = tmdbApiWrapper.getPersonInfo(Integer.parseInt(tmdbId), throwTempError); } catch (TemporaryUnavailableException ex) { // check retry int maxRetries = configServiceWrapper.getIntProperty("themoviedb.maxRetries.person", 0); if (person.getRetries() < maxRetries) { return ScanResult.RETRY; } } if (tmdbPerson == null) { LOG.error("Can't find information for person '{}'", person.getName()); return ScanResult.ERROR; } // fill in data person.setSourceDbId(ImdbScanner.SCANNER_ID, StringUtils.trim(tmdbPerson.getImdbId())); if (OverrideTools.checkOverwritePersonNames(person, SCANNER_ID)) { // split person names PersonNameDTO nameDTO = MetadataTools.splitFullName(tmdbPerson.getName()); if (OverrideTools.checkOverwriteName(person, SCANNER_ID)) { person.setName(nameDTO.getName(), SCANNER_ID); } if (OverrideTools.checkOverwriteName(person, SCANNER_ID)) { person.setFirstName(nameDTO.getFirstName(), SCANNER_ID); } if (OverrideTools.checkOverwriteLastName(person, SCANNER_ID)) { person.setLastName(nameDTO.getLastName(), SCANNER_ID); } } if (OverrideTools.checkOverwriteBirthDay(person, SCANNER_ID)) { Date parsedDate = MetadataTools.parseToDate(tmdbPerson.getBirthday()); person.setBirthDay(parsedDate, SCANNER_ID); } if (OverrideTools.checkOverwriteBirthPlace(person, SCANNER_ID)) { person.setBirthPlace(StringUtils.trimToNull(tmdbPerson.getPlaceOfBirth()), SCANNER_ID); } if (OverrideTools.checkOverwriteBirthName(person, SCANNER_ID)) { if (CollectionUtils.isNotEmpty(tmdbPerson.getAlsoKnownAs())) { String birthName = tmdbPerson.getAlsoKnownAs().get(0); person.setBirthName(birthName, SCANNER_ID); } } if (OverrideTools.checkOverwriteDeathDay(person, SCANNER_ID)) { Date parsedDate = MetadataTools.parseToDate(tmdbPerson.getDeathday()); person.setDeathDay(parsedDate, SCANNER_ID); } if (OverrideTools.checkOverwriteBiography(person, SCANNER_ID)) { person.setBiography(cleanBiography(tmdbPerson.getBiography()), SCANNER_ID); } return ScanResult.OK; }
From source file:org.yamj.core.service.metadata.online.TheMovieDbScanner.java
@Override public ScanResult scanFilmography(Person person) { PersonCreditList<CreditBasic> credits = null; try {/*from ww w.j a v a 2 s . c o m*/ boolean throwTempError = configServiceWrapper .getBooleanProperty("themoviedb.throwError.tempUnavailable", Boolean.TRUE); String tmdbId = getPersonId(person, throwTempError); if (!StringUtils.isNumeric(tmdbId)) { LOG.debug("TMDb id not available '{}'", person.getName()); return ScanResult.MISSING_ID; } credits = tmdbApiWrapper.getPersonCredits(Integer.parseInt(tmdbId), throwTempError); } catch (TemporaryUnavailableException ex) { // check retry int maxRetries = configServiceWrapper.getIntProperty("themoviedb.maxRetries.filmography", 0); if (person.getRetries() < maxRetries) { return ScanResult.RETRY; } } if (credits == null) { LOG.error("Can't find filmography for person '{}'", person.getName()); return ScanResult.ERROR; } // fill in data Set<FilmParticipation> newFilmography = new HashSet<>(); for (CreditBasic credit : credits.getCast()) { JobType jobType = retrieveJobType(credit.getDepartment()); if (jobType == null) { // job type must be present continue; } FilmParticipation filmo = null; switch (credit.getMediaType()) { case MOVIE: filmo = convertMovieCreditToFilm((CreditMovieBasic) credit, person, jobType); break; case TV: LOG.debug("TV credit information for {} ({}) not used: {}", person.getName(), jobType, credit.toString()); break; case EPISODE: LOG.debug("TV Episode credit information for {} ({}) not used: {}", person.getName(), jobType, credit.toString()); break; default: LOG.debug("Unknown media type '{}' for credit {}", credit.getMediaType(), credit.toString()); } if (filmo != null) { newFilmography.add(filmo); } } person.setNewFilmography(newFilmography); return ScanResult.OK; }
From source file:org.yamj.core.service.metadata.online.TheTVDbScanner.java
@Override public ScanResult scan(Series series) { com.omertron.thetvdbapi.model.Series tvdbSeries = null; List<Actor> tvdbActors = null; try {/*from ww w . j av a2 s .c o m*/ boolean throwTempError = configServiceWrapper.getBooleanProperty("thetvdb.throwError.tempUnavailable", Boolean.TRUE); String tvdbId = getSeriesId(series, throwTempError); if (StringUtils.isBlank(tvdbId)) { LOG.debug("TVDb id not available '{}'", series.getTitle()); return ScanResult.MISSING_ID; } tvdbSeries = tvdbApiWrapper.getSeries(tvdbId, throwTempError); tvdbActors = tvdbApiWrapper.getActors(tvdbSeries.getId(), throwTempError); } catch (TemporaryUnavailableException ex) { // check retry int maxRetries = this.configServiceWrapper.getIntProperty("thetvdb.maxRetries.tvshow", 0); if (series.getRetries() < maxRetries) { return ScanResult.RETRY; } } if (tvdbSeries == null || StringUtils.isBlank(tvdbSeries.getId()) || tvdbActors == null) { LOG.error("Can't find informations for series '{}'", series.getTitle()); return ScanResult.ERROR; } series.setSourceDbId(SCANNER_ID, tvdbSeries.getId()); series.setSourceDbId(ImdbScanner.SCANNER_ID, tvdbSeries.getImdbId()); if (OverrideTools.checkOverwriteTitle(series, SCANNER_ID)) { series.setTitle(tvdbSeries.getSeriesName(), SCANNER_ID); } if (OverrideTools.checkOverwritePlot(series, SCANNER_ID)) { series.setPlot(tvdbSeries.getOverview(), SCANNER_ID); } if (OverrideTools.checkOverwriteOutline(series, SCANNER_ID)) { series.setOutline(tvdbSeries.getOverview(), SCANNER_ID); } if (StringUtils.isNumeric(tvdbSeries.getRating())) { try { series.addRating(SCANNER_ID, (int) (Float.parseFloat(tvdbSeries.getRating()) * 10)); } catch (NumberFormatException nfe) { LOG.warn("Failed to convert TVDB rating '{}' to an integer: {}", tvdbSeries.getRating(), nfe.getMessage()); } } if (OverrideTools.checkOverwriteYear(series, SCANNER_ID)) { String faDate = tvdbSeries.getFirstAired(); if (StringUtils.isNotBlank(faDate) && (faDate.length() >= 4)) { try { series.setStartYear(Integer.parseInt(faDate.substring(0, 4)), SCANNER_ID); } catch (Exception ignore) { // ignore error if year is invalid } } } if (OverrideTools.checkOverwriteGenres(series, SCANNER_ID)) { series.setGenreNames(new LinkedHashSet<>(tvdbSeries.getGenres()), SCANNER_ID); } if (OverrideTools.checkOverwriteStudios(series, SCANNER_ID)) { String studioName = StringUtils.trimToNull(tvdbSeries.getNetwork()); if (studioName != null) { Set<String> studioNames = Collections.singleton(studioName); series.setStudioNames(studioNames, SCANNER_ID); } } // CAST & CREW Set<CreditDTO> actors = new LinkedHashSet<>(); if (this.configServiceWrapper.isCastScanEnabled(JobType.ACTOR)) { for (Actor actor : tvdbActors) { actors.add(new CreditDTO(SCANNER_ID, JobType.ACTOR, actor.getName(), actor.getRole())); } } // SCAN SEASONS this.scanSeasons(series, tvdbSeries, actors); return ScanResult.OK; }
From source file:org.yamj.core.service.plugin.TheMovieDbScanner.java
@Override public ScanResult scan(Person person) { String id = getPersonId(person); if (StringUtils.isBlank(id) || !StringUtils.isNumeric(id)) { return ScanResult.MISSING_ID; }/* w ww. j a v a 2 s. co m*/ try { LOG.debug("Getting information on {}-'{}' from {}", person.getId(), person.getName(), SCANNER_ID); com.omertron.themoviedbapi.model.Person tmdbPerson = tmdbApi.getPersonInfo(Integer.parseInt(id)); person.setBiography(cleanBiography(tmdbPerson.getBiography())); person.setBirthPlace(StringUtils.trimToNull(tmdbPerson.getBirthplace())); person.setPersonId(ImdbScanner.SCANNER_ID, StringUtils.trim(tmdbPerson.getImdbId())); Date parsedDate = parseDate(tmdbPerson.getBirthday()); if (parsedDate != null) { person.setBirthDay(parsedDate); } parsedDate = parseDate(tmdbPerson.getDeathday()); if (parsedDate != null) { person.setDeathDay(parsedDate); } } catch (MovieDbException ex) { LOG.warn("Failed to get information on {}-'{}', error: {}", id, person.getName(), ex.getMessage()); return ScanResult.ERROR; } LOG.debug("Successfully processed person: {}-'{}'", id, person.getName()); return ScanResult.OK; }
From source file:org.yamj.core.service.plugin.TheTVDbScanner.java
@Override public ScanResult scan(Series series) { String id = getSeriesId(series); if (StringUtils.isBlank(id)) { return ScanResult.MISSING_ID; }/* w w w . j a va2 s . c om*/ com.omertron.thetvdbapi.model.Series tvdbSeries = tvdbApiWrapper.getSeries(id); series.setSourceDbId(SCANNER_ID, tvdbSeries.getId()); series.setSourceDbId(ImdbScanner.SCANNER_ID, tvdbSeries.getImdbId()); if (OverrideTools.checkOverwriteTitle(series, SCANNER_ID)) { series.setTitle(StringUtils.trim(tvdbSeries.getSeriesName()), SCANNER_ID); } if (OverrideTools.checkOverwritePlot(series, SCANNER_ID)) { series.setPlot(StringUtils.trim(tvdbSeries.getOverview()), SCANNER_ID); } if (OverrideTools.checkOverwriteOutline(series, SCANNER_ID)) { series.setOutline(StringUtils.trim(tvdbSeries.getOverview()), SCANNER_ID); } // Add the genres series.setGenreNames(new HashSet<String>(tvdbSeries.getGenres()), SCANNER_ID); // TODO more values if (StringUtils.isNumeric(tvdbSeries.getRating())) { try { series.addRating(SCANNER_ID, (int) (Float.parseFloat(tvdbSeries.getRating()) * 10)); } catch (NumberFormatException nfe) { LOG.warn("Failed to convert TVDB rating '{}' to an integer, error: {}", tvdbSeries.getRating(), nfe.getMessage()); } } String faDate = tvdbSeries.getFirstAired(); if (StringUtils.isNotBlank(faDate) && (faDate.length() >= 4)) { series.setStartYear(Integer.parseInt(faDate.substring(0, 4))); } // CAST & CREW Set<CreditDTO> actors = new LinkedHashSet<CreditDTO>(); for (Actor actor : tvdbApiWrapper.getActors(id)) { actors.add(new CreditDTO(JobType.ACTOR, actor.getName(), actor.getRole())); } // SCAN SEASONS this.scanSeasons(series, tvdbSeries, actors); return ScanResult.OK; }
From source file:org.yamj.core.service.tasks.ExecutionTaskInitialization.java
@PostConstruct public void init() throws Exception { LOG.debug("Initialize execution tasks"); String[] tasks = PropertyTools.getProperty("execution.task.init.tasks", "").split(","); if (tasks.length > 0) { for (String task : tasks) { boolean valid = true; String name = PropertyTools.getProperty("execution.task." + task + ".name"); if (StringUtils.isBlank(name)) { LOG.warn("Property 'execution.task.{}.name' is not present", task); valid = false;/*from ww w . j av a 2s .c o m*/ } String taskName = PropertyTools.getProperty("execution.task." + task + ".taskName"); if (StringUtils.isBlank(taskName)) { LOG.warn("Property 'execution.task.{}.taskName' is not present", task); valid = false; } String type = PropertyTools.getProperty("execution.task." + task + ".type", IntervalType.UNKNOWN.toString()); IntervalType intervalType = IntervalType.fromString(type); if (IntervalType.UNKNOWN == intervalType) { LOG.warn("Property 'execution.task.{}.type' denotes invalid interval type: {}", task, type); valid = false; } int delay = -1; if (intervalType.needsDelay()) { String delayString = PropertyTools.getProperty("execution.task." + task + ".delay"); if (!StringUtils.isNumeric(delayString)) { LOG.warn("Property 'execution.task.{}.delay' is not numeric: {}", name, delayString); valid = false; } else { delay = Integer.parseInt(delayString); } } String dateString = PropertyTools.getProperty("execution.task." + task + ".nextExecution"); Date nextExecution = MetadataTools.parseToDate(dateString); if (nextExecution == null) { LOG.warn("Property 'execution.task.{}.nextExecution' is no valid date: {}", name, dateString); valid = false; } if (!valid) { LOG.warn("Execution task {} has no valid setup, so skipping", task); continue; } ExecutionTask executionTask = new ExecutionTask(); executionTask.setName(name); executionTask.setTaskName(taskName); executionTask.setIntervalType(intervalType); executionTask.setDelay(delay); executionTask.setNextExecution(nextExecution); executionTask.setOptions(PropertyTools.getProperty("execution.task." + task + ".options")); try { // call another service to handle transactions this.executionTaskStorageService.storeExecutionTask(executionTask); } catch (Exception error) { LOG.error("Failed to store execution task {}", executionTask); LOG.warn("Storage error", error); } } } }
From source file:org.yamj.core.tools.MetadataTools.java
public static int toYear(String string) { int year;//from w w w .jav a 2 s . co m if (StringUtils.isNotBlank(string) && StringUtils.isNumeric(string)) { try { year = Integer.parseInt(string); } catch (NumberFormatException ex) { year = -1; } } else { year = -1; } return year; }