/** * Because the Youtube Video object contains complex objects within its hierarchy, we have to use * a custom deserializer * * @param jsonParser jsonParser * @param deserializationContext deserializationContext * @return The deserialized {@link com.google.api.services.youtube.YouTube.Videos} object * @throws java.io.IOException IOException * @throws com.fasterxml.jackson.core.JsonProcessingException JsonProcessingException */ @Override public Video deserialize(JsonParser jsonParser, DeserializationContext deserializationContext) throws IOException { JsonNode node = jsonParser.getCodec().readTree(jsonParser); Video video = new Video(); try { video.setId(node.get("id").asText()); video.setEtag(node.get("etag").asText()); video.setKind(node.get("kind").asText()); video.setSnippet(buildSnippet(node)); video.setStatistics(buildStatistics(node)); } catch (Exception ex) { LOGGER.error("Exception while trying to deserialize a Video object: {}", ex); } return video; }
private void directTag(final VideoData video) { final Video updateVideo = new Video(); VideoSnippet snippet = video .addTags(Arrays.asList( Constants.DEFAULT_KEYWORD, Upload.generateKeywordFromPlaylistId(Constants.UPLOAD_PLAYLIST))); updateVideo.setSnippet(snippet); updateVideo.setId(video.getYouTubeId()); new AsyncTask<Void, Void, Void>() { @Override protected Void doInBackground(Void... voids) { YouTube youtube = new YouTube.Builder(transport, jsonFactory, credential).setApplicationName(Constants.APP_NAME) .build(); try { youtube.videos().update("snippet", updateVideo).execute(); } catch (UserRecoverableAuthIOException e) { startActivityForResult(e.getIntent(), REQUEST_AUTHORIZATION); } catch (IOException e) { Log.e(TAG, e.getMessage()); } return null; } }.execute((Void) null); Toast.makeText(this, R.string.video_submitted_to_ytdl, Toast.LENGTH_LONG) .show(); }