private void addBroadcast(Version version, Broadcast newBroadcast) {
    if (Strings.isNullOrEmpty(newBroadcast.getSourceId())) {
      return;
    }

    Set<Broadcast> broadcasts = Sets.newHashSet();
    Interval newBroadcastInterval = newBroadcast.transmissionInterval().requireValue();

    for (Broadcast existingBroadcast : version.getBroadcasts()) {
      if (newBroadcast.getSourceId().equals(existingBroadcast.getSourceId())) {
        continue;
      }
      if (existingBroadcast.transmissionInterval().hasValue()) {
        Interval currentInterval = existingBroadcast.transmissionInterval().requireValue();
        if (existingBroadcast.getBroadcastOn().equals(newBroadcast.getBroadcastOn())
            && currentInterval.overlaps(newBroadcastInterval)) {
          continue;
        }
      }
      broadcasts.add(existingBroadcast);
    }
    broadcasts.add(newBroadcast);

    version.setBroadcasts(broadcasts);
  }
Exemple #2
0
 private void updateSchedule(Item item) {
   Iterable<Broadcast> broadcasts =
       Iterables.concat(Iterables.transform(item.getVersions(), Version.TO_BROADCASTS));
   for (Broadcast broadcast : broadcasts) {
     Maybe<Channel> channel = channelResolver.fromUri(broadcast.getBroadcastOn());
     if (channel.hasValue()) {
       scheduleWriter.replaceScheduleBlock(
           item.getPublisher(),
           channel.requireValue(),
           ImmutableSet.of(new ScheduleEntry.ItemRefAndBroadcast(item, broadcast)));
     }
   }
 }
Exemple #3
0
 private Broadcast broadcastFrom(WsProgramme programme) {
   if (!Strings.isNullOrEmpty(programme.getFirstTxDate())
       && !Strings.isNullOrEmpty(programme.getProgDuration())) {
     DateTime start = dayFormatter.parseDateTime(programme.getFirstTxDate());
     if (start.isAfter(BBC_FOUNDED)) {
       Broadcast broadcast =
           new Broadcast(
               BBC_WORLD_SERVICE_URI,
               start,
               standardSeconds(parseInt(programme.getProgDuration())));
       broadcast.setScheduleDate(start.toLocalDate());
       return broadcast;
     }
   }
   return null;
 }
  private Broadcast broadcast(
      ProgData progData, Channel channel, DateTimeZone zone, Timestamp updateAt) {
    Duration duration = Duration.standardMinutes(Long.valueOf(progData.getDuration()));

    DateTime transmissionTime = getTransmissionTime(progData.getDate(), progData.getTime(), zone);

    Broadcast broadcast =
        new Broadcast(channel.getUri(), transmissionTime, duration)
            .withId(PaHelper.getBroadcastId(progData.getShowingId()));

    if (progData.getAttr() != null) {
      broadcast.setRepeat(isRepeat(channel, progData.getAttr()));
      broadcast.setSubtitled(getBooleanValue(progData.getAttr().getSubtitles()));
      broadcast.setSigned(getBooleanValue(progData.getAttr().getSignLang()));
      broadcast.setAudioDescribed(getBooleanValue(progData.getAttr().getAudioDes()));
      broadcast.setHighDefinition(getBooleanValue(progData.getAttr().getHd()));
      broadcast.setWidescreen(getBooleanValue(progData.getAttr().getWidescreen()));
      broadcast.setLive(getBooleanValue(progData.getAttr().getLive()));
      broadcast.setSurround(getBooleanValue(progData.getAttr().getSurround()));
      broadcast.setPremiere(getBooleanValue(progData.getAttr().getPremiere()));

      Boolean newSeries = getBooleanValue(progData.getAttr().getNewSeries());
      Boolean newEpisode = getBooleanValue(progData.getAttr().getNewEpisode());

      broadcast.setNewSeries(newSeries);
      broadcast.setNewEpisode(isNewEpisode(newSeries, newEpisode));
    }
    broadcast.setLastUpdated(updateAt.toDateTimeUTC());
    return broadcast;
  }
 @Override
 public int compare(Broadcast o1, Broadcast o2) {
   return o1.getTransmissionTime().compareTo(o2.getTransmissionTime());
 }
Exemple #6
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);
  }