Skip to content

Commit ecf873b

Browse files
committed
changes in response
1 parent 6f1f2eb commit ecf873b

3 files changed

Lines changed: 32 additions & 11 deletions

File tree

OGParser/src/main/java/com/kedia/ogparser/JsoupNetworkCall.kt

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
package com.kedia.ogparser
22

33
import android.util.Log
4-
import kotlinx.coroutines.Dispatchers
5-
import kotlinx.coroutines.launch
64
import org.jsoup.Jsoup
75

86
class JsoupNetworkCall {
@@ -62,6 +60,19 @@ class JsoupNetworkCall {
6260
}
6361
}
6462
}
63+
64+
Log.e("TAG!!!!!", "result ${doc.select("meta[name=description]").first().attr("content")} ${checkNullParserResult(openGraphResult)}")
65+
66+
if (openGraphResult!!.title.isNullOrEmpty())
67+
openGraphResult!!.title = doc.title()
68+
if (openGraphResult!!.description.isNullOrEmpty())
69+
openGraphResult!!.description = if (doc.select("meta[name=description]").size != 0) doc.select("meta[name=description]")
70+
.first().attr("content") else ""
71+
if (openGraphResult!!.url.isNullOrEmpty())
72+
openGraphResult!!.url = getBaseUrl(url)
73+
74+
75+
6576
} catch (e: Exception) {
6677
e.printStackTrace()
6778
return null
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,18 @@
11
package com.kedia.ogparser
22

3+
import java.net.URI
4+
import java.net.URL
5+
36
fun checkNullParserResult(openGraphResult: OpenGraphResult?): Boolean {
47
return (openGraphResult?.title.isNullOrEmpty() ||
58
openGraphResult?.title.equals("null")) &&
69
(openGraphResult?.description.isNullOrEmpty() ||
710
openGraphResult?.description.equals(
811
"null"
912
))
13+
}
14+
15+
fun getBaseUrl(urlString: String): String {
16+
val url: URL = URI.create(urlString).toURL()
17+
return url.protocol.toString() + "://" + url.authority + "/"
1018
}

app/src/main/java/com/kedia/opengraphpreview/MainActivity.kt

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,17 @@ class MainActivity : AppCompatActivity(), OpenGraphCallback {
1313
private val openGraphParser by lazy { OpenGraphParser(this, showNullOnEmpty = true) }
1414

1515
private val LINKS_TO_TEST = mutableListOf(
16-
"https://www.linkedin.com/posts/madhusmita-padhy_machinelearning-datascience-activity-6886390508722163712-yhQ0",
17-
"https://www.youtube.com/watch?v=n3zsoX7bRlc",
18-
"https://twitter.com/levelsio/status/1481942293108359168",
19-
"https://stackoverflow.com/questions/44515769/conda-is-not-recognized-as-internal-or-external-command",
20-
"https://github.com/Priyansh-Kedia/OpenGraphParser",
21-
"https://chat.whatsapp.com/DdWAKRkt2VfAmd4OS47y7P",
22-
"https://www.reddit.com/r/MachineLearning/comments/s3mjqf/deep_learning_interviews_hundreds_of_fully_solved/?utm_medium=android_app&utm_source=share",
23-
"https://instagram.com/fcbarcelona?utm_medium=copy_link",
24-
"https://www.facebook.com/groups/777946865955982/permalink/1385110621906267/"
16+
// "https://www.linkedin.com/posts/madhusmita-padhy_machinelearning-datascience-activity-6886390508722163712-yhQ0",
17+
// "https://www.youtube.com/watch?v=n3zsoX7bRlc",
18+
// "https://twitter.com/levelsio/status/1481942293108359168",
19+
// "https://stackoverflow.com/questions/44515769/conda-is-not-recognized-as-internal-or-external-command",
20+
// "https://github.com/Priyansh-Kedia/OpenGraphParser",
21+
// "https://chat.whatsapp.com/DdWAKRkt2VfAmd4OS47y7P",
22+
// "https://www.reddit.com/r/MachineLearning/comments/s3mjqf/deep_learning_interviews_hundreds_of_fully_solved/?utm_medium=android_app&utm_source=share",
23+
// "https://instagram.com/fcbarcelona?utm_medium=copy_link",
24+
// "https://www.facebook.com/groups/777946865955982/permalink/1385110621906267/",
25+
"https://www.youtube.com/",
26+
"https://www.instagram.com/"
2527
)
2628

2729
override fun onCreate(savedInstanceState: Bundle?) {

0 commit comments

Comments
 (0)