Skip to content

Commit

Permalink
Merge pull request #223 from Shikkanime/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
Ziedelth authored Feb 29, 2024
2 parents 091c8a3 + a7392bd commit 7469f34
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 31 deletions.
37 changes: 17 additions & 20 deletions src/main/kotlin/fr/shikkanime/jobs/FetchEpisodesJob.kt
Original file line number Diff line number Diff line change
Expand Up @@ -82,12 +82,7 @@ class FetchEpisodesJob : AbstractJob {

if (savedEpisodes.isNotEmpty() && savedEpisodes.size < configCacheService.getValueAsInt(ConfigPropertyKey.SOCIAL_NETWORK_EPISODES_SIZE_LIMIT)) {
val dtos = AbstractConverter.convert(savedEpisodes, EpisodeDto::class.java)

dtos.forEach {
Thread {
sendToSocialNetworks(it)
}.start()
}
dtos.forEach { sendToSocialNetworks(it) }
}

isRunning = false
Expand All @@ -104,20 +99,22 @@ class FetchEpisodesJob : AbstractJob {
}

Constant.abstractSocialNetworks.forEach { socialNetwork ->
try {
socialNetwork.sendEpisodeRelease(dto, mediaImage)
} catch (e: Exception) {
logger.log(
Level.SEVERE,
"Error while sending episode release for ${
socialNetwork.javaClass.simpleName.replace(
"SocialNetwork",
""
)
}",
e
)
}
Thread {
try {
socialNetwork.sendEpisodeRelease(dto, mediaImage)
} catch (e: Exception) {
logger.log(
Level.SEVERE,
"Error while sending episode release for ${
socialNetwork.javaClass.simpleName.replace(
"SocialNetwork",
""
)
}",
e
)
}
}.start()
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ class BskySocialNetwork : AbstractSocialNetwork() {
try {
val identifier = requireNotNull(configCacheService.getValueAsString(ConfigPropertyKey.BSKY_IDENTIFIER))
val password = requireNotNull(configCacheService.getValueAsString(ConfigPropertyKey.BSKY_PASSWORD))
if (identifier.isBlank() || password.isBlank()) throw Exception("Identifier or password is empty")
val session = runBlocking { BskyWrapper.createSession(identifier, password) }
accessJwt = requireNotNull(session.getAsString("accessJwt"))
did = requireNotNull(session.getAsString("did"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@ class DiscordSocialNetwork : AbstractSocialNetwork() {
if (isInitialized) return

try {
val builder = JDABuilder.createDefault(configCacheService.getValueAsString(ConfigPropertyKey.DISCORD_TOKEN))
val token = requireNotNull(configCacheService.getValueAsString(ConfigPropertyKey.DISCORD_TOKEN))
if (token.isBlank()) throw Exception("Token is empty")
val builder = JDABuilder.createDefault(token)
builder.setActivity(Activity.playing(BASE_URL))
jda = builder.build()
jda?.awaitReady()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class ThreadsSocialNetwork : AbstractSocialNetwork() {
try {
val username = requireNotNull(configCacheService.getValueAsString(ConfigPropertyKey.THREADS_USERNAME))
val password = requireNotNull(configCacheService.getValueAsString(ConfigPropertyKey.THREADS_PASSWORD))

if (username.isBlank() || password.isBlank()) throw Exception("Username or password is empty")
val generateDeviceId = ThreadsWrapper.generateDeviceId(username, password)
val (token, userId) = runBlocking { ThreadsWrapper.login(generateDeviceId, username, password) }

Expand All @@ -39,7 +39,7 @@ class ThreadsSocialNetwork : AbstractSocialNetwork() {
isInitialized = true
initializedAt = ZonedDateTime.now()
} catch (e: Exception) {
logger.log(Level.SEVERE, "Error while initializing BskySocialNetwork", e)
logger.log(Level.SEVERE, "Error while initializing ThreadsSocialNetwork", e)
}
}

Expand Down Expand Up @@ -71,7 +71,7 @@ class ThreadsSocialNetwork : AbstractSocialNetwork() {
Platform.CRUN -> "@crunchyroll_fr"
Platform.NETF -> "@netflixfr"
Platform.PRIM -> "@primevideofr"
else -> platform.name
else -> platform.platformName
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,19 @@ class TwitterSocialNetwork : AbstractSocialNetwork() {
if (isInitialized) return

try {
val consumerKey = requireNotNull(configCacheService.getValueAsString(ConfigPropertyKey.TWITTER_CONSUMER_KEY))
val consumerSecret = requireNotNull(configCacheService.getValueAsString(ConfigPropertyKey.TWITTER_CONSUMER_SECRET))
val accessToken = requireNotNull(configCacheService.getValueAsString(ConfigPropertyKey.TWITTER_ACCESS_TOKEN))
val accessTokenSecret = requireNotNull(configCacheService.getValueAsString(ConfigPropertyKey.TWITTER_ACCESS_TOKEN_SECRET))
if (consumerKey.isBlank() || consumerSecret.isBlank() || accessToken.isBlank() || accessTokenSecret.isBlank()) throw Exception("Twitter credentials are empty")

twitter = TwitterFactory(
ConfigurationBuilder()
.setDebugEnabled(true)
.setOAuthConsumerKey(configCacheService.getValueAsString(ConfigPropertyKey.TWITTER_CONSUMER_KEY))
.setOAuthConsumerSecret(configCacheService.getValueAsString(ConfigPropertyKey.TWITTER_CONSUMER_SECRET))
.setOAuthAccessToken(configCacheService.getValueAsString(ConfigPropertyKey.TWITTER_ACCESS_TOKEN))
.setOAuthAccessTokenSecret(configCacheService.getValueAsString(ConfigPropertyKey.TWITTER_ACCESS_TOKEN_SECRET))
.setOAuthConsumerKey(consumerKey)
.setOAuthConsumerSecret(consumerSecret)
.setOAuthAccessToken(accessToken)
.setOAuthAccessTokenSecret(accessTokenSecret)
.build()
).instance

Expand Down
8 changes: 5 additions & 3 deletions src/main/kotlin/fr/shikkanime/wrappers/ThreadsWrapper.kt
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ object ThreadsWrapper {
private val httpRequest = HttpRequest()
private val secureRandom = SecureRandom()

suspend fun qeSync(): HttpResponse {
private suspend fun qeSync(): HttpResponse {
val uuid = UUID.randomUUID().toString()

return httpRequest.post(
Expand All @@ -54,11 +54,13 @@ object ThreadsWrapper {
)
}

suspend fun encryptPassword(password: String): Map<String, String> {
private suspend fun encryptPassword(password: String): Map<String, String> {
// https://github.com/instagram4j/instagram4j/blob/39635974c391e21a322ab3294275df99d7f75f84/src/main/java/com/github/instagram4j/instagram4j/utils/IGUtils.java#L176
val randKey = ByteArray(32).also { secureRandom.nextBytes(it) }
val iv = ByteArray(12).also { secureRandom.nextBytes(it) }
val headers = qeSync().headers
val response = qeSync()
require(response.status.value == 200) { "Failed to get qeSync: ${response.status}" }
val headers = response.headers
val time = (System.currentTimeMillis() / 1000).toString()

val passwordEncryptionKeyID = headers["ig-set-password-encryption-key-id"]!!.toInt()
Expand Down

0 comments on commit 7469f34

Please sign in to comment.