Skip to content

Commit

Permalink
chore: add KDocs and integrate Koin for dependency injection
Browse files Browse the repository at this point in the history
  • Loading branch information
abdlhay committed Nov 14, 2024
1 parent bec987e commit 319b7b3
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 7 deletions.
9 changes: 4 additions & 5 deletions src/main/kotlin/com/abmo/services/VideoDownloader.kt
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
package com.abmo.services

import com.abmo.common.Logger
import com.abmo.model.*
import com.abmo.crypto.CryptoHelper
import com.abmo.executor.JavaScriptExecutor
import com.abmo.model.*
import com.abmo.util.displayProgressBar
import com.abmo.util.toJson
import com.abmo.util.toReadableTime
Expand Down Expand Up @@ -125,7 +124,7 @@ class VideoDownloader: KoinComponent {
*
* @param segmentFolderPath The folder containing the video segments.
* @param output The output file where the merged segments will be written.
* @throws IOException If there is an error reading or writing the segment files.
* @throws Exception If there is an error reading or writing the segment files.
*/
private fun mergeSegmentsIntoMp4(segmentFolderPath: File, output: File) {
val segmentFiles = segmentFolderPath.listFiles { file -> file.name.startsWith("segment_") }
Expand Down Expand Up @@ -269,7 +268,7 @@ class VideoDownloader: KoinComponent {
* @throws Exception If the request fails or the response status is not successful.
*/
private suspend fun requestSegment(url: String, body: String, index: Int? = null): Flow<ByteArray> = flow {
println("\n")
// println("\n")
Logger.debug("[$index] Starting HTTP POST request to $url with body length: ${body.length}. Body (truncated): \"...$body")
val response = Unirest.post(url)
.header("Content-Type", "application/json")
Expand All @@ -279,7 +278,7 @@ class VideoDownloader: KoinComponent {
val rawBody = response.rawBody
val responseCode = response.status

println("\n")
// println("\n")
Logger.debug("[$index] Received response with status $responseCode\n", responseCode !in 200..299)

val buffer = ByteArray(65536)
Expand Down
4 changes: 2 additions & 2 deletions src/main/kotlin/com/abmo/util/Extensions.kt
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ fun Any.toJson(): String = Gson().toJson(this)
*
* @return The parsed `Document` object representing the HTML content.
* @throws IllegalArgumentException if the URL is malformed or cannot be accessed.
* @throws IOException if an I/O error occurs while attempting to retrieve the document.
* @throws Exception if an I/O error occurs while attempting to retrieve the document.
*/
fun String.fetchDocument(): Document = Jsoup.connect(this).get()

Expand All @@ -32,7 +32,7 @@ fun String.toJsoupDocument(): Document = Jsoup.parse(this)
* @return The corresponding value as a String, or null if not found.
*/
fun String.findValueByKey(key: String): String? {
val regex = """"$key"\s*:\s*("(?:[^"\\]*(?:\\.[^"\\]*)*)"|[^\s,}]+)""".toRegex()
val regex = """"$key"\s*:\s*("[^"\\]*(?:\\.[^"\\]*)*"|[^\s,}]+)""".toRegex()
val matchResult = regex.find(this)
return matchResult?.groupValues?.get(1)?.let {
if (it.startsWith("\"") && it.endsWith("\"")) {
Expand Down

0 comments on commit 319b7b3

Please sign in to comment.