private ItemAndBroadcast getClosedEpisode( Brand brand, ProgData progData, Channel channel, DateTimeZone zone, Timestamp updatedAt) { String uri = CLOSED_EPISODE + getClosedPostfix(channel); Maybe<Identified> resolvedContent = contentResolver.findByCanonicalUris(ImmutableList.of(uri)).getFirstValue(); Episode episode; if (resolvedContent.hasValue() && resolvedContent.requireValue() instanceof Episode) { episode = (Episode) resolvedContent.requireValue(); } else { episode = (Episode) getBasicEpisode(progData, true); } episode.setCanonicalUri(uri); episode.setCurie(CLOSED_CURIE + getClosedPostfix(channel)); episode.setTitle(progData.getTitle()); episode.setScheduleOnly(true); episode.setMediaType(channel.getMediaType()); Version version = findBestVersion(episode.getVersions()); Broadcast broadcast = broadcast(progData, channel, zone, updatedAt); addBroadcast(version, broadcast); return new ItemAndBroadcast(episode, Maybe.just(broadcast)); }
private Integer duration(Episode episode) { for (Version version : episode.getVersions()) { Integer duration = version.getDuration(); if (duration != null) { return duration; } } return null; }
private List<Broadcast> extractBroadcasts(Iterable<Episode> episodes) { List<Broadcast> broadcasts = Lists.newArrayList(); for (Episode episode : episodes) { for (Version version : episode.getVersions()) { broadcasts.addAll(version.getBroadcasts()); } } return broadcasts; }
private DateTime extractLastAvailabilityDate(Episode episode) { for (Version version : episode.getVersions()) { for (Encoding encoding : version.getManifestedAs()) { for (Location location : encoding.getAvailableAt()) { if (location.getPolicy() != null && Platform.XBOX.equals(location.getPolicy().getPlatform()) && location.getPolicy().getAvailabilityStart() != null) { return location.getPolicy().getAvailabilityEnd(); } } } } return null; }
private String extractAssetId(Episode episode) { for (Version version : episode.getVersions()) { for (Encoding encoding : version.getManifestedAs()) { for (Location location : encoding.getAvailableAt()) { if (location.getTransportType().equals(TransportType.LINK) && location.getPolicy() != null && Platform.XBOX.equals(location.getPolicy().getPlatform())) { Pattern pattern = Pattern.compile(".*asset/(\\d+).*"); Matcher matcher = pattern.matcher(location.getUri()); if (matcher.matches()) { return matcher.group(1); } } } } } return "NONE"; }
@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); }