use of com.zype.fire.api.Model.VideoResponse in project zype-firebuilder by zype.
the class ZypeApi method getVideo.
public VideoResponse getVideo(String videoId) {
try {
HashMap<String, String> params = new HashMap<>();
params.put(APP_KEY, ZypeSettings.APP_KEY);
Response response = apiImpl.getVideo(videoId, params).execute();
if (response.isSuccessful()) {
return (VideoResponse) response.body();
} else {
return null;
}
} catch (IOException e) {
e.printStackTrace();
return null;
}
}
use of com.zype.fire.api.Model.VideoResponse in project zype-firebuilder by zype.
the class ZypeDataDownloaderHelper method loadFavoriteVideos.
public static VideosResult loadFavoriteVideos(String favoritesPlaylistId, String consumerId, String accessToken, int page) {
Log.d(TAG, "loadFavoriteVideos(): consumerId=" + consumerId);
VideosResult result = new VideosResult();
result.nextPage = page;
boolean loadNext = true;
while (loadNext) {
VideoFavoritesResponse response = ZypeApi.getInstance().getVideoFavorites(consumerId, accessToken, result.nextPage);
if (response != null) {
Log.d(TAG, "loadFavoriteVideos(): size=" + response.videoFavorites.size());
if (result.videos == null) {
result.videos = new ArrayList<>();
}
if (response.pagination.current >= response.pagination.pages) {
result.nextPage = -1;
} else {
result.nextPage = response.pagination.next;
}
for (VideoFavoriteData data : response.videoFavorites) {
VideoResponse responseVideo = ZypeApi.getInstance().getVideo(data.videoId);
if (responseVideo != null) {
VideoData videoData = responseVideo.videoData;
if (TextUtils.isEmpty(videoData.description) || videoData.description.equals("null")) {
videoData.description = " ";
}
videoData.playlistId = favoritesPlaylistId;
videoData.playerUrl = "null";
videoData.videoFavoriteId = data.id;
result.videos.add(videoData);
} else {
Log.e(TAG, "loadFavoriteVideos(): error loading video, id=" + data.videoId);
}
}
} else {
Log.e(TAG, "loadFavoriteVideos(): failed");
return null;
}
// Load all favorites
loadNext = !(result.nextPage == -1);
}
return result;
}
use of com.zype.fire.api.Model.VideoResponse in project zype-firebuilder by zype.
the class ZypeDataDownloaderHelper method loadVideos.
public static VideosResult loadVideos(List<String> videoIds, String playlistId) {
Log.d(TAG, "loadVideos(): ");
VideosResult result = new VideosResult();
result.videos = new ArrayList<>();
result.nextPage = -1;
for (String videoId : videoIds) {
VideoResponse responseVideo = ZypeApi.getInstance().getVideo(videoId);
if (responseVideo != null) {
VideoData videoData = responseVideo.videoData;
if (TextUtils.isEmpty(videoData.description) || videoData.description.equals("null")) {
videoData.description = " ";
}
videoData.playlistId = playlistId;
videoData.playerUrl = "null";
videoData.videoFavoriteId = null;
result.videos.add(videoData);
} else {
Log.e(TAG, "loadFavoriteVideos(): error loading video, id=" + videoId);
return null;
}
}
return result;
}
use of com.zype.fire.api.Model.VideoResponse in project zype-firebuilder by zype.
the class ContentLoader method getMyLibraryVideosObservable.
public Observable<Pair> getMyLibraryVideosObservable(Object contentContainerAsObject) {
ContentContainer contentContainer = (ContentContainer) contentContainerAsObject;
ContentContainer rootMyLibrary = getRootContentContainer().findContentContainerByName(ZypeSettings.ROOT_MY_LIBRARY_PLAYLIST_ID);
int nextPage = rootMyLibrary.getExtraValueAsInt(ExtraKeys.NEXT_PAGE);
if (nextPage <= 0) {
Log.e(TAG, "getMyLibraryVideosObservable(): incorrect page: " + nextPage);
return Observable.just(Pair.create(contentContainerAsObject, ""));
}
String accessToken = Preferences.getString(ZypeAuthentication.ACCESS_TOKEN);
VideoEntitlementsResponse response = ZypeApi.getInstance().getVideoEntitlements(accessToken, nextPage, ZypeApi.PER_PAGE_DEFAULT);
if (response != null) {
if (response.pagination.current == response.pagination.pages) {
rootMyLibrary.setExtraValue(ExtraKeys.NEXT_PAGE, -1);
} else {
rootMyLibrary.setExtraValue(ExtraKeys.NEXT_PAGE, response.pagination.next);
}
Log.d(TAG, "getMyLibraryVideosObservable(): size=" + response.videoEntitlements.size());
List<VideoData> videos = new ArrayList<>();
for (VideoEntitlementData data : response.videoEntitlements) {
VideoResponse responseVideo = ZypeApi.getInstance().getVideo(data.videoId);
if (responseVideo != null) {
VideoData videoData = responseVideo.videoData;
if (TextUtils.isEmpty(videoData.description) || videoData.description.equals("null")) {
videoData.description = " ";
}
videoData.playlistId = contentContainer.getExtraStringValue(Recipe.KEY_DATA_TYPE_TAG);
videoData.playerUrl = "null";
videos.add(videoData);
} else {
Log.e(TAG, "getMyLibraryVideosObservable(): error loading video, id=" + data.videoId);
}
}
GsonBuilder builder = new GsonBuilder();
Gson gson = builder.create();
String feed = gson.toJson(videos);
return Observable.just(Pair.create(contentContainerAsObject, feed));
} else {
Log.e(TAG, "getMyLibraryVideosObservable(): no videos found");
return Observable.just(Pair.create(contentContainerAsObject, ""));
}
}
Aggregations