Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[IMPROVEMENT] Prevent 429 error with bandcamp api #55

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import org.jsoup.HttpStatusException
import org.jsoup.Jsoup
import java.util.*
import java.util.regex.Pattern
import java.util.concurrent.TimeUnit


class BandcampAPIConnector constructor(
private val bandcampUser: String,
Expand Down Expand Up @@ -166,6 +168,7 @@ class BandcampAPIConnector constructor(
// Append download pages from this api endpoint as well
val theRest =
util.retry({
TimeUnit.SECONDS.sleep((1 + Random().nextInt(2)).toLong())
Jsoup.connect("https://bandcamp.com/api/fancollection/1/${collectionName}")
.ignoreContentType(true)
.timeout(timeout)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import java.time.temporal.ChronoField
import java.util.*
import java.util.concurrent.*
import java.util.stream.Collectors
import java.util.concurrent.TimeUnit

class BandcampCollectionDownloader(
private val args: Command,
Expand Down Expand Up @@ -150,7 +151,7 @@ class BandcampCollectionDownloader(
}

private fun manageDownloadPage(connector: BandcampAPIConnector, saleItemId: String, cache: Cache) {

TimeUnit.SECONDS.sleep((1 + Random().nextInt(2)).toLong())
val digitalItem = connector.retrieveDigitalItemData(saleItemId)

// If null, then the download page is simply invalid and not usable anymore, therefore it can be added to the cache
Expand Down