diff --git a/app/src/androidTest/java/com/ensoft/imgurviewer/service/ResourceSolverTest.java b/app/src/androidTest/java/com/ensoft/imgurviewer/service/ResourceSolverTest.java index 63ba3e1..b71cadb 100644 --- a/app/src/androidTest/java/com/ensoft/imgurviewer/service/ResourceSolverTest.java +++ b/app/src/androidTest/java/com/ensoft/imgurviewer/service/ResourceSolverTest.java @@ -111,9 +111,6 @@ public void loadFailed( Uri uri, String error ) }); String[] testUris = new String[] { - // deprecate? - "https://www.pornhub.com/view_video.php?viewkey=ph5effde87227d2", - // approved "https://www.reddit.com/gallery/huxc4s", "https://redgifs.com/watch/calculatingsoreemperorpenguin-lauren-summer-swimsuit-bikini-beach", "https://redgifs.com/watch/grimyacademicafricanbushviper-bz-beauty", @@ -169,6 +166,7 @@ public void loadFailed( Uri uri, String error ) "https://la.spankbang.com/22xtb/video/", "http://www.xvideos.com/video4588838/biker_takes_his_girl", "https://xhamster.com/videos/asmr-you-know-i-like-you-xhnBhXU", + "https://www.pornhub.com/view_video.php?viewkey=ph5effde87227d2", }; for ( String testUri :testUris ) diff --git a/app/src/main/java/com/ensoft/imgurviewer/service/resource/BasicVideoServiceSolver.java b/app/src/main/java/com/ensoft/imgurviewer/service/resource/BasicVideoServiceSolver.java index 60c2457..e9498cb 100644 --- a/app/src/main/java/com/ensoft/imgurviewer/service/resource/BasicVideoServiceSolver.java +++ b/app/src/main/java/com/ensoft/imgurviewer/service/resource/BasicVideoServiceSolver.java @@ -54,7 +54,7 @@ protected JSONObject getParameters() return new JSONObject(); } - protected Map getHeaders( Uri referer ) + protected HashMap getHeaders( Uri referer ) { HashMap headers = new HashMap<>(); headers.put( "Origin", referer.getScheme() + "://" + referer.getHost() ); diff --git a/app/src/main/java/com/ensoft/imgurviewer/service/resource/PornHubService.java b/app/src/main/java/com/ensoft/imgurviewer/service/resource/PornHubService.java index 6734640..64e2956 100644 --- a/app/src/main/java/com/ensoft/imgurviewer/service/resource/PornHubService.java +++ b/app/src/main/java/com/ensoft/imgurviewer/service/resource/PornHubService.java @@ -1,7 +1,20 @@ package com.ensoft.imgurviewer.service.resource; +import android.content.Context; import android.net.Uri; import android.text.TextUtils; +import android.util.Log; + +import com.android.volley.Request; +import com.ensoft.imgurviewer.model.YouPornVideo; +import com.ensoft.imgurviewer.service.UriUtils; +import com.ensoft.imgurviewer.service.listener.PathResolverListener; +import com.ensoft.restafari.helper.ThreadMode; +import com.ensoft.restafari.network.helper.RequestParameters; +import com.ensoft.restafari.network.processor.ResponseListener; +import com.ensoft.restafari.network.rest.response.Header; +import com.ensoft.restafari.network.service.RequestService; +import com.imgurviewer.R; import java.util.ArrayList; import java.util.Arrays; @@ -28,10 +41,10 @@ public String[] getDomainPath() } @Override - protected Map getHeaders( Uri referer ) + protected HashMap getHeaders( Uri referer ) { - Map headers = super.getHeaders( referer ); - headers.put( "Cookie", "platform=tv;" ); + HashMap headers = super.getHeaders( referer ); + headers.put( "Cookie", "platform=pc;" ); return headers; } @@ -156,42 +169,84 @@ protected Uri getVideoUrlFromResponse( String response ) if ( !vars.isEmpty() ) { - int bestQuality = 0; - String bestQualityUrl = ""; for ( Map.Entry entry : vars.entrySet() ) { - if ( entry.getKey().startsWith( "quality_" ) && !entry.getValue().isEmpty() ) + if ( "media_1".equalsIgnoreCase( entry.getKey() ) ) { - int q = Integer.parseInt( entry.getKey().substring( 8 ).replace( "p", "" ) ); - - if ( q > bestQuality ) - { - bestQuality = q; - bestQualityUrl = entry.getValue(); - } + return Uri.parse( entry.getValue() ); } } - - try + } + + return null; + } + + @Override + protected ResponseListener getResponseListener( Uri uri, PathResolverListener pathResolverListener ) + { + return new ResponseListener() + { + @Override + public ThreadMode getThreadMode() { - return Uri.parse( bestQualityUrl ); + return ThreadMode.ASYNC; } - catch ( Exception ignored ) + + @Override + public void onRequestSuccess( Context context, String response ) { - return null; + Uri videoUrl = getVideoUrlFromResponse( response ); + + HashMap headers = getHeaders( uri ); + + String cookie = "platform=pc;"; + + for ( Header header : this.networkResponse.allHeaders ) + { + if ( "set-cookie".equalsIgnoreCase( header.getName() ) ) + { + String[] values = header.getValue().split( ";" ); + + if ( values.length > 0 ) + { + cookie += values[0].trim() + ";"; + } + } + } + + headers.put( "Cookie", cookie ); + + if ( videoUrl != null ) + { + RequestService.getInstance().makeJsonArrayRequest( Request.Method.GET, videoUrl.toString(), new ResponseListener() + { + @Override + public void onRequestSuccess( Context context, YouPornVideo[] response ) + { + sendPathResolved( pathResolverListener, response[0].getVideoUri(), UriUtils.guessMediaTypeFromUri( response[0].getVideoUri() ), uri ); + } + + @Override + public void onRequestError( Context context, int errorCode, String errorMessage ) + { + sendPathError( uri, pathResolverListener, R.string.could_not_resolve_video_url ); + } + }, new RequestParameters(), headers ); + } + else + { + sendPathError( uri, pathResolverListener, R.string.could_not_resolve_video_url ); + } } - } - else - { - List mediaVars = getJsVars(getStringMatch( response, "var mediastring=", ";" )); - StringBuilder url = new StringBuilder(); - for ( String var : mediaVars ) + @Override + public void onRequestError( Context context, int errorCode, String errorMessage ) { - url.append( getJsVarValue( response, var ) ); + if ( null != getDomain() && null != errorMessage ) + Log.v( getDomain(), errorMessage ); + + sendPathError( uri, pathResolverListener, null != errorMessage ? errorMessage : "" ); } - - return !url.toString().isEmpty() ? Uri.parse( url.toString() ) : null; - } + }; } }