Skip to content

Commit

Permalink
Fixes #8 imgur galleries not working.
Browse files Browse the repository at this point in the history
  • Loading branch information
SpartanJ committed Aug 21, 2020
1 parent 2ae45b1 commit 7943c15
Show file tree
Hide file tree
Showing 7 changed files with 43 additions and 45 deletions.
8 changes: 4 additions & 4 deletions app/build.gradle
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
apply plugin: 'com.android.application'

def versionMajor = 2
def versionMinor = 1
def versionPatch = 9
def versionMinor = 2
def versionPatch = 0
// We need to use a static versionCode and versionName to support automatic updates in F-Droid
def versionCodeNum = versionMajor * 10000 + versionMinor * 1000 + versionPatch * 100

Expand All @@ -14,8 +14,8 @@ android {
applicationId "com.ensoft.imgurviewer"
minSdkVersion 14
targetSdkVersion 28
versionCode 21900
versionName "2.1.9"
versionCode 22000
versionName "2.2.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,14 @@ public void loadFailed( Uri uri, String error )
});

String[] testUris = new String[] {
"https://www.gfycat.com/giantunfoldedesok-rata",
"http://imgur.com/gallery/qZ7Oq2m",
"https://imgur.com/A61SaA1",
"https://i.imgur.com/crGpqCV.mp4",
"https://i.imgur.com/jxBXAMC.gifv",
"https://imgur.com/gallery/YcAQlkx",
"http://imgur.com/topic/Aww/ll5Vk",
"http://imgur.com/a/j6Orj",
"https://www.gfycat.com/temptingimpuregermanspaniel",
"https://www.pornhub.com/view_video.php?viewkey=ph5e13f804cbf69",
"https://www.gifdeliverynetwork.com/unconsciouslankyivorygull",
"https://gfycat.com/whoppingcostlyairedale",
Expand All @@ -120,13 +127,6 @@ public void loadFailed( Uri uri, String error )
"https://www.redgifs.com/watch/grimyacademicafricanbushviper-bz-beauty",
"https://www.redgifs.com/watch/calculatingsoreemperorpenguin-lauren-summer-swimsuit-bikini-beach",
"https://ibb.co/f2D3BNg",
"https://imgur.com/A61SaA1",
"https://i.imgur.com/crGpqCV.mp4",
"https://i.imgur.com/jxBXAMC.gifv",
"http://imgur.com/gallery/Q95ko",
"https://imgur.com/gallery/YcAQlkx",
"http://imgur.com/topic/Aww/ll5Vk",
"http://imgur.com/a/j6Orj",
"https://gyazo.com/1eae60fbb44ba44cdcd89064ffbaacef",
"https://imgflip.com/i/3dhvnl",
"http://gfycat.com/DeadlyDecisiveGermanpinscher",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ protected Map<String, String> getHeaders( Uri referer )
headers.put( "Accept-Charset", "ISO-8859-1,utf-8;q=0.7,*;q=0.7" );
headers.put( "Accept-Language", "en-us,en;q=0.5" );
headers.put( "Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8" );
headers.put( "User-Agent", "Mozilla/5.0 (X11; Linux x86_64; rv:76.0) Gecko/20100101 Firefox/76.0" );
headers.put( "User-Agent", "Mozilla/5.0 (X11; Linux x86_64; rv:76.0) Gecko/20100101 Firefox/79.0" );
return headers;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
package com.ensoft.imgurviewer.service.resource;

import android.content.Context;
import android.net.Uri;
import android.util.Log;

import com.android.volley.AuthFailureError;
import com.android.volley.Request;
import com.android.volley.toolbox.JsonObjectRequest;
import com.ensoft.imgurviewer.App;
import com.ensoft.imgurviewer.model.ImgurAlbum;
Expand All @@ -12,8 +14,11 @@
import com.ensoft.imgurviewer.service.listener.AlbumProvider;
import com.ensoft.imgurviewer.service.listener.AlbumSolverListener;
import com.ensoft.imgurviewer.service.listener.ImgurAlbumResolverListener;
import com.ensoft.restafari.network.helper.RequestParameters;
import com.ensoft.restafari.network.processor.ResponseListener;
import com.ensoft.restafari.network.service.RequestService;
import com.google.gson.Gson;
import com.google.gson.JsonObject;
import com.imgurviewer.R;

import org.json.JSONException;
Expand Down Expand Up @@ -87,9 +92,10 @@ public void getAlbum( Uri uri, final ImgurAlbumResolverListener imgurAlbumResolv
@Override
public Map<String, String> getHeaders() throws AuthFailureError
{
Map<String, String> params = new HashMap<>();
params.put( "Authorization", "Client-ID " + App.getInstance().getString( R.string.imgur_client_id ) );
return params;
Map<String, String> headers = new HashMap<>();
headers.put( "Authorization", "Client-ID " + App.getInstance().getString( R.string.imgur_client_id ) );
headers.put( "User-Agent", "Mozilla/5.0 (X11; Linux x86_64; rv:76.0) Gecko/20100101 Firefox/79.0" );
return headers;
}
};

Expand Down Expand Up @@ -176,15 +182,19 @@ public void onAlbumError( String error )
else
{
String albumUrl = IMGUR_GALLERY_API_URL + getGalleryId( uri );
Map<String, String> headers = new HashMap<>();
headers.put( "Authorization", "Client-ID " + App.getInstance().getString( R.string.imgur_client_id ) );
headers.put( "User-Agent", "Mozilla/5.0 (X11; Linux x86_64; rv:76.0) Gecko/20100101 Firefox/79.0" );

JsonObjectRequest jsonObjectRequest = new JsonObjectRequest( albumUrl, null, response ->
RequestService.getInstance().makeStringRequest( Request.Method.GET, albumUrl, new ResponseListener<String>()
{
try
@Override
public void onRequestSuccess( Context context, String response )
{
JSONObject data = response.getJSONObject( "data" );

try
{
JSONObject data = new JSONObject( response ).getJSONObject( "data" );

boolean isAlbum = data.getBoolean( "is_album" );

if ( isAlbum )
Expand All @@ -200,34 +210,20 @@ public void onAlbumError( String error )
albumSolverListener.onImageResolved( image );
}
}
catch ( JSONException e )
catch ( Exception e )
{
Log.e( TAG, e.getMessage() );
Log.v( TAG, e.getMessage() );

albumSolverListener.onAlbumError( e.toString() );
}
}
catch ( JSONException e )
{
Log.v( TAG, e.getMessage() );

albumSolverListener.onAlbumError( e.toString() );
}
}, error ->
{
Log.v( TAG, error.toString() );

albumSolverListener.onAlbumError( error.toString() );
} )
{
@Override
public Map<String, String> getHeaders() throws AuthFailureError
{
Map<String, String> params = new HashMap<>();
params.put( "Authorization", "Client-ID " + App.getInstance().getString( R.string.imgur_client_id ) );
return params;
public void onRequestError( Context context, int errorCode, String errorMessage ) {
Log.v( TAG, errorMessage );

albumSolverListener.onAlbumError( errorMessage );
}
};

RequestService.getInstance().addToRequestQueue( jsonObjectRequest );
}, new RequestParameters(), headers );
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public void onRequestSuccess( Context context, String response )
if ( null != dataStreamKey && null != csrfSession )
{
Map<String, String> headers = new HashMap<>();
headers.put( "User-Agent", "Mozilla/5.0 (X11; Linux x86_64; rv:69.0) Gecko/20100101 Firefox/69.0" );
headers.put( "User-Agent", "Mozilla/5.0 (X11; Linux x86_64; rv:69.0) Gecko/20100101 Firefox/79.0" );
headers.put( "Referer", uri.toString() );
headers.put( "Cookie", "sb_session=" + csrfSession + ";" );

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ protected Uri getVideoUrlFromResponse( String response )
@Override
public String[] getNeedleStart()
{
return new String[] { "window.initials = " };
return new String[] { "window.initials=" };
}

@Override
Expand Down
2 changes: 2 additions & 0 deletions fastlane/metadata/android/en-US/changelogs/22000.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
2.2.0:
Fixed imgur galleries and albums.

0 comments on commit 7943c15

Please sign in to comment.