コード例 #1
0
 private Map<String, Object> getMetadataMetadata(final Upload upload) {
   final Map<String, Object> params = Maps.newHashMapWithExpectedSize(4);
   final Metadata metadata = upload.getMetadata();
   params.put("title", metadata.getTitle());
   params.put("description", Strings.nullToEmpty(metadata.getDescription()));
   params.put(
       "keywords",
       Joiner.on(TagParser.TAG_DELIMITER)
           .skipNulls()
           .join(TagParser.parse(metadata.getKeywords(), true)));
   params.put(
       "reuse",
       License.YOUTUBE == metadata.getLicense() ? "all_rights_reserved" : "creative_commons");
   return params;
 }
コード例 #2
0
  @Override
  public String atomBuilder(final Upload upload) {
    // create atom xml metadata - create object first, then convert with
    // xstream

    final Metadata metadata = upload.getMetadata();
    final VideoEntry videoEntry = new VideoEntry();
    videoEntry.mediaGroup.category = new ArrayList<>(1);
    videoEntry.mediaGroup.category.add(metadata.getCategory().toCategory());
    videoEntry.mediaGroup.license = metadata.getLicense().getMetaIdentifier();
    videoEntry.mediaGroup.title = metadata.getTitle();
    videoEntry.mediaGroup.description = metadata.getDescription();
    videoEntry.mediaGroup.keywords =
        Joiner.on(TagParser.TAG_DELIMITER)
            .skipNulls()
            .join(TagParser.parse(metadata.getKeywords()));
    final Permissions permissions = upload.getPermissions();

    if (Visibility.PRIVATE == permissions.getVisibility()
        || Visibility.SCHEDULED == permissions.getVisibility()) {
      videoEntry.mediaGroup.ytPrivate = new Object();
    }

    videoEntry.accessControl.add(
        new YoutubeAccessControl(
            "embed", PermissionStringConverter.convertBoolean(permissions.isEmbed())));
    videoEntry.accessControl.add(
        new YoutubeAccessControl(
            "rate", PermissionStringConverter.convertBoolean(permissions.isRate())));
    videoEntry.accessControl.add(
        new YoutubeAccessControl(
            "commentVote", PermissionStringConverter.convertBoolean(permissions.isCommentvote())));
    videoEntry.accessControl.add(
        new YoutubeAccessControl(
            "comment",
            PermissionStringConverter.convertInteger(permissions.getComment().ordinal())));
    videoEntry.accessControl.add(
        new YoutubeAccessControl(
            "list",
            PermissionStringConverter.convertBoolean(
                Visibility.PUBLIC == permissions.getVisibility())));

    // convert metadata with xstream
    final XStream xStream =
        new XStream(
            new DomDriver(Charsets.UTF_8.name()) {
              @Override
              public HierarchicalStreamWriter createWriter(final Writer out) {
                return new PrettyPrintWriter(out) {
                  boolean isCDATA;

                  @Override
                  public void startNode(
                      final String name, @SuppressWarnings("rawtypes") final Class clazz) {
                    super.startNode(name, clazz);
                    isCDATA =
                        "media:description".equals(name)
                            || "media:keywords".equals(name)
                            || "media:title".equals(name);
                  }

                  @Override
                  protected void writeText(final QuickWriter writer, String text) {
                    final String tmpText = Strings.nullToEmpty(text);
                    text = "null".equals(tmpText) ? "" : tmpText;
                    if (isCDATA) {
                      writer.write("<![CDATA[");
                      writer.write(text);
                      writer.write("]]>");
                    } else {
                      super.writeText(writer, text);
                    }
                  }
                };
              }
            });
    xStream.autodetectAnnotations(true);

    return String.format("<?xml version=\"1.0\" encoding=\"UTF-8\"?>%s", xStream.toXML(videoEntry));
  }
コード例 #3
0
  private Map<String, Object> getMetadataMonetization(final String content, final Upload upload) {
    final Map<String, Object> params = Maps.newHashMapWithExpectedSize(MONETIZE_PARAMS_SIZE);
    final Metadata metadata = upload.getMetadata();
    final Monetization monetization = upload.getMonetization();
    if (monetization.isClaim() && License.YOUTUBE == upload.getMetadata().getLicense()) {
      params.put("video_monetization_style", "ads");
      if (!monetization.isPartner() || ClaimOption.MONETIZE == monetization.getClaimoption()) {
        params.put("claim_style", "ads");
        params.put("enable_overlay_ads", boolConverter(monetization.isOverlay()));
        params.put("trueview_instream", boolConverter(monetization.isTrueview()));
        params.put("instream", boolConverter(monetization.isInstream()));
        params.put("long_ads_checkbox", boolConverter(monetization.isInstreamDefaults()));
        params.put("paid_product", boolConverter(monetization.isProduct()));
        params.put(
            "allow_syndication",
            boolConverter(Syndication.GLOBAL == monetization.getSyndication()));
      }
      if (monetization.isPartner()) {
        params.put(
            "claim_type",
            ClaimType.AUDIO_VISUAL == monetization.getClaimtype()
                ? "B"
                : ClaimType.VISUAL == monetization.getClaimtype() ? "V" : "A");

        final String toFind =
            ClaimOption.MONETIZE == monetization.getClaimoption()
                ? "Monetize in all countries"
                : ClaimOption.TRACK == monetization.getClaimoption()
                    ? "Track in all countries"
                    : "Block in all countries";

        final Pattern pattern =
            Pattern.compile(
                "<option\\s*value=\"([^\"]+?)\"\\s*(selected(=\"\")?)?\\sdata-is-monetized-policy=\"(true|false)\"\\s*>\\s*([^<]+?)\\s*</option>");
        final Matcher matcher = pattern.matcher(content);

        String usagePolicy = null;
        int position = 0;
        while (matcher.find(position)) {
          position = matcher.end();
          if (matcher.group(5).trim().equals(toFind)) {
            usagePolicy = matcher.group(1);
          }
        }
        params.put("usage_policy", usagePolicy);

        final String assetName = monetization.getAsset().name().toLowerCase(Locale.getDefault());

        params.put("asset_type", assetName);
        params.put(
            assetName + "_custom_id",
            monetization.getCustomId().isEmpty()
                ? upload.getVideoid()
                : monetization.getCustomId());

        params.put(assetName + "_notes", monetization.getNotes());
        params.put(assetName + "_tms_id", monetization.getTmsid());
        params.put(assetName + "_isan", monetization.getIsan());
        params.put(assetName + "_eidr", monetization.getEidr());

        if (Asset.TV != monetization.getAsset()) {
          // WEB + MOVIE ONLY
          params.put(
              assetName + "_title",
              !monetization.getTitle().isEmpty() ? monetization.getTitle() : metadata.getTitle());
          params.put(assetName + "_description", monetization.getDescription());
        } else {
          // TV ONLY
          params.put("show_title", monetization.getTitle());
          params.put("episode_title", monetization.getTitleepisode());
          params.put("season_nb", monetization.getSeasonNb());
          params.put("episode_nb", monetization.getEpisodeNb());
        }
      }
    }

    return params;
  }