diff --git a/build.gradle b/build.gradle deleted file mode 100644 index 2b7a135..0000000 --- a/build.gradle +++ /dev/null @@ -1,52 +0,0 @@ -plugins { - id 'org.jetbrains.kotlin.jvm' version '1.3.61' - id 'org.jetbrains.dokka' version '0.10.1' -} - -group 'com.hadiyarajesh.instabot' -version '1.0.0' - -repositories { - mavenCentral() - jcenter() - maven { url 'https://jitpack.io' } -} - -dependencies { - implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8" - implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core:1.3.3" - implementation 'com.github.jkcclemens:khttp:-SNAPSHOT' - implementation 'com.nfeld.jsonpathlite:json-path-lite:1.1.0' - compile("org.json:json:20180813") - -} - -compileKotlin { - kotlinOptions.jvmTarget = "1.8" -} -compileTestKotlin { - kotlinOptions.jvmTarget = "1.8" -} - -dokka { - outputFormat = 'html' - outputDirectory = "$buildDir/dokka" - - configuration { - includeNonPublic = false - - perPackageOption { - prefix = "api" - suppress = true - } - perPackageOption { - prefix = "util" - suppress = true - } - - perPackageOption { - prefix = "com.nfeld.jsonpathlite" - suppress = true - } - } -} \ No newline at end of file diff --git a/build.gradle.kts b/build.gradle.kts new file mode 100644 index 0000000..f3abdb1 --- /dev/null +++ b/build.gradle.kts @@ -0,0 +1,54 @@ +plugins { + kotlin("jvm") version "1.4.30" + id("org.jetbrains.dokka") version "1.4.20" +} + +group = "com.hadiyarajesh" +version = "1.0.0" +java.sourceCompatibility = JavaVersion.VERSION_11 + +repositories { + mavenCentral() + jcenter() + maven(url = "https://jitpack.io") +} + +sourceSets { + main { + java.srcDir("src/main/kotlin") + } +} + +dependencies { + implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8") + implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.3.3") + implementation("com.github.jkcclemens:khttp:-SNAPSHOT") + implementation("com.nfeld.jsonpathlite:json-path-lite:1.1.0") + implementation("org.json:json:20180813") +} + +tasks.withType().configureEach { + dokkaSourceSets { + named("main") { + moduleName.set("instagram-api") + includeNonPublic.set(false) + + perPackageOption { + matchingRegex.set("api($|\\.).*") // will match all api packages and sub-packages + suppress.set(true) + } + perPackageOption { + matchingRegex.set("util($|\\.).*") // will match all util packages and sub-packages + suppress.set(true) + } + perPackageOption { + matchingRegex.set("samples($|\\.).*") // will match all samples packages and sub-packages + suppress.set(true) + } + perPackageOption { + matchingRegex.set("com.nfeld.jsonpathlite($|\\.).*") // will match all com.nfeld.jsonpathlite packages and sub-packages + suppress.set(true) + } + } + } +} \ No newline at end of file diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 65d2f34..ffaf513 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,5 +1,5 @@ #Tue Dec 24 00:37:30 CST 2019 -distributionUrl=https\://services.gradle.org/distributions/gradle-5.2.1-all.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-6.8.3-all.zip distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStorePath=wrapper/dists diff --git a/settings.gradle b/settings.gradle deleted file mode 100644 index 6f683c9..0000000 --- a/settings.gradle +++ /dev/null @@ -1,2 +0,0 @@ -rootProject.name = 'InstagramAPI' - diff --git a/settings.gradle.kts b/settings.gradle.kts new file mode 100644 index 0000000..adf0071 --- /dev/null +++ b/settings.gradle.kts @@ -0,0 +1,9 @@ +rootProject.name = "InstagramAPI" + +pluginManagement { + repositories { + gradlePluginPortal() + jcenter() + } +} + diff --git a/src/main/kotlin/BotTest.kt b/src/main/kotlin/BotTest.kt index 57ca74d..c1b3794 100644 --- a/src/main/kotlin/BotTest.kt +++ b/src/main/kotlin/BotTest.kt @@ -1,45 +1,47 @@ import bot.InstagramBot -import kotlinx.coroutines.* +import kotlinx.coroutines.ExperimentalCoroutinesApi +import kotlinx.coroutines.InternalCoroutinesApi import kotlinx.coroutines.flow.collect +import kotlinx.coroutines.runBlocking @InternalCoroutinesApi @ExperimentalCoroutinesApi -fun main() { +fun main() = runBlocking { - val username = "your_instagram_username" - val password = "your_instagram_password" + val username = Credentials.USERNAME + val password = Credentials.PASSWORD val bot = InstagramBot() bot.prepare(username) bot.login(username, password) /** - * Minimum and maximum time to sleep before performing next action. + * Minimum and maximum time (in seconds) to wait before performing next action. * Actual time will be randomly generated each time between min and max time */ - bot.minSleepTime = 100 - bot.maxSleepTime = 200 + bot.minSleepTime = 150 + bot.maxSleepTime = 300 + // Provide your comment list here val commentsList = listOf("Sample comment 1", "Sample comment 2") - val userList = listOf("username1", "username2") + // Provide your username list here + val userList = listOf("user_name_1", "user_name_2") - runBlocking { - // Get your own followers - bot.getSelfFollowing(Int.MAX_VALUE).collect { println(it) } - // Get 100 followers of given username - bot.getUserFollowers("user_name", 100, isUsername = true).collect { println(it) } - // Like 5 medias from explore page - bot.likeMediasByExplorePage(5).collect { println(it) } - // Comment 5 medias having given hashtag and given comment list - bot.commentMediasByHashTag("hashtag_name", commentsList, 5).collect { println(it) } - // Follow given list of users - bot.followUsers(userList).collect { println(it) } - // Approve all pending follow requests - bot.approveAllPendingFollowRequests().collect { println(it) } - // Watch stories of 200 users based on given location - bot.watchLocationUsersStories("location_name", 200).collect { println(it) } - // Download latest 5 medias of given username along with caption - bot.downloadUserMedias("user_name", 5, true).collect { println(it) } - } + // Get your own followers + bot.getSelfFollowing(Int.MAX_VALUE).collect { println(it) } + // Get 100 followers of given username + bot.getUserFollowers("enter_user_name_here", 100, isUsername = true).collect { println(it) } + // Like 5 medias from explore page + bot.likeMediasByExplorePage(5).collect { println(it) } + // Comment 5 medias having given hashtag and given comment list + bot.commentMediasByHashTag("enter_hashtag_name_here", commentsList, 5).collect { println(it) } + // Follow given list of users + bot.followUsers(userList).collect { println(it) } + // Approve all pending follow requests + bot.approveAllPendingFollowRequests().collect { println(it) } + // Watch stories of 200 users based on given location + bot.watchLocationUsersStories("enter_location_name_here", 200).collect { println(it) } + // Download latest 5 medias of given user along with caption + bot.downloadUserMedias("enter_user_name_here", 5, true).collect { println(it) } } \ No newline at end of file diff --git a/src/main/kotlin/Credentials.kt b/src/main/kotlin/Credentials.kt new file mode 100644 index 0000000..64fc96f --- /dev/null +++ b/src/main/kotlin/Credentials.kt @@ -0,0 +1,4 @@ +object Credentials { + const val USERNAME = "enter_your_instagram_username_here" + const val PASSWORD = "enter_your_instagram_password_here" +} \ No newline at end of file diff --git a/src/main/kotlin/api/InstagramAPI.kt b/src/main/kotlin/api/InstagramAPI.kt index 20ac714..3586ae8 100644 --- a/src/main/kotlin/api/InstagramAPI.kt +++ b/src/main/kotlin/api/InstagramAPI.kt @@ -22,6 +22,7 @@ import java.util.* import kotlin.math.max import kotlin.math.min import kotlin.random.Random +import kotlin.system.exitProcess object InstagramAPI { var username: String = "username" @@ -144,6 +145,7 @@ object InstagramAPI { return true } else { println("Username or password is incorrect.") + exitProcess(1) } } return false diff --git a/src/main/kotlin/samples/comment/CommentExploreTabMedias.kt b/src/main/kotlin/samples/comment/CommentExploreTabMedias.kt index 190058f..3b4c68a 100644 --- a/src/main/kotlin/samples/comment/CommentExploreTabMedias.kt +++ b/src/main/kotlin/samples/comment/CommentExploreTabMedias.kt @@ -1,15 +1,16 @@ package samples.comment +import Credentials import bot.InstagramBot import kotlinx.coroutines.ExperimentalCoroutinesApi import kotlinx.coroutines.flow.collect import kotlinx.coroutines.runBlocking @ExperimentalCoroutinesApi -fun main() { +fun main() = runBlocking { - val username = "your_instagram_username" - val password = "your_instagram_password" + val username = Credentials.USERNAME + val password = Credentials.PASSWORD val bot = InstagramBot() bot.prepare(username) @@ -18,7 +19,5 @@ fun main() { val commentList = listOf("Comment 1", "Comment 2") val howManyMediasYouWantToComment = 10 - runBlocking { - bot.commentMediasByExplorePage(commentList, howManyMediasYouWantToComment).collect { println(it) } - } + bot.commentMediasByExplorePage(commentList, howManyMediasYouWantToComment).collect { println(it) } } \ No newline at end of file diff --git a/src/main/kotlin/samples/comment/CommentHashTagMedias.kt b/src/main/kotlin/samples/comment/CommentHashTagMedias.kt index 806acc5..c739358 100644 --- a/src/main/kotlin/samples/comment/CommentHashTagMedias.kt +++ b/src/main/kotlin/samples/comment/CommentHashTagMedias.kt @@ -1,15 +1,16 @@ package samples.comment +import Credentials import bot.InstagramBot import kotlinx.coroutines.ExperimentalCoroutinesApi import kotlinx.coroutines.flow.collect import kotlinx.coroutines.runBlocking @ExperimentalCoroutinesApi -fun main() { +fun main() = runBlocking { - val username = "your_instagram_username" - val password = "your_instagram_password" + val username = Credentials.USERNAME + val password = Credentials.PASSWORD val bot = InstagramBot() bot.prepare(username) @@ -19,7 +20,5 @@ fun main() { val commentList = listOf("Comment 1", "Comment 2") val howManyMediasYouWantToComment = 10 - runBlocking { - bot.commentMediasByHashTag(hashTagName, commentList, howManyMediasYouWantToComment).collect { println(it) } - } + bot.commentMediasByHashTag(hashTagName, commentList, howManyMediasYouWantToComment).collect { println(it) } } \ No newline at end of file diff --git a/src/main/kotlin/samples/comment/CommentLocationBasedMedias.kt b/src/main/kotlin/samples/comment/CommentLocationBasedMedias.kt index 1fa2bd4..37bc757 100644 --- a/src/main/kotlin/samples/comment/CommentLocationBasedMedias.kt +++ b/src/main/kotlin/samples/comment/CommentLocationBasedMedias.kt @@ -1,15 +1,16 @@ package samples.comment +import Credentials import bot.InstagramBot import kotlinx.coroutines.ExperimentalCoroutinesApi import kotlinx.coroutines.flow.collect import kotlinx.coroutines.runBlocking @ExperimentalCoroutinesApi -fun main() { +fun main() = runBlocking { - val username = "your_instagram_username" - val password = "your_instagram_password" + val username = Credentials.USERNAME + val password = Credentials.PASSWORD val bot = InstagramBot() bot.prepare(username) @@ -19,7 +20,5 @@ fun main() { val commentList = listOf("Comment 1", "Comment 2") val howManyMediasYouWantToComment = 10 - runBlocking { - bot.commentMediasByLocation(locationName, commentList, howManyMediasYouWantToComment).collect { println(it) } - } + bot.commentMediasByLocation(locationName, commentList, howManyMediasYouWantToComment).collect { println(it) } } \ No newline at end of file diff --git a/src/main/kotlin/samples/dm/SendHashTagToTimeLineUsers.kt b/src/main/kotlin/samples/dm/SendHashTagToTimeLineUsers.kt index f9c952d..822957f 100644 --- a/src/main/kotlin/samples/dm/SendHashTagToTimeLineUsers.kt +++ b/src/main/kotlin/samples/dm/SendHashTagToTimeLineUsers.kt @@ -1,7 +1,7 @@ package samples.dm +import Credentials import bot.InstagramBot -import com.nfeld.jsonpathlite.extension.read import kotlinx.coroutines.ExperimentalCoroutinesApi import kotlinx.coroutines.flow.collect import kotlinx.coroutines.flow.map @@ -9,10 +9,10 @@ import kotlinx.coroutines.flow.toList import kotlinx.coroutines.runBlocking @ExperimentalCoroutinesApi -fun main() { +fun main() = runBlocking { - val username = "your_instagram_username" - val password = "your_instagram_password" + val username = Credentials.USERNAME + val password = Credentials.PASSWORD val bot = InstagramBot() bot.prepare(username) @@ -21,9 +21,8 @@ fun main() { val hashTagName = "enter_hashtag_name_here_without_#" val textName = "enter_text_name_to_send_along_with_hashtag" - runBlocking { - bot.sendDirectHashTagToUsers(bot.getUsersByTimeline().map { it.get("pk").toString() }.toList(), - hashTagName, textName).collect { println(it) } - } - + bot.sendDirectHashTagToUsers( + bot.getUsersByTimeline().map { it.get("pk").toString() }.toList(), + hashTagName, textName + ).collect { println(it) } } \ No newline at end of file diff --git a/src/main/kotlin/samples/dm/SendLikeToAllYourFollowers.kt b/src/main/kotlin/samples/dm/SendLikeToAllYourFollowers.kt index de76023..3f8e0b0 100644 --- a/src/main/kotlin/samples/dm/SendLikeToAllYourFollowers.kt +++ b/src/main/kotlin/samples/dm/SendLikeToAllYourFollowers.kt @@ -8,17 +8,15 @@ import kotlinx.coroutines.flow.toList import kotlinx.coroutines.runBlocking @ExperimentalCoroutinesApi -fun main() { +fun main() = runBlocking { - val username = "your_instagram_username" - val password = "your_instagram_password" + val username = Credentials.USERNAME + val password = Credentials.PASSWORD val bot = InstagramBot() bot.prepare(username) bot.login(username, password) - runBlocking { - val yourFollowers = bot.getSelfFollowers().toList() - bot.sendDirectLikeToUsers(yourFollowers).collect { println(it) } - } + val yourFollowers = bot.getSelfFollowers().toList() + bot.sendDirectLikeToUsers(yourFollowers).collect { println(it) } } \ No newline at end of file diff --git a/src/main/kotlin/samples/download/DownloadStoriesOfUser.kt b/src/main/kotlin/samples/download/DownloadStoriesOfUser.kt index b2f4305..50c8c9d 100644 --- a/src/main/kotlin/samples/download/DownloadStoriesOfUser.kt +++ b/src/main/kotlin/samples/download/DownloadStoriesOfUser.kt @@ -1,15 +1,16 @@ package samples.download +import Credentials import bot.InstagramBot import kotlinx.coroutines.ExperimentalCoroutinesApi import kotlinx.coroutines.flow.collect import kotlinx.coroutines.runBlocking @ExperimentalCoroutinesApi -fun main() { +fun main() = runBlocking { - val username = "your_instagram_username" - val password = "your_instagram_password" + val username = Credentials.USERNAME + val password = Credentials.PASSWORD val bot = InstagramBot() bot.prepare(username) @@ -17,7 +18,5 @@ fun main() { val user = "enter_username_here_whose_media_you_want_to_download" - runBlocking { - bot.downloadUserStories(user).collect { println(it) } - } + bot.downloadUserStories(user).collect { println(it) } } \ No newline at end of file diff --git a/src/main/kotlin/samples/download/DownloadUserMedias.kt b/src/main/kotlin/samples/download/DownloadUserMedias.kt index fbcc774..1ff35b2 100644 --- a/src/main/kotlin/samples/download/DownloadUserMedias.kt +++ b/src/main/kotlin/samples/download/DownloadUserMedias.kt @@ -1,15 +1,16 @@ package samples.download +import Credentials import bot.InstagramBot import kotlinx.coroutines.ExperimentalCoroutinesApi import kotlinx.coroutines.flow.collect import kotlinx.coroutines.runBlocking @ExperimentalCoroutinesApi -fun main() { +fun main() = runBlocking { - val username = "your_instagram_username" - val password = "your_instagram_password" + val username = Credentials.USERNAME + val password = Credentials.PASSWORD val bot = InstagramBot() bot.prepare(username) @@ -19,9 +20,9 @@ fun main() { val howManyMediasYouWantToDownload = 10 val doYouWantToSaveDescriptionOfMedias = false - runBlocking { - bot.downloadUserMedias(user, howManyMediasYouWantToDownload, doYouWantToSaveDescriptionOfMedias).collect { - println(it) - } - } + bot.downloadUserMedias( + user, + howManyMediasYouWantToDownload, + doYouWantToSaveDescriptionOfMedias + ).collect { println(it) } } \ No newline at end of file diff --git a/src/main/kotlin/samples/follow/FollowUserByLocation.kt b/src/main/kotlin/samples/follow/FollowUserByLocation.kt index f47474a..36db51d 100644 --- a/src/main/kotlin/samples/follow/FollowUserByLocation.kt +++ b/src/main/kotlin/samples/follow/FollowUserByLocation.kt @@ -1,7 +1,7 @@ package samples.follow +import Credentials import bot.InstagramBot -import com.nfeld.jsonpathlite.extension.read import kotlinx.coroutines.ExperimentalCoroutinesApi import kotlinx.coroutines.flow.collect import kotlinx.coroutines.flow.map @@ -9,10 +9,10 @@ import kotlinx.coroutines.flow.toList import kotlinx.coroutines.runBlocking @ExperimentalCoroutinesApi -fun main() { +fun main() = runBlocking { - val username = "your_instagram_username" - val password = "your_instagram_password" + val username = Credentials.USERNAME + val password = Credentials.PASSWORD val bot = InstagramBot() bot.prepare(username) @@ -21,8 +21,8 @@ fun main() { val locationName = "enter_location_name_here" val howManyFollowersYouWantToFollow = 10 - runBlocking { - bot.followUsers(bot.getUsersByLocation(locationName, howManyFollowersYouWantToFollow) - .map { it.get("pk").toString() }.toList()).collect { println(it) } - } + bot.followUsers( + bot.getUsersByLocation(locationName, howManyFollowersYouWantToFollow) + .map { it.get("pk").toString() }.toList() + ).collect { println(it) } } \ No newline at end of file diff --git a/src/main/kotlin/samples/follow/FollowUsersFollowers.kt b/src/main/kotlin/samples/follow/FollowUsersFollowers.kt index 7e5606e..5c83f36 100644 --- a/src/main/kotlin/samples/follow/FollowUsersFollowers.kt +++ b/src/main/kotlin/samples/follow/FollowUsersFollowers.kt @@ -1,15 +1,16 @@ package samples.follow +import Credentials import bot.InstagramBot import kotlinx.coroutines.ExperimentalCoroutinesApi import kotlinx.coroutines.flow.collect import kotlinx.coroutines.runBlocking @ExperimentalCoroutinesApi -fun main() { +fun main() = runBlocking { - val username = "your_instagram_username" - val password = "your_instagram_password" + val username = Credentials.USERNAME + val password = Credentials.PASSWORD val bot = InstagramBot() bot.prepare(username) @@ -18,7 +19,5 @@ fun main() { val user = "enter_username_whose_followers_you_want_to_follow_here" val howManyFollowersYouWantToFollow = 10 - runBlocking { - bot.followUserFollowers(user, howManyFollowersYouWantToFollow).collect { println(it) } - } + bot.followUserFollowers(user, howManyFollowersYouWantToFollow).collect { println(it) } } \ No newline at end of file diff --git a/src/main/kotlin/samples/follow/UnfollowNonFollowers.kt b/src/main/kotlin/samples/follow/UnfollowNonFollowers.kt index c8bf90e..72b3f19 100644 --- a/src/main/kotlin/samples/follow/UnfollowNonFollowers.kt +++ b/src/main/kotlin/samples/follow/UnfollowNonFollowers.kt @@ -1,21 +1,20 @@ package samples.follow +import Credentials import bot.InstagramBot import kotlinx.coroutines.ExperimentalCoroutinesApi import kotlinx.coroutines.flow.collect import kotlinx.coroutines.runBlocking @ExperimentalCoroutinesApi -fun main() { +fun main() = runBlocking { - val username = "your_instagram_username" - val password = "your_instagram_password" + val username = Credentials.USERNAME + val password = Credentials.PASSWORD val bot = InstagramBot() bot.prepare(username) bot.login(username, password) - runBlocking { - bot.unfollowNonFollowers().collect { println(it) } - } + bot.unfollowNonFollowers().collect { println(it) } } \ No newline at end of file diff --git a/src/main/kotlin/samples/like/LikeExploreTabMedias.kt b/src/main/kotlin/samples/like/LikeExploreTabMedias.kt index 9722f9e..bddff2c 100644 --- a/src/main/kotlin/samples/like/LikeExploreTabMedias.kt +++ b/src/main/kotlin/samples/like/LikeExploreTabMedias.kt @@ -1,15 +1,16 @@ package samples.like +import Credentials import bot.InstagramBot import kotlinx.coroutines.ExperimentalCoroutinesApi import kotlinx.coroutines.flow.collect import kotlinx.coroutines.runBlocking @ExperimentalCoroutinesApi -fun main() { +fun main() = runBlocking { - val username = "your_instagram_username" - val password = "your_instagram_password" + val username = Credentials.USERNAME + val password = Credentials.PASSWORD val bot = InstagramBot() bot.prepare(username) @@ -17,7 +18,5 @@ fun main() { val howManyMediasYouWantToLike = 10 - runBlocking { - bot.likeMediasByExplorePage(howManyMediasYouWantToLike).collect { println(it) } - } + bot.likeMediasByExplorePage(howManyMediasYouWantToLike).collect { println(it) } } \ No newline at end of file diff --git a/src/main/kotlin/samples/like/LikeHashTagMedias.kt b/src/main/kotlin/samples/like/LikeHashTagMedias.kt index 23ed1cd..aea031e 100644 --- a/src/main/kotlin/samples/like/LikeHashTagMedias.kt +++ b/src/main/kotlin/samples/like/LikeHashTagMedias.kt @@ -1,15 +1,16 @@ package samples.like +import Credentials import bot.InstagramBot import kotlinx.coroutines.ExperimentalCoroutinesApi import kotlinx.coroutines.flow.collect import kotlinx.coroutines.runBlocking @ExperimentalCoroutinesApi -fun main() { +fun main() = runBlocking { - val username = "your_instagram_username" - val password = "your_instagram_password" + val username = Credentials.USERNAME + val password = Credentials.PASSWORD val bot = InstagramBot() bot.prepare(username) @@ -18,7 +19,5 @@ fun main() { val hashTagName = "enter_hashtag_name_here" val howManyMediasYouWantToLike = 10 - runBlocking { - bot.likeMediasByHashTag(hashTagName, howManyMediasYouWantToLike).collect { println(it) } - } + bot.likeMediasByHashTag(hashTagName, howManyMediasYouWantToLike).collect { println(it) } } \ No newline at end of file diff --git a/src/main/kotlin/samples/like/LikeLocationBasedMedias.kt b/src/main/kotlin/samples/like/LikeLocationBasedMedias.kt index 475aff3..a7057a4 100644 --- a/src/main/kotlin/samples/like/LikeLocationBasedMedias.kt +++ b/src/main/kotlin/samples/like/LikeLocationBasedMedias.kt @@ -1,15 +1,16 @@ package samples.like +import Credentials import bot.InstagramBot import kotlinx.coroutines.ExperimentalCoroutinesApi import kotlinx.coroutines.flow.collect import kotlinx.coroutines.runBlocking @ExperimentalCoroutinesApi -fun main() { +fun main() = runBlocking { - val username = "your_instagram_username" - val password = "your_instagram_password" + val username = Credentials.USERNAME + val password = Credentials.PASSWORD val bot = InstagramBot() bot.prepare(username) @@ -18,7 +19,5 @@ fun main() { val locationName = "enter_location_name_here" val howManyMediasYouWantToLike = 10 - runBlocking { - bot.likeMediasByLocation(locationName, howManyMediasYouWantToLike).collect { println(it) } - } + bot.likeMediasByLocation(locationName, howManyMediasYouWantToLike).collect { println(it) } } \ No newline at end of file diff --git a/src/main/kotlin/samples/stories/WatchStoriesByLocation.kt b/src/main/kotlin/samples/stories/WatchStoriesByLocation.kt index 3eb9fb4..64b4669 100644 --- a/src/main/kotlin/samples/stories/WatchStoriesByLocation.kt +++ b/src/main/kotlin/samples/stories/WatchStoriesByLocation.kt @@ -1,16 +1,16 @@ package samples.stories +import Credentials import bot.InstagramBot -import com.nfeld.jsonpathlite.extension.read import kotlinx.coroutines.ExperimentalCoroutinesApi import kotlinx.coroutines.flow.collect import kotlinx.coroutines.runBlocking @ExperimentalCoroutinesApi -fun main() { +fun main() = runBlocking { - val username = "your_instagram_username" - val password = "your_instagram_password" + val username = Credentials.USERNAME + val password = Credentials.PASSWORD val bot = InstagramBot() bot.prepare(username) @@ -19,7 +19,8 @@ fun main() { val locationName = "enter_location_name_here" val howManyUsersYouWantToWatchStories = 10 - runBlocking { - bot.watchLocationUsersStories(locationName, howManyUsersYouWantToWatchStories).collect { println(it) } - } + bot.watchLocationUsersStories( + locationName, + howManyUsersYouWantToWatchStories + ).collect { println(it) } } \ No newline at end of file diff --git a/src/main/kotlin/samples/stories/WatchStoriesFromExploreTab.kt b/src/main/kotlin/samples/stories/WatchStoriesFromExploreTab.kt index ac47d28..3bbb87b 100644 --- a/src/main/kotlin/samples/stories/WatchStoriesFromExploreTab.kt +++ b/src/main/kotlin/samples/stories/WatchStoriesFromExploreTab.kt @@ -1,22 +1,20 @@ package samples.stories +import Credentials import bot.InstagramBot -import com.nfeld.jsonpathlite.extension.read import kotlinx.coroutines.ExperimentalCoroutinesApi import kotlinx.coroutines.flow.collect import kotlinx.coroutines.runBlocking @ExperimentalCoroutinesApi -fun main() { +fun main() = runBlocking { - val username = "your_instagram_username" - val password = "your_instagram_password" + val username = Credentials.USERNAME + val password = Credentials.PASSWORD val bot = InstagramBot() bot.prepare(username) bot.login(username, password) - runBlocking { - bot.watchExploreTabUsersStories().collect { println(it) } - } + bot.watchExploreTabUsersStories().collect { println(it) } } \ No newline at end of file diff --git a/src/main/kotlin/samples/stories/WatchStoriesOfUserFollowers.kt b/src/main/kotlin/samples/stories/WatchStoriesOfUserFollowers.kt index e96b29a..056cfbd 100644 --- a/src/main/kotlin/samples/stories/WatchStoriesOfUserFollowers.kt +++ b/src/main/kotlin/samples/stories/WatchStoriesOfUserFollowers.kt @@ -1,17 +1,17 @@ package samples.stories +import Credentials import bot.InstagramBot -import com.nfeld.jsonpathlite.extension.read import kotlinx.coroutines.ExperimentalCoroutinesApi import kotlinx.coroutines.flow.collect import kotlinx.coroutines.flow.toList import kotlinx.coroutines.runBlocking @ExperimentalCoroutinesApi -fun main() { +fun main() = runBlocking { - val username = "your_instagram_username" - val password = "your_instagram_password" + val username = Credentials.USERNAME + val password = Credentials.PASSWORD val bot = InstagramBot() bot.prepare(username) @@ -21,7 +21,7 @@ fun main() { val user = "enter_username_whose_followers_stories_you_want_to_watch" val howManyFollowersYouWantWatchStories = 10 - runBlocking { - bot.watchUsersStories(bot.getUserFollowers(user, howManyFollowersYouWantWatchStories).toList()).collect { println(it) } - } + bot.watchUsersStories( + bot.getUserFollowers(user, howManyFollowersYouWantWatchStories).toList() + ).collect { println(it) } } \ No newline at end of file diff --git a/src/main/kotlin/util/Config.kt b/src/main/kotlin/util/Config.kt index 0b324cc..f678168 100644 --- a/src/main/kotlin/util/Config.kt +++ b/src/main/kotlin/util/Config.kt @@ -42,10 +42,10 @@ object HTTP { ) } -val USER_AGENT: String = "Instagram ${one_plus_7.instagram_version} " + - "Android (${one_plus_7.android_version}/${one_plus_7.android_release}; " + - "${one_plus_7.dpi}; ${one_plus_7.resolution}; ${one_plus_7.manufacturer}; " + - "${one_plus_7.device}; ${one_plus_7.model}; ${one_plus_7.cpu}; en_US)" +val USER_AGENT: String = "Instagram ${Devices.DEFAULT_DEVICE.instagramVersion} " + + "Android (${Devices.DEFAULT_DEVICE.androidVersion}/${Devices.DEFAULT_DEVICE.androidRelease}; " + + "${Devices.DEFAULT_DEVICE.dpi}; ${Devices.DEFAULT_DEVICE.resolution}; ${Devices.DEFAULT_DEVICE.manufacturer}; " + + "${Devices.DEFAULT_DEVICE.device}; ${Devices.DEFAULT_DEVICE.model}; ${Devices.DEFAULT_DEVICE.cpu}; en_US)" // File names diff --git a/src/main/kotlin/util/Device.kt b/src/main/kotlin/util/Device.kt index 065f344..44963eb 100644 --- a/src/main/kotlin/util/Device.kt +++ b/src/main/kotlin/util/Device.kt @@ -1,6 +1,13 @@ package util -data class Device(val instagram_version: String = "126.0.0.25.121", val android_version : Int = 29, - val android_release: String = "10.0", val dpi: String = "420dpi", - val resolution: String = "1080x2260", val manufacturer: String = "OnePlus", - val device: String = "GM1903", val model: String = "OnePlus7", val cpu: String = "qcom") \ No newline at end of file +data class Device( + val instagramVersion: String, + val androidVersion: Int, + val androidRelease: String, + val dpi: String, + val resolution: String, + val manufacturer: String, + val device: String, + val model: String, + val cpu: String +) \ No newline at end of file diff --git a/src/main/kotlin/util/Devices.kt b/src/main/kotlin/util/Devices.kt new file mode 100644 index 0000000..af69e94 --- /dev/null +++ b/src/main/kotlin/util/Devices.kt @@ -0,0 +1,22 @@ +package util + +object Devices { + private const val INSTAGRAM_VERSION_OLD: String = "105.0.0.18.119" + private const val INSTAGRAM_VERSION_NEW: String = "126.0.0.25.121" + + // Released on August 2019 + val onePlus7 = Device( + INSTAGRAM_VERSION_NEW, 29, "10.0", "420dpi", + "1080x2260", "OnePlus", "GM1903", + "OnePlus7", "qcom" + ) + + // Released on February 2018 + val samsungGalaxyS9Plus = Device( + INSTAGRAM_VERSION_OLD, 24, "7.0", "640dpi", + "1440x2560", "samsung", "SM-G965F", + "star2qltecs", "samsungexynos9810" + ) + + val DEFAULT_DEVICE: Device = onePlus7 +} \ No newline at end of file diff --git a/src/main/kotlin/util/LoginException.kt b/src/main/kotlin/util/LoginException.kt index b1c341a..a553d64 100644 --- a/src/main/kotlin/util/LoginException.kt +++ b/src/main/kotlin/util/LoginException.kt @@ -1,6 +1,6 @@ package util -class LoginException(message: String): Exception() { +class LoginException(message: String) : Exception() { val msg = message override fun toString(): String { return msg diff --git a/src/main/kotlin/util/devices.kt b/src/main/kotlin/util/devices.kt deleted file mode 100644 index 967fcb5..0000000 --- a/src/main/kotlin/util/devices.kt +++ /dev/null @@ -1,14 +0,0 @@ -package util - - -const val INSTAGRAM_VERSION: String = "105.0.0.18.119" - -// Released on August 2019 -val one_plus_7 = Device() - -// Released on February 2018 -val samsung_galaxy_s9_plus = Device( - INSTAGRAM_VERSION, 24, "7.0", "640dpi", - "1440x2560", "samsung", "SM-G965F", - "star2qltecs", "samsungexynos9810" -) \ No newline at end of file