Beispiel #1
0
  @Test
  public void testMergesHDandSDforFilms() {
    BtVodEntry btVodEntrySD = filmRow("About Alex");
    btVodEntrySD.setProductTargetBandwidth("SD");

    BtVodEntry btVodEntryHD = filmRow("About Alex - HD");
    btVodEntryHD.setGuid(PRODUCT_GUID + "_HD");
    btVodEntryHD.setProductTargetBandwidth("HD");

    when(imageExtractor.imagesFor(Matchers.<BtVodEntry>any())).thenReturn(ImmutableSet.<Image>of());

    when(btVodBrandProvider.brandRefFor(btVodEntrySD)).thenReturn(Optional.<ParentRef>absent());
    when(btVodBrandProvider.brandRefFor(btVodEntryHD)).thenReturn(Optional.<ParentRef>absent());

    when(seriesProvider.seriesFor(btVodEntryHD)).thenReturn(Optional.<Series>absent());
    when(seriesProvider.seriesFor(btVodEntrySD)).thenReturn(Optional.<Series>absent());

    itemExtractor.process(btVodEntrySD);
    itemExtractor.process(btVodEntryHD);

    Item writtenItem = Iterables.getOnlyElement(itemExtractor.getProcessedItems().values());

    assertThat(writtenItem.getTitle(), is("About Alex"));
    assertThat(writtenItem.getDescription(), is(SYNOPSIS));

    assertThat(writtenItem.getVersions().size(), is(2));

    Version hdVersion = Iterables.get(writtenItem.getVersions(), 0);
    Version sdVersion = Iterables.get(writtenItem.getVersions(), 1);
    assertThat(
        Iterables.getOnlyElement(sdVersion.getManifestedAs()).getHighDefinition(), is(false));
    assertThat(Iterables.getOnlyElement(hdVersion.getManifestedAs()).getHighDefinition(), is(true));
  }
  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);
  }
  private Version findBestVersion(Iterable<Version> versions) {
    for (Version version : versions) {
      if (version.getProvider() == Publisher.PA) {
        return version;
      }
    }

    return versions.iterator().next();
  }
 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;
 }
Beispiel #6
0
  private Broadcast addBroadcast(
      ProgData progData, Item item, Channel channel, DateTimeZone zone, Timestamp updatedAt) {
    Version version = findBestVersion(item.getVersions());
    version.set3d(getBooleanValue(progData.getAttr().getThreeD()));
    version.setDuration(Duration.standardMinutes(Long.valueOf(progData.getDuration())));

    Broadcast broadcast = broadcast(progData, channel, zone, updatedAt);
    addBroadcast(version, broadcast);

    return broadcast;
  }
  private void setBasicDetails(ProgData progData, Item item) {
    setCertificate(progData, item);
    Version version = new Version();
    version.setProvider(Publisher.PA);
    version.set3d(getBooleanValue(progData.getAttr().getThreeD()));
    item.addVersion(version);

    Duration duration = Duration.standardMinutes(Long.valueOf(progData.getDuration()));
    version.setDuration(duration);

    item.addVersion(version);
  }
  private Version createVersion(boolean subtitled) {
    Version version = new Version();

    Restriction restriction = new Restriction();
    restriction.setRestricted(true);

    version.setManifestedAs(Sets.newHashSet(createEncoding(subtitled)));

    version.setDuration(Duration.standardMinutes(90));
    version.setCanonicalUri("http://nitro.bbc.co.uk/programmes/b00gszl0");
    version.setRestriction(restriction);

    return version;
  }
 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;
 }
Beispiel #10
0
  @Test
  public void testDoesNotCreatePayToXLocationsWithZeroPrice() {
    BtVodEntry btVodEntry =
        episodeRow(SERIES_TITLE + ": S1 S1-E9 " + REAL_EPISODE_TITLE, PRODUCT_GUID);

    btVodEntry.setProductOfferingType("type-EST");

    BtVodProductPricingPlan pricingPlan = new BtVodProductPricingPlan();

    BtVodProductPricingTier pricingTier = new BtVodProductPricingTier();
    pricingTier.setProductAbsoluteStart(DateTime.now().minusMonths(2).getMillis());
    pricingTier.setProductAbsoluteEnd(DateTime.now().plusMonths(2).getMillis());

    BtVodProductAmounts productAmounts = new BtVodProductAmounts();
    productAmounts.setGBP(0D);

    pricingTier.setProductAmounts(productAmounts);
    pricingPlan.setProductPricingTiers(Lists.newArrayList(pricingTier));
    btVodEntry.setProductPricingPlan(pricingPlan);

    ParentRef parentRef = new ParentRef(BRAND_URI);

    Series series = new Series();
    series.setCanonicalUri("seriesUri");
    series.withSeriesNumber(1);

    when(seriesProvider.seriesFor(btVodEntry)).thenReturn(Optional.of(series));
    when(imageExtractor.imagesFor(Matchers.<BtVodEntry>any())).thenReturn(ImmutableSet.<Image>of());
    when(btVodBrandProvider.brandRefFor(btVodEntry)).thenReturn(Optional.of(parentRef));
    when(seriesProvider.seriesFor(btVodEntry)).thenReturn(Optional.of(series));

    itemExtractor.process(btVodEntry);

    assertThat(itemExtractor.getProcessedItems().size(), is(1));

    Item item = Iterables.getOnlyElement(itemExtractor.getProcessedItems().values());
    Version version = Iterables.getOnlyElement(item.getVersions());
    Encoding encoding = Iterables.getOnlyElement(version.getManifestedAs());

    assertThat(encoding.getAvailableAt().size(), is(1));

    Location location = Iterables.getOnlyElement(encoding.getAvailableAt());
    assertThat(
        location.getCanonicalUri().contains(RevenueContract.PAY_TO_BUY.toString()), is(false));
    assertThat(
        location.getCanonicalUri().contains(RevenueContract.PAY_TO_RENT.toString()), is(false));
  }
 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";
 }
Beispiel #12
0
  private void testHdSdMerging(String hdTitle, String sdTitle, String extractedTitle) {
    BtVodEntry btVodEntrySD = episodeRow(FULL_EPISODE_TITLE, PRODUCT_GUID);
    btVodEntrySD.setTitle(sdTitle);
    ParentRef parentRef = new ParentRef(BRAND_URI);
    btVodEntrySD.setProductTargetBandwidth("SD");

    BtVodEntry btVodEntryHD = episodeRow(FULL_EPISODE_TITLE, PRODUCT_GUID);
    btVodEntryHD.setTitle(hdTitle);
    btVodEntryHD.setGuid(PRODUCT_GUID + "_HD");
    btVodEntryHD.setProductTargetBandwidth("HD");

    Series series = new Series();
    series.setCanonicalUri("seriesUri");
    series.withSeriesNumber(1);

    when(seriesProvider.seriesFor(btVodEntrySD)).thenReturn(Optional.of(series));
    when(seriesProvider.seriesFor(btVodEntryHD)).thenReturn(Optional.of(series));

    when(imageExtractor.imagesFor(Matchers.<BtVodEntry>any())).thenReturn(ImmutableSet.<Image>of());
    when(btVodBrandProvider.brandRefFor(btVodEntrySD)).thenReturn(Optional.of(parentRef));
    when(btVodBrandProvider.brandRefFor(btVodEntryHD)).thenReturn(Optional.of(parentRef));

    itemExtractor.process(btVodEntrySD);
    itemExtractor.process(btVodEntryHD);

    Item writtenItem = Iterables.getOnlyElement(itemExtractor.getProcessedItems().values());

    assertThat(writtenItem.getTitle(), is(extractedTitle));
    assertThat(writtenItem.getDescription(), is(SYNOPSIS));
    assertThat(writtenItem.getContainer(), is(parentRef));

    assertThat(writtenItem.getVersions().size(), is(2));

    Version hdVersion = Iterables.get(writtenItem.getVersions(), 0);
    Version sdVersion = Iterables.get(writtenItem.getVersions(), 1);
    assertThat(
        Iterables.getOnlyElement(sdVersion.getManifestedAs()).getHighDefinition(), is(false));
    assertThat(Iterables.getOnlyElement(hdVersion.getManifestedAs()).getHighDefinition(), is(true));
    assertThat(
        Iterables.getFirst(writtenItem.getClips(), null),
        is(new Clip(TRAILER_URI, TRAILER_URI, Publisher.BT_VOD)));
  }
 private ItemOnDemandHierarchy hierarchyFrom(Item item) {
   Version version = Iterables.getOnlyElement(item.getVersions());
   Encoding encoding = Iterables.getOnlyElement(version.getManifestedAs());
   Location location = Iterables.getOnlyElement(encoding.getAvailableAt());
   return new ItemOnDemandHierarchy(item, version, encoding, location);
 }
Beispiel #14
0
  private Broadcast setCommonDetails(
      ProgData progData, Channel channel, DateTimeZone zone, Item episode, Timestamp updatedAt) {

    // currently Welsh channels have Welsh titles/descriptions
    // which flip the English ones, resulting in many writes. We'll only take the Welsh title if we
    // don't
    // already have a title from another channel
    if (episode.getTitle() == null || !channel.getUri().contains("wales")) {
      if (progData.getEpisodeTitle() != null) {
        episode.setTitle(progData.getEpisodeTitle());
      } else {
        episode.setTitle(progData.getTitle());
      }
    }

    if (progData.getBillings() != null) {
      for (Billing billing : progData.getBillings().getBilling()) {
        if ((episode.getDescription() == null || !channel.getUri().contains("wales"))
            && billing.getType().equals("synopsis")) {
          episode.setDescription(billing.getvalue());
        }
        if ((episode.getShortDescription() == null || !channel.getUri().contains("wales"))
            && billing.getType().equals("pa_detail1")) {
          episode.setShortDescription(billing.getvalue());
        }
        if ((episode.getMediumDescription() == null || !channel.getUri().contains("wales"))
            && billing.getType().equals("pa_detail2")) {
          episode.setMediumDescription(billing.getvalue());
        }
        if ((episode.getLongDescription() == null || !channel.getUri().contains("wales"))
            && billing.getType().equals("pa_detail3")) {
          episode.setLongDescription(billing.getvalue());
        }
      }
    }

    episode.setMediaType(channel.getMediaType());
    episode.setSpecialization(specialization(progData, channel));
    setGenres(progData, episode);

    if (progData.getCountry() != null) {
      episode.setCountriesOfOrigin(countryMap.parseCountries(progData.getCountry()));
    }

    if (progData.getAttr() != null) {
      episode.setBlackAndWhite(getBooleanValue(progData.getAttr().getBw()));
    }

    selectImages(
        progData.getPictures(),
        episode,
        PA_PICTURE_TYPE_EPISODE,
        PA_PICTURE_TYPE_SERIES,
        Maybe.just(PA_PICTURE_TYPE_BRAND));

    episode.setPeople(people(progData));

    Version version = findBestVersion(episode.getVersions());
    version.set3d(getBooleanValue(progData.getAttr().getThreeD()));
    Duration duration = Duration.standardMinutes(Long.valueOf(progData.getDuration()));
    version.setDuration(duration);
    setCertificate(progData, episode);

    Broadcast broadcast = broadcast(progData, channel, zone, updatedAt);
    addBroadcast(version, broadcast);
    return broadcast;
  }
Beispiel #15
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);
  }