Skip to content

Commit

Permalink
Fix MP3 grabbing algorithm
Browse files Browse the repository at this point in the history
  • Loading branch information
ruslanys committed Oct 19, 2018
1 parent 4d694d9 commit 524df69
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 3 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,13 @@
и [Семантическом версионировании](http://semver.org/lang/ru/spec/v2.0.0.html).

## [Новое]
### Исправлено
- Обновлен алгоритм выгрузки адресов MP3 файлов,
в соответствии с правками, внесенными на стороне VK.

### Изменено
- Spring Boot обновлен до версии 2.0.6.
- Gradle обновлен до 4.10.2

## [3.1.2] - 2018-09-14
### Исправлено
Expand Down
16 changes: 13 additions & 3 deletions src/main/kotlin/me/ruslanys/vkmusic/component/ScraperVkClient.kt
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ class ScraperVkClient : VkClient {
private const val JSON_DELIMITER = "<!json>"
private const val BLOCK_DELIMITER = "<!>"
private const val SLEEP_INTERVAL = 5000L
private const val CHUNK_SIZE = 5

private val SCRIPT_ENGINE = ScriptEngineManager().getEngineByName("JavaScript")
private val log = LoggerFactory.getLogger(ScraperVkClient::class.java)
Expand Down Expand Up @@ -115,7 +116,7 @@ class ScraperVkClient : VkClient {
val userId = fetchUserId()
var sleepInterval = SLEEP_INTERVAL

val chunks = audioList.chunked(10)
val chunks = audioList.chunked(CHUNK_SIZE)
var chunkNumber = 0
while (chunkNumber < chunks.size) {
val chunkContent = chunks[chunkNumber]
Expand All @@ -139,7 +140,8 @@ class ScraperVkClient : VkClient {

private fun fetchUrlsChunk(userId: Long, audioList: List<Audio>) {
val audioMap = audioList.associateBy { it.id }.toSortedMap()
val ids = audioList.joinToString(",") { "${it.ownerId}_${it.id}" }
val ids = audioList.joinToString(",") { "${it.ownerId}_${it.id}_${it.hash}" }
.plus(",${audioList.first().ownerId}_${audioList.first().id}")

val response = Jsoup.connect("$PATH_BASE/al_audio.php")
.userAgent(USER_AGENT).cookies(cookies).method(Connection.Method.POST)
Expand Down Expand Up @@ -188,7 +190,15 @@ class ScraperVkClient : VkClient {
(it[1] as Number).toLong(),
StringEscapeUtils.unescapeHtml4(it[4] as String),
StringEscapeUtils.unescapeHtml4(it[3] as String),
it[5] as Int
it[5] as Int,
(it[13] as String).split("/") // hash
.reduceIndexed { index, acc, s ->
when (index) {
2 -> s
5 -> acc + "_" + s
else -> acc
}
}
)
}.toList()
) {
Expand Down
1 change: 1 addition & 0 deletions src/main/kotlin/me/ruslanys/vkmusic/domain/Audio.kt
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ data class Audio(
val artist: String,
val title: String,
val durationInSec: Int,
val hash: String,

var status: DownloadStatus = DownloadStatus.NEW,
var url: String? = null,
Expand Down

0 comments on commit 524df69

Please sign in to comment.