Example #1
0
  private Item getBasicEpisodeWithoutBroadcast(ProgData progData, boolean isEpisode) {
    String episodeUri = PaHelper.getEpisodeUri(identifierFor(progData));

    Maybe<Identified> possiblePrevious =
        contentResolver.findByCanonicalUris(ImmutableList.of(episodeUri)).getFirstValue();

    Item item;
    if (possiblePrevious.hasValue()) {
      Item previous = (Item) possiblePrevious.requireValue();

      if (!(previous instanceof Episode) && isEpisode) {
        String message =
            String.format(
                "%s resolved as %s being ingested as Episode",
                episodeUri, previous.getClass().getSimpleName());

        adapterLog.record(warnEntry().withSource(getClass()).withDescription(message));
        log.info(message);

        item = convertItemToEpisode(previous);
      } else if (previous instanceof Episode && !isEpisode) {
        String message =
            String.format(
                "%s resolved as %s being ingested as Item",
                episodeUri, previous.getClass().getSimpleName());

        adapterLog.record(errorEntry().withSource(getClass()).withDescription(message));
        log.info(message);

        item = new Item();
        Item.copyTo(previous, item);
      } else {
        item = previous;
      }
    } else {
      item = getBasicEpisode(progData, isEpisode);
    }

    if (SCHEDULED_ONLY_EPISODE.equals(episodeUri)) {
      item.setScheduleOnly(true);
    }

    item.addAlias(PaHelper.getEpisodeAlias(identifierFor(progData)));

    try {
      if (item instanceof Episode) {
        Episode episode = (Episode) item;
        episode.setSpecial(getBooleanValue(progData.getAttr().getSpecial()));
        episode.setEpisodeNumber(episodeNumber(progData));
        episode.setSeriesNumber(seriesNumber(progData));
      }
    } catch (NumberFormatException e) {
      // sometimes we don't get valid numbers
      log.warn("Failed to parse a numeric field for PA episode {}", episodeUri, e);
    }
    return item;
  }
Example #2
0
  private ItemAndBroadcast getEpisode(
      ProgData progData,
      Channel channel,
      DateTimeZone zone,
      boolean isEpisode,
      Timestamp updatedAt) {

    String episodeUri = PaHelper.getEpisodeUri(identifierFor(progData));
    Maybe<Identified> possiblePrevious =
        contentResolver.findByCanonicalUris(ImmutableList.of(episodeUri)).getFirstValue();

    Item item;
    if (possiblePrevious.hasValue()) {
      item = (Item) possiblePrevious.requireValue();
      if (!(item instanceof Episode) && isEpisode) {
        log.record(
            warnEntry()
                .withSource(getClass())
                .withDescription(
                    "%s resolved as %s being ingested as Episode",
                    episodeUri, item.getClass().getSimpleName()));
        item = convertItemToEpisode(item);
      } else if (item instanceof Episode && !isEpisode) {
        log.record(
            errorEntry()
                .withSource(getClass())
                .withDescription(
                    "%s resolved as %s being ingested as Item",
                    episodeUri, item.getClass().getSimpleName()));
      }
    } else {
      item = getBasicEpisode(progData, isEpisode);
    }

    item.addAlias(PaHelper.getEpisodeAlias(identifierFor(progData)));

    Broadcast broadcast = setCommonDetails(progData, channel, zone, item, updatedAt);

    try {
      if (item instanceof Episode) {
        Episode episode = (Episode) item;
        episode.setSpecial(getBooleanValue(progData.getAttr().getSpecial()));
        episode.setEpisodeNumber(episodeNumber(progData));
        episode.setSeriesNumber(seriesNumber(progData));
      }
    } catch (NumberFormatException e) {
      // sometimes we don't get valid numbers
      // log.
    }

    return new ItemAndBroadcast(item, Maybe.just(broadcast));
  }
Example #3
0
  @Override
  public void handle(WsProgramme programme, Iterable<WsAudioItem> audioItems) {
    checkNotNull(programme.getProgId());
    checkNotNull(programme.getSeriesId());

    String episodeUri = uriFor(programme);

    Maybe<Identified> possibleEpisode =
        resolver.findByCanonicalUris(ImmutableSet.of(episodeUri)).get(episodeUri);

    Episode episode = null;

    if (possibleEpisode.hasValue()) {
      Identified resolved = possibleEpisode.requireValue();
      if (resolved instanceof Episode) {
        episode = (Episode) resolved;
      } else {
        log.record(
            errorEntry()
                .withDescription(
                    "Resolved %s for episode %s", resolved.getClass().getSimpleName(), episodeUri));
        return;
      }
    } else {
      episode = new Episode(episodeUri, curieFor(programme), WORLD_SERVICE);
    }

    episode.setParentRef(new ParentRef(uriForBrand(programme.getSeriesId())));
    episode.setTitle(titleFrom(programme, audioItems));
    episode.setDescription(programme.getSynopsis());
    if (!Strings.isNullOrEmpty(programme.getEpisodeNo())
        && programme.getEpisodeNo().matches("\\d+")) {
      episode.setEpisodeNumber(Integer.parseInt(programme.getEpisodeNo()));
    }
    episode.setGenres(WsGenre.genresForCode(programme.getGenreCode()));
    episode.setMediaType(AUDIO);
    episode.setSpecialization(RADIO);

    if (!Iterables.isEmpty(audioItems)) {
      for (WsAudioItem audioItem : audioItems) {
        Version version = new Version();

        if (!Strings.isNullOrEmpty(audioItem.getDuration())
            && audioItem.getDuration().matches("\\d+")) {
          version.setDuration(new Duration(Long.parseLong(audioItem.getDuration())));
        }

        Policy policy = policyFor(audioItem);

        String broadcastUri = audioItem.getLinkAudioBroadcastQuality();
        if (!Strings.isNullOrEmpty(broadcastUri)) {
          version.addManifestedAs(encodingFrom(policy, broadcastUri, MimeType.AUDIO_WAV));
        }

        String thumbnailUri = audioItem.getLinkAudioThumbnail();
        if (!Strings.isNullOrEmpty(thumbnailUri)) {
          version.addManifestedAs(encodingFrom(policy, thumbnailUri, MimeType.AUDIO_MP3));
        }
        if (!version.getManifestedAs().isEmpty()) {
          episode.addVersion(version);
        }
      }
    }

    Broadcast broadcast = broadcastFrom(programme);
    if (broadcast != null) {
      Version version = Iterables.getFirst(episode.getVersions(), new Version());
      if (version.getDuration() == null) {
        version.setDuration(Duration.standardSeconds(broadcast.getBroadcastDuration()));
      }
      version.addBroadcast(broadcast);
    }

    writer.createOrUpdate(episode);
  }