Skip to content

Commit

Permalink
Fixed PornHub service.
Browse files Browse the repository at this point in the history
  • Loading branch information
SpartanJ committed Sep 26, 2021
1 parent ca02720 commit 4638bca
Show file tree
Hide file tree
Showing 3 changed files with 85 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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 )
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ protected JSONObject getParameters()
return new JSONObject();
}

protected Map<String, String> getHeaders( Uri referer )
protected HashMap<String, String> getHeaders( Uri referer )
{
HashMap<String,String> headers = new HashMap<>();
headers.put( "Origin", referer.getScheme() + "://" + referer.getHost() );
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -28,10 +41,10 @@ public String[] getDomainPath()
}

@Override
protected Map<String, String> getHeaders( Uri referer )
protected HashMap<String, String> getHeaders( Uri referer )
{
Map<String, String> headers = super.getHeaders( referer );
headers.put( "Cookie", "platform=tv;" );
HashMap<String, String> headers = super.getHeaders( referer );
headers.put( "Cookie", "platform=pc;" );
return headers;
}

Expand Down Expand Up @@ -156,42 +169,84 @@ protected Uri getVideoUrlFromResponse( String response )

if ( !vars.isEmpty() )
{
int bestQuality = 0;
String bestQualityUrl = "";
for ( Map.Entry<String, String> 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<String> getResponseListener( Uri uri, PathResolverListener pathResolverListener )
{
return new ResponseListener<String>()
{
@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<String, String> 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<YouPornVideo[]>()
{
@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<String> mediaVars = getJsVars(getStringMatch( response, "var mediastring=", ";</script>" ));
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;
}
};
}
}

0 comments on commit 4638bca

Please sign in to comment.