From f70721d7fd5c5c63b710f006c9984ce2b84a42b3 Mon Sep 17 00:00:00 2001 From: Docile-Alligator <25734209+Docile-Alligator@users.noreply.github.com> Date: Fri, 16 Sep 2022 23:56:46 +1000 Subject: Fix redgifs download issues. --- .../infinityforreddit/AppModule.java | 2 +- .../FetchGfycatOrRedgifsVideoLinks.java | 2 +- .../activities/ViewVideoActivity.java | 26 ++++++++++------------ .../adapters/HistoryPostRecyclerViewAdapter.java | 6 ++--- .../adapters/PostDetailRecyclerViewAdapter.java | 2 +- .../adapters/PostRecyclerViewAdapter.java | 6 ++--- .../fragments/ViewImgurVideoFragment.java | 2 +- .../fragments/ViewRPANBroadcastFragment.java | 2 +- .../fragments/ViewRedditGalleryVideoFragment.java | 2 +- .../services/DownloadMediaService.java | 11 ++++++++- .../infinityforreddit/utils/APIUtils.java | 20 ----------------- .../videoautoplay/DefaultExoCreator.java | 2 +- 12 files changed, 33 insertions(+), 50 deletions(-) (limited to 'app/src/main/java/ml') diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/AppModule.java b/app/src/main/java/ml/docilealligator/infinityforreddit/AppModule.java index 3f5f51fd..1b709651 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/AppModule.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/AppModule.java @@ -125,7 +125,7 @@ class AppModule { .addInterceptor(chain -> chain.proceed( chain.request() .newBuilder() - .header("User-Agent", APIUtils.getRedgifsUserAgent(mApplication)) + .header("User-Agent", APIUtils.USER_AGENT) .build() )) .addInterceptor(new RedgifsAccessTokenAuthenticator(currentAccountSharedPreferences)) diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/FetchGfycatOrRedgifsVideoLinks.java b/app/src/main/java/ml/docilealligator/infinityforreddit/FetchGfycatOrRedgifsVideoLinks.java index d1bfd941..1f55fb7f 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/FetchGfycatOrRedgifsVideoLinks.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/FetchGfycatOrRedgifsVideoLinks.java @@ -51,7 +51,7 @@ public class FetchGfycatOrRedgifsVideoLinks { executor.execute(() -> { try { Response response = redgifsRetrofit.create(RedgifsAPI.class).getRedgifsData(APIUtils.getRedgifsOAuthHeader(currentAccountSharedPreferences.getString(SharedPreferencesUtils.REDGIFS_ACCESS_TOKEN, "")), - gfycatId, APIUtils.getRedgifsUserAgent(context)).execute(); + gfycatId, APIUtils.USER_AGENT).execute(); if (response.isSuccessful()) { parseRedgifsVideoLinks(handler, response.body(), fetchGfycatOrRedgifsVideoLinksListener); } else { diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewVideoActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewVideoActivity.java index 39398315..865d8fc5 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewVideoActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewVideoActivity.java @@ -6,7 +6,6 @@ import static androidx.appcompat.app.AppCompatDelegate.MODE_NIGHT_NO; import static androidx.appcompat.app.AppCompatDelegate.MODE_NIGHT_YES; import android.Manifest; -import android.app.AlertDialog; import android.app.Dialog; import android.content.Intent; import android.content.SharedPreferences; @@ -25,7 +24,6 @@ import android.os.Bundle; import android.os.Handler; import android.provider.Settings; import android.text.Html; -import android.util.Log; import android.view.Menu; import android.view.MenuItem; import android.view.OrientationEventListener; @@ -40,6 +38,7 @@ import android.widget.Toast; import androidx.annotation.NonNull; import androidx.appcompat.app.ActionBar; +import androidx.appcompat.app.AlertDialog; import androidx.appcompat.app.AppCompatActivity; import androidx.appcompat.app.AppCompatDelegate; import androidx.coordinatorlayout.widget.CoordinatorLayout; @@ -505,7 +504,7 @@ public class ViewVideoActivity extends AppCompatActivity implements CustomFontRe loadStreamableVideo(shortCode, savedInstanceState); } else { dataSourceFactory = new CacheDataSource.Factory().setCache(mSimpleCache) - .setUpstreamDataSourceFactory(new DefaultHttpDataSource.Factory().setUserAgent(APIUtils.getRedgifsUserAgent(ViewVideoActivity.this))); + .setUpstreamDataSourceFactory(new DefaultHttpDataSource.Factory().setUserAgent(APIUtils.USER_AGENT)); player.prepare(); player.setMediaSource(new ProgressiveMediaSource.Factory(dataSourceFactory).createMediaSource(MediaItem.fromUri(mVideoUri))); preparePlayer(savedInstanceState); @@ -537,7 +536,7 @@ public class ViewVideoActivity extends AppCompatActivity implements CustomFontRe } } else { dataSourceFactory = new CacheDataSource.Factory().setCache(mSimpleCache) - .setUpstreamDataSourceFactory(new DefaultHttpDataSource.Factory().setUserAgent(APIUtils.getRedgifsUserAgent(ViewVideoActivity.this))); + .setUpstreamDataSourceFactory(new DefaultHttpDataSource.Factory().setUserAgent(APIUtils.USER_AGENT)); player.prepare(); player.setMediaSource(new ProgressiveMediaSource.Factory(dataSourceFactory).createMediaSource(MediaItem.fromUri(mVideoUri))); preparePlayer(savedInstanceState); @@ -551,7 +550,7 @@ public class ViewVideoActivity extends AppCompatActivity implements CustomFontRe } // Produces DataSource instances through which media data is loaded. dataSourceFactory = new CacheDataSource.Factory().setCache(mSimpleCache) - .setUpstreamDataSourceFactory(new DefaultHttpDataSource.Factory().setUserAgent(APIUtils.getRedgifsUserAgent(ViewVideoActivity.this))); + .setUpstreamDataSourceFactory(new DefaultHttpDataSource.Factory().setUserAgent(APIUtils.USER_AGENT)); // Prepare the player with the source. player.prepare(); player.setMediaSource(new ProgressiveMediaSource.Factory(dataSourceFactory).createMediaSource(MediaItem.fromUri(mVideoUri))); @@ -563,7 +562,7 @@ public class ViewVideoActivity extends AppCompatActivity implements CustomFontRe videoFileName = subredditName + "-" + id + ".mp4"; // Produces DataSource instances through which media data is loaded. dataSourceFactory = new CacheDataSource.Factory().setCache(mSimpleCache) - .setUpstreamDataSourceFactory(new DefaultHttpDataSource.Factory().setUserAgent(APIUtils.getRedgifsUserAgent(ViewVideoActivity.this))); + .setUpstreamDataSourceFactory(new DefaultHttpDataSource.Factory().setUserAgent(APIUtils.USER_AGENT)); // Prepare the player with the source. player.prepare(); player.setMediaSource(new HlsMediaSource.Factory(dataSourceFactory).createMediaSource(MediaItem.fromUri(mVideoUri))); @@ -625,13 +624,12 @@ public class ViewVideoActivity extends AppCompatActivity implements CustomFontRe if (videoType == VIDEO_TYPE_NORMAL) { hdButton.setVisibility(View.VISIBLE); hdButton.setOnClickListener(view -> { - TrackSelectionDialogBuilder builder = new TrackSelectionDialogBuilder(ViewVideoActivity.this, getString(R.string.select_video_quality), player, 0); + TrackSelectionDialogBuilder builder = new TrackSelectionDialogBuilder(ViewVideoActivity.this, getString(R.string.select_video_quality), player, C.TRACK_TYPE_VIDEO); builder.setShowDisableOption(true); builder.setAllowAdaptiveSelections(false); - Dialog dialog = builder.build(); + Dialog dialog = builder.setTheme(R.style.MaterialAlertDialogTheme).build(); dialog.show(); if (dialog instanceof AlertDialog) { - Log.i("asfadsf", "asdfasdf"); ((AlertDialog) dialog).getButton(AlertDialog.BUTTON_POSITIVE).setTextColor(mCustomThemeWrapper.getPrimaryTextColor()); ((AlertDialog) dialog).getButton(AlertDialog.BUTTON_NEGATIVE).setTextColor(mCustomThemeWrapper.getPrimaryTextColor()); } @@ -695,7 +693,7 @@ public class ViewVideoActivity extends AppCompatActivity implements CustomFontRe mVideoUri = Uri.parse(webm); videoDownloadUrl = mp4; dataSourceFactory = new CacheDataSource.Factory().setCache(mSimpleCache) - .setUpstreamDataSourceFactory(new DefaultHttpDataSource.Factory().setUserAgent(APIUtils.getRedgifsUserAgent(ViewVideoActivity.this))); + .setUpstreamDataSourceFactory(new DefaultHttpDataSource.Factory().setUserAgent(APIUtils.USER_AGENT)); preparePlayer(savedInstanceState); player.prepare(); player.setMediaSource(new ProgressiveMediaSource.Factory(dataSourceFactory).createMediaSource(MediaItem.fromUri(mVideoUri))); @@ -725,7 +723,7 @@ public class ViewVideoActivity extends AppCompatActivity implements CustomFontRe mVideoUri = Uri.parse(webm); videoDownloadUrl = mp4; dataSourceFactory = new CacheDataSource.Factory().setCache(mSimpleCache) - .setUpstreamDataSourceFactory(new DefaultHttpDataSource.Factory().setUserAgent(APIUtils.getRedgifsUserAgent(ViewVideoActivity.this))); + .setUpstreamDataSourceFactory(new DefaultHttpDataSource.Factory().setUserAgent(APIUtils.USER_AGENT)); preparePlayer(savedInstanceState); player.prepare(); player.setMediaSource(new ProgressiveMediaSource.Factory(dataSourceFactory).createMediaSource(MediaItem.fromUri(mVideoUri))); @@ -791,7 +789,7 @@ public class ViewVideoActivity extends AppCompatActivity implements CustomFontRe videoFileName = "imgur-" + FilenameUtils.getName(videoDownloadUrl); // Produces DataSource instances through which media data is loaded. dataSourceFactory = new CacheDataSource.Factory().setCache(mSimpleCache) - .setUpstreamDataSourceFactory(new DefaultHttpDataSource.Factory().setUserAgent(APIUtils.getRedgifsUserAgent(ViewVideoActivity.this))); + .setUpstreamDataSourceFactory(new DefaultHttpDataSource.Factory().setUserAgent(APIUtils.USER_AGENT)); // Prepare the player with the source. player.prepare(); player.setMediaSource(new ProgressiveMediaSource.Factory(dataSourceFactory).createMediaSource(MediaItem.fromUri(mVideoUri))); @@ -807,7 +805,7 @@ public class ViewVideoActivity extends AppCompatActivity implements CustomFontRe videoFileName = subredditName + "-" + id + ".mp4"; // Produces DataSource instances through which media data is loaded. dataSourceFactory = new CacheDataSource.Factory().setCache(mSimpleCache) - .setUpstreamDataSourceFactory(new DefaultHttpDataSource.Factory().setUserAgent(APIUtils.getRedgifsUserAgent(ViewVideoActivity.this))); + .setUpstreamDataSourceFactory(new DefaultHttpDataSource.Factory().setUserAgent(APIUtils.USER_AGENT)); // Prepare the player with the source. preparePlayer(savedInstanceState); player.prepare(); @@ -850,7 +848,7 @@ public class ViewVideoActivity extends AppCompatActivity implements CustomFontRe videoDownloadUrl = streamableVideo.mp4 == null ? streamableVideo.mp4Mobile.url : streamableVideo.mp4.url; mVideoUri = Uri.parse(videoDownloadUrl); dataSourceFactory = new CacheDataSource.Factory().setCache(mSimpleCache) - .setUpstreamDataSourceFactory(new DefaultHttpDataSource.Factory().setUserAgent(APIUtils.getRedgifsUserAgent(ViewVideoActivity.this))); + .setUpstreamDataSourceFactory(new DefaultHttpDataSource.Factory().setUserAgent(APIUtils.USER_AGENT)); preparePlayer(savedInstanceState); player.prepare(); player.setMediaSource(new ProgressiveMediaSource.Factory(dataSourceFactory).createMediaSource(MediaItem.fromUri(mVideoUri))); diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/HistoryPostRecyclerViewAdapter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/HistoryPostRecyclerViewAdapter.java index 62c3e0d1..b14d094c 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/HistoryPostRecyclerViewAdapter.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/HistoryPostRecyclerViewAdapter.java @@ -43,8 +43,6 @@ import com.bumptech.glide.request.RequestListener; import com.bumptech.glide.request.RequestOptions; import com.bumptech.glide.request.target.Target; import com.google.android.exoplayer2.Tracks; -import com.google.android.exoplayer2.source.TrackGroupArray; -import com.google.android.exoplayer2.trackselection.TrackSelectionArray; import com.google.android.exoplayer2.ui.AspectRatioFrameLayout; import com.google.android.exoplayer2.ui.PlayerView; import com.google.common.collect.ImmutableList; @@ -681,7 +679,7 @@ public class HistoryPostRecyclerViewAdapter extends PagingDataAdapter chain.proceed( + chain.request() + .newBuilder() + .header("User-Agent", APIUtils.USER_AGENT) + .build() + )) .build(); retrofit = retrofit.newBuilder().client(client).build(); @@ -140,7 +148,8 @@ public class DownloadMediaService extends Service { String destinationFileUriString = null; boolean isDefaultDestination = true; try { - response = retrofit.create(DownloadFile.class).downloadFile(fileUrl).execute(); + Call call = retrofit.create(DownloadFile.class).downloadFile(fileUrl); + response = call.execute(); if (response.isSuccessful() && response.body() != null) { String destinationFileDirectory = getDownloadLocation(mediaType, isNsfw); if (destinationFileDirectory.equals("")) { diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/utils/APIUtils.java b/app/src/main/java/ml/docilealligator/infinityforreddit/utils/APIUtils.java index 248c917b..3486b463 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/utils/APIUtils.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/utils/APIUtils.java @@ -1,6 +1,5 @@ package ml.docilealligator.infinityforreddit.utils; -import android.content.Context; import android.util.Base64; import java.util.HashMap; @@ -153,23 +152,4 @@ public class APIUtils { params.put(APIUtils.USER_AGENT_KEY, APIUtils.USER_AGENT); return params; } - - public static String getRedgifsUserAgent(Context context) { - return APIUtils.USER_AGENT; - /*String versionName; - try { - String packageName = context.getPackageName(); - PackageInfo info = context.getPackageManager().getPackageInfo(packageName, 0); - versionName = info.versionName; - } catch (Exception e) { - versionName = "?"; - } - return "Toro ExoPlayer Extension, v3.7.0.2010003" - + "/" - + versionName - + " (Linux;Android " - + Build.VERSION.RELEASE - + ") " - + ExoPlayerLibraryInfo.VERSION_SLASHY;*/ - } } diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/videoautoplay/DefaultExoCreator.java b/app/src/main/java/ml/docilealligator/infinityforreddit/videoautoplay/DefaultExoCreator.java index 4c82c34b..dc1375b9 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/videoautoplay/DefaultExoCreator.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/videoautoplay/DefaultExoCreator.java @@ -79,7 +79,7 @@ public class DefaultExoCreator implements ExoCreator, MediaSourceEventListener { DataSource.Factory baseFactory = config.dataSourceFactory; if (baseFactory == null) { - baseFactory = new DefaultHttpDataSource.Factory().setUserAgent(APIUtils.getRedgifsUserAgent(getContext())); + baseFactory = new DefaultHttpDataSource.Factory().setUserAgent(APIUtils.USER_AGENT); } DataSource.Factory factory = new DefaultDataSource.Factory(this.toro.context, baseFactory); if (config.cache != null) -- cgit v1.2.3