Skip to content

Commit

Permalink
changed scrapper as per changes in instagram. Fuckin stop changing in…
Browse files Browse the repository at this point in the history
…stagramgit add .
  • Loading branch information
Lcukerd authored and Lcukerd committed Feb 1, 2018
1 parent 36ca76e commit de6d757
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 45 deletions.
2 changes: 2 additions & 0 deletions .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ apply plugin: 'com.android.application'

android {
compileSdkVersion 25
buildToolsVersion "25.0.0"
buildToolsVersion '26.0.2'
defaultConfig {
applicationId "lcukerd.com.instaswipe"
minSdkVersion 18
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ public void onLoadingComplete(String imageUri, View view, Bitmap loadedImage)
public void onClick(View v)
{
ArrayList<String> temp = new ArrayList<>();
temp.add(profilepicURL);
temp.add(Scrapper.getProfilePicHDUrl(sourceCode));
Intent intent = new Intent(ProfileActivity.this, SwipePic.class);
intent.putStringArrayListExtra("urls", temp);
intent.putExtra("id", "-1");
Expand Down
67 changes: 27 additions & 40 deletions app/src/main/java/lcukerd/com/instaswipe/Utils/Scrapper.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,15 @@
* Created by Programmer on 15-09-2017.
*/

public class Scrapper
{
public class Scrapper {
private static final String tag = Scrapper.class.getSimpleName();

public static ArrayList<User> getUsersfromsearch(String result)
{
public static ArrayList<User> getUsersfromsearch(String result) {
ArrayList<User> userArrayList = new ArrayList<>();
try
{
try {
JSONObject jsonObject = new JSONObject(result);
JSONArray jsonArray = jsonObject.getJSONArray("users");
for (int i = 0; i < jsonArray.length(); i++)
{
for (int i = 0; i < jsonArray.length(); i++) {
User u = new User();
jsonObject = jsonArray.getJSONObject(i);
jsonObject = jsonObject.getJSONObject("user");
Expand All @@ -41,32 +37,34 @@ public static ArrayList<User> getUsersfromsearch(String result)
u.isprivate = "";
userArrayList.add(u);
}
} catch (JSONException e)
{
} catch (JSONException e) {
Log.e(tag, "Error in Json " + result);
}
return userArrayList;
}

public static String getUsername(String result)
{
public static String getUsername(String result) {
int start = result.indexOf("<meta property=\"og:title\" content=");
int end = result.indexOf("Instagram photos", result.indexOf("<meta property=\"og:title\" content="));
return result.substring(start + 35, end - 5);
}

public static String getProfilePicUrl(String result)
{
public static String getProfilePicUrl(String result) {
int start = result.indexOf("<meta property=\"og:image\" content=\"");
int end = result.indexOf(" />", result.indexOf("<meta property=\"og:image\" content="));
return result.substring(start + 35, end - 1);
}

public static String getProfilePicHDUrl(String result) {
int start = result.indexOf("\"profile_pic_url_hd\"");
int end = result.indexOf("\",", start);
return result.substring(start + 22, end);
}

/**
* media link that are video start with v followedby code then '@' after that url of thumbnail starts.
*/
public static String getimageUrl(String result, int pos, boolean full)
{
public static String getimageUrl(String result, int pos, boolean full) {
int start = result.indexOf("thumbnail_src", pos);
if ((start == -1) && (pos == 0))
return "private";
Expand All @@ -76,40 +74,34 @@ else if (start == -1)
pos = end;
int checkvideo = result.indexOf("\"is_video\"", pos);
String isvideo = result.substring(checkvideo + 12, result.indexOf(',', checkvideo));
if (isvideo.equals("true"))
{
if (isvideo.equals("true")) {
int cstart = result.indexOf(',', checkvideo) + 11;
int cend = result.indexOf('"', cstart);
String code = result.substring(cstart, cend);
Log.i(tag, "is video " + isvideo + " " + code);
return "v" + code + "@" + result.substring(start + 17, end);
} else if (full)
{
} else if (full) {
start = result.indexOf("display_src", pos);
end = result.indexOf("\",", result.indexOf("display_src", pos));
return result.substring(start + 15, end);
}
else
return result.substring(start + 17, end);
return result.substring(start + 14, end);
} else
return result.substring(start + 16, end);
}

public static String getnextpageID(String result, int pos)
{
public static String getnextpageID(String result, int pos) {
int index = 21;
int start = result.indexOf("\"GraphImage\", \"id\"", pos);
if (start == -1)
start = result.indexOf("\"GraphVideo\", \"id\"", pos);
if (start == -1)
{
if (start == -1) {
index += 2;
start = result.indexOf("\"GraphSidecar\", \"id\"", pos);
}
int end = result.indexOf("\",", start + 21);
return result.substring(start + index, end);
}

public static String formatURLforfullscreen(String tempurl)
{
public static String formatURLforfullscreen(String tempurl) {
int istart = tempurl.indexOf("s640x640/", 0);
if (istart == -1)
istart = tempurl.indexOf("s360x360/", 0);
Expand All @@ -125,38 +117,33 @@ public static String formatURLforfullscreen(String tempurl)
return tempurl.substring(0, istart) + tempurl.substring(iend);
}

public static String getFollowers(String result)
{
public static String getFollowers(String result) {
int index = result.indexOf("Followers");
int start = result.indexOf('"', index - 12);
return result.substring(start + 1, index - 1);
}

public static String getFollowing(String result)
{
public static String getFollowing(String result) {
int index = result.indexOf("Following");
int start = result.indexOf(',', index - 12);
return result.substring(start + 2, index - 1);
}

public static String getPosts(String result)
{
public static String getPosts(String result) {
int index = result.indexOf("Posts");
int start = result.indexOf(',', index - 12);
return result.substring(start + 2, index - 1);
}

public static String getVideoPageUrl(String code, String id)
{
public static String getVideoPageUrl(String code, String id) {
int start = id.indexOf("m/") + 2;
int end = id.indexOf("/", start);
String url = "https://www.instagram.com/p/" + code + "/?taken-by=" + id.substring(start, end);
Log.i(tag, url);
return url;
}

public static String getVideoUrl(String result)
{
public static String getVideoUrl(String result) {
int start = result.indexOf("\"og:video\" content") + 20;
int end = result.indexOf("\" />", start);
String videoUrl = result.substring(start, end);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ public boolean onLongClick(View v) {
}
});
} else {
if ((imgURLs.size() - 4 <= position + 1) && (imgURLs.size() >= 12)) {
if ((imgURLs.size() - 1 <= position + 1) && (imgURLs.size() >= 12)) {
Log.d(tag, "end reached");
if ((wait == false) && (nomoreposts == false) && (Private == false) && (internetworking == true))
loadmore();
Expand Down Expand Up @@ -231,8 +231,8 @@ public void onCompleted(Exception e, String result) {
}
pos = result.indexOf("\",", result.indexOf("thumbnail_src", pos));
} catch (NullPointerException ne) {
internetworking = false;
Toast.makeText(mContext, "Internet Not Working", Toast.LENGTH_SHORT).show();
/*internetworking = false;
Toast.makeText(mContext, "Internet Not Working", Toast.LENGTH_SHORT).show();*/
Log.e(tag, "Internet not working", ne);
} catch (StringIndexOutOfBoundsException finished) {
Toast.makeText(mContext, "No More posts", Toast.LENGTH_SHORT).show();
Expand Down
2 changes: 2 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
buildscript {
repositories {
jcenter()
google()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.0.1'
Expand All @@ -21,6 +22,7 @@ allprojects {
mavenCentral()
maven { url 'https://maven.google.com' }
maven { url 'https://dl.bintray.com/drummer-aidan/maven' }
google()
}
}

Expand Down

0 comments on commit de6d757

Please sign in to comment.