This commit is contained in:
Thomas 2020-12-18 16:49:18 +01:00
parent 83e7c41ca0
commit d5a0dcb980
2 changed files with 74 additions and 24 deletions

View File

@ -184,27 +184,56 @@ public interface PeertubeService {
//Timelines Authenticated //Timelines Authenticated
//Subscriber timeline //Subscriber timeline
@GET("users/me/subscriptions/videos?sort=-publishedAt") @GET("users/me/subscriptions/videos?sort=-publishedAt")
Call<VideoData> getSubscriptionVideos(@Header("Authorization") String credentials, @Query("start") String maxId, @Query("count") String count, @Query("languageOneOf") List<String> languageOneOf); Call<VideoData> getSubscriptionVideos(
@Header("Authorization") String credentials,
@Query("start") String maxId,
@Query("count") String coun,
@Query("nsfw") boolean nsfwt,
@Query("languageOneOf") List<String> languageOneOf);
//Overview videos //Overview videos
@GET("overviews/videos") @GET("overviews/videos")
Call<OverviewVideo> getOverviewVideos(@Header("Authorization") String credentials, @Query("page") String page, @Query("languageOneOf") List<String> languageOneOf); Call<OverviewVideo> getOverviewVideos(
@Header("Authorization") String credentials,
@Query("page") String page,
@Query("nsfw") boolean nsfw,
@Query("languageOneOf") List<String> languageOneOf);
//Most liked videos //Most liked videos
@GET("videos?sort=-likes") @GET("videos?sort=-likes")
Call<VideoData> getMostLikedVideos(@Header("Authorization") String credentials, @Query("start") String maxId, @Query("count") String count, @Query("languageOneOf") List<String> languageOneOf); Call<VideoData> getMostLikedVideos(
@Header("Authorization") String credentials,
@Query("start") String maxId,
@Query("count") String count,
@Query("nsfw") boolean nsfw,
@Query("languageOneOf") List<String> languageOneOf);
//Trending videos //Trending videos
@GET("videos?sort=-trending") @GET("videos?sort=-trending")
Call<VideoData> getTrendingVideos(@Header("Authorization") String credentials, @Query("start") String maxId, @Query("count") String count, @Query("languageOneOf") List<String> languageOneOf); Call<VideoData> getTrendingVideos(
@Header("Authorization") String credentials,
@Query("start") String maxId,
@Query("count") String count,
@Query("nsfw") boolean nsfw,
@Query("languageOneOf") List<String> languageOneOf);
//Recently added videos //Recently added videos
@GET("videos?sort=-publishedAt") @GET("videos?sort=-publishedAt")
Call<VideoData> getRecentlyAddedVideos(@Header("Authorization") String credentials, @Query("start") String maxId, @Query("count") String count, @Query("languageOneOf") List<String> languageOneOf); Call<VideoData> getRecentlyAddedVideos(
@Header("Authorization") String credentials,
@Query("start") String maxId,
@Query("count") String count,
@Query("nsfw") boolean nsfw,
@Query("languageOneOf") List<String> languageOneOf);
//Local videos //Local videos
@GET("videos?sort=-publishedAt&filter=local") @GET("videos?sort=-publishedAt&filter=local")
Call<VideoData> getLocalVideos(@Header("Authorization") String credentials, @Query("start") String maxId, @Query("count") String count, @Query("languageOneOf") List<String> languageOneOf); Call<VideoData> getLocalVideos(
@Header("Authorization") String credentials,
@Query("start") String maxId,
@Query("count") String count,
@Query("nsfw") boolean nsfw,
@Query("languageOneOf") List<String> languageOneOf);
//History //History
@GET("users/me/history/videos") @GET("users/me/history/videos")
@ -212,6 +241,7 @@ public interface PeertubeService {
@Header("Authorization") String credentials, @Header("Authorization") String credentials,
@Query("start") String maxId, @Query("start") String maxId,
@Query("count") String count, @Query("count") String count,
@Query("nsfw") boolean nsfw,
@Query("startDate") String startDate, @Query("startDate") String startDate,
@Query("endDate") String endDate @Query("endDate") String endDate
); );
@ -226,7 +256,8 @@ public interface PeertubeService {
@Header("Authorization") String credentials, @Header("Authorization") String credentials,
@Query("search") String search, @Query("search") String search,
@Query("start") String maxId, @Query("start") String maxId,
@Query("count") String count); @Query("count") String count,
@Query("nsfw") boolean nsfw);
//Search channels //Search channels
@GET("search/video-channels") @GET("search/video-channels")
@ -243,7 +274,8 @@ public interface PeertubeService {
@Header("Authorization") String credentials, @Header("Authorization") String credentials,
@Query("tagsOneOf") List<String> tagsOneOf, @Query("tagsOneOf") List<String> tagsOneOf,
@Query("start") String maxId, @Query("start") String maxId,
@Query("count") String count); @Query("count") String count,
@Query("nsfw") boolean nsfw);
//Get notifications //Get notifications
@GET("users/me/notifications") @GET("users/me/notifications")
@ -269,9 +301,14 @@ public interface PeertubeService {
@GET("users/me/videos?sort=-publishedAt") @GET("users/me/videos?sort=-publishedAt")
Call<VideoData> getMyVideos(@Header("Authorization") String credentials, @Query("start") String maxId, @Query("count") String count); Call<VideoData> getMyVideos(@Header("Authorization") String credentials, @Query("start") String maxId, @Query("count") String count);
//Get my video //Get user videos
@GET("accounts/{name}/videos?sort=-publishedAt") @GET("accounts/{name}/videos?sort=-publishedAt")
Call<VideoData> getVideosForAccount(@Path("name") String name, @Query("start") String maxId, @Query("count") String count); Call<VideoData> getVideosForAccount(
@Path("name") String name,
@Query("start") String maxId,
@Query("count") String count,
@Query("nsfw") boolean nsfw
);
@Multipart @Multipart
@PUT("videos/{id}") @PUT("videos/{id}")
@ -318,7 +355,11 @@ public interface PeertubeService {
Call<ChannelData> getAllChannels(); Call<ChannelData> getAllChannels();
@GET("video-channels/{channelHandle}/videos") @GET("video-channels/{channelHandle}/videos")
Call<VideoData> getChannelVideos(@Path("channelHandle") String channelHandle, @Query("start") String maxId, @Query("count") String count); Call<VideoData> getChannelVideos(
@Path("channelHandle") String channelHandle,
@Query("start") String maxId,
@Query("count") String count,
@Query("nsfw") boolean nsfw);
@POST("video-channels") @POST("video-channels")
Call<ChannelData.ChannelCreation> addChannel(@Header("Authorization") String credentials, @Body ChannelParams channelParams); Call<ChannelData.ChannelCreation> addChannel(@Header("Authorization") String credentials, @Body ChannelParams channelParams);

View File

@ -100,6 +100,7 @@ public class RetrofitPeertubeAPI {
private final String count; private final String count;
private String token; private String token;
private Set<String> selection; private Set<String> selection;
private boolean showNSFWVideos = true;
public RetrofitPeertubeAPI(Context context) { public RetrofitPeertubeAPI(Context context) {
_context = context; _context = context;
@ -107,6 +108,10 @@ public class RetrofitPeertubeAPI {
finalUrl = "https://" + HelperInstance.getLiveInstance(context) + "/api/v1/"; finalUrl = "https://" + HelperInstance.getLiveInstance(context) + "/api/v1/";
SharedPreferences sharedpreferences = _context.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE); SharedPreferences sharedpreferences = _context.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
count = String.valueOf(sharedpreferences.getInt(Helper.SET_VIDEOS_PER_PAGE, Helper.VIDEOS_PER_PAGE)); count = String.valueOf(sharedpreferences.getInt(Helper.SET_VIDEOS_PER_PAGE, Helper.VIDEOS_PER_PAGE));
String currentSensitive = sharedpreferences.getString(_context.getString(R.string.set_video_sensitive_choice), Helper.BLUR);
if (currentSensitive.compareTo(Helper.DO_NOT_LIST) == 0) {
showNSFWVideos = false;
}
} }
public RetrofitPeertubeAPI(Context context, String instance, String token) { public RetrofitPeertubeAPI(Context context, String instance, String token) {
@ -116,6 +121,10 @@ public class RetrofitPeertubeAPI {
finalUrl = "https://" + instance + "/api/v1/"; finalUrl = "https://" + instance + "/api/v1/";
SharedPreferences sharedpreferences = _context.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE); SharedPreferences sharedpreferences = _context.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
count = String.valueOf(sharedpreferences.getInt(Helper.SET_VIDEOS_PER_PAGE, Helper.VIDEOS_PER_PAGE)); count = String.valueOf(sharedpreferences.getInt(Helper.SET_VIDEOS_PER_PAGE, Helper.VIDEOS_PER_PAGE));
String currentSensitive = sharedpreferences.getString(_context.getString(R.string.set_video_sensitive_choice), Helper.BLUR);
if (currentSensitive.compareTo(Helper.DO_NOT_LIST) == 0) {
showNSFWVideos = false;
}
} }
@ -336,7 +345,7 @@ public class RetrofitPeertubeAPI {
public APIResponse getVideosForChannel(String channelId, String max_id) { public APIResponse getVideosForChannel(String channelId, String max_id) {
APIResponse apiResponse = new APIResponse(); APIResponse apiResponse = new APIResponse();
PeertubeService peertubeService = init(); PeertubeService peertubeService = init();
Call<VideoData> videoCall = peertubeService.getChannelVideos(channelId, max_id, count); Call<VideoData> videoCall = peertubeService.getChannelVideos(channelId, max_id, count, showNSFWVideos);
if (videoCall != null) { if (videoCall != null) {
try { try {
Response<VideoData> response = videoCall.execute(); Response<VideoData> response = videoCall.execute();
@ -381,7 +390,7 @@ public class RetrofitPeertubeAPI {
public APIResponse getHistory(String max_id, String startDate, String endDate) { public APIResponse getHistory(String max_id, String startDate, String endDate) {
APIResponse apiResponse = new APIResponse(); APIResponse apiResponse = new APIResponse();
PeertubeService peertubeService = init(); PeertubeService peertubeService = init();
Call<VideoData> videoCall = peertubeService.getHistory(getToken(), max_id, count, startDate, endDate); Call<VideoData> videoCall = peertubeService.getHistory(getToken(), max_id, count, showNSFWVideos, startDate, endDate);
if (videoCall != null) { if (videoCall != null) {
try { try {
Response<VideoData> response = videoCall.execute(); Response<VideoData> response = videoCall.execute();
@ -410,29 +419,29 @@ public class RetrofitPeertubeAPI {
videoCall = peertubeService.getMyVideos(getToken(), max_id, count); videoCall = peertubeService.getMyVideos(getToken(), max_id, count);
break; break;
case ACCOUNT_VIDEOS: case ACCOUNT_VIDEOS:
videoCall = peertubeService.getVideosForAccount(forAccount, max_id, count); videoCall = peertubeService.getVideosForAccount(forAccount, max_id, count, showNSFWVideos);
break; break;
case SUBSCRIBTIONS: case SUBSCRIBTIONS:
if (forAccount == null) { if (forAccount == null) {
videoCall = peertubeService.getSubscriptionVideos(getToken(), max_id, count, filter); videoCall = peertubeService.getSubscriptionVideos(getToken(), max_id, count, showNSFWVideos, filter);
} else { } else {
videoCall = peertubeService.getChannelVideos(forAccount, max_id, count); videoCall = peertubeService.getChannelVideos(forAccount, max_id, count, showNSFWVideos);
} }
break; break;
case MOST_LIKED: case MOST_LIKED:
videoCall = peertubeService.getMostLikedVideos(getToken(), max_id, count, filter); videoCall = peertubeService.getMostLikedVideos(getToken(), max_id, count, showNSFWVideos, filter);
break; break;
case LOCAL: case LOCAL:
videoCall = peertubeService.getLocalVideos(getToken(), max_id, count, filter); videoCall = peertubeService.getLocalVideos(getToken(), max_id, count, showNSFWVideos, filter);
break; break;
case TRENDING: case TRENDING:
videoCall = peertubeService.getTrendingVideos(getToken(), max_id, count, filter); videoCall = peertubeService.getTrendingVideos(getToken(), max_id, count, showNSFWVideos, filter);
break; break;
case HISTORY: case HISTORY:
videoCall = peertubeService.getHistory(getToken(), max_id, count, null, null); videoCall = peertubeService.getHistory(getToken(), max_id, count, showNSFWVideos, null, null);
break; break;
case RECENT: case RECENT:
videoCall = peertubeService.getRecentlyAddedVideos(getToken(), max_id, count, filter); videoCall = peertubeService.getRecentlyAddedVideos(getToken(), max_id, count, showNSFWVideos, filter);
break; break;
} }
if (videoCall != null) { if (videoCall != null) {
@ -463,7 +472,7 @@ public class RetrofitPeertubeAPI {
APIResponse apiResponse = new APIResponse(); APIResponse apiResponse = new APIResponse();
PeertubeService peertubeService = init(); PeertubeService peertubeService = init();
ArrayList<String> filter = selection != null ? new ArrayList<>(selection) : null; ArrayList<String> filter = selection != null ? new ArrayList<>(selection) : null;
Call<OverviewVideo> overviewVideoCall = peertubeService.getOverviewVideos(getToken(), page, filter); Call<OverviewVideo> overviewVideoCall = peertubeService.getOverviewVideos(getToken(), page, showNSFWVideos, filter);
try { try {
Response<OverviewVideo> response = overviewVideoCall.execute(); Response<OverviewVideo> response = overviewVideoCall.execute();
if (response.isSuccessful() && response.body() != null) { if (response.isSuccessful() && response.body() != null) {
@ -903,7 +912,7 @@ public class RetrofitPeertubeAPI {
*/ */
public APIResponse searchNextVideos(List<String> tags) { public APIResponse searchNextVideos(List<String> tags) {
PeertubeService peertubeService = init(); PeertubeService peertubeService = init();
Call<VideoData> searchVideosCall = peertubeService.searchNextVideo(getToken(), tags, "0", "20"); Call<VideoData> searchVideosCall = peertubeService.searchNextVideo(getToken(), tags, "0", "20", showNSFWVideos);
APIResponse apiResponse = new APIResponse(); APIResponse apiResponse = new APIResponse();
try { try {
Response<VideoData> response = searchVideosCall.execute(); Response<VideoData> response = searchVideosCall.execute();
@ -929,7 +938,7 @@ public class RetrofitPeertubeAPI {
*/ */
public APIResponse searchPeertube(String query, String max_id) { public APIResponse searchPeertube(String query, String max_id) {
PeertubeService peertubeService = init(); PeertubeService peertubeService = init();
Call<VideoData> searchVideosCall = peertubeService.searchVideos(getToken(), query, max_id, count); Call<VideoData> searchVideosCall = peertubeService.searchVideos(getToken(), query, max_id, count, showNSFWVideos);
APIResponse apiResponse = new APIResponse(); APIResponse apiResponse = new APIResponse();
try { try {
Response<VideoData> response = searchVideosCall.execute(); Response<VideoData> response = searchVideosCall.execute();