@@ -20,6 +20,8 @@ import com.github.libretube.api.obj.StreamItem.Companion.TYPE_PLAYLIST
20
20
import com.github.libretube.api.obj.StreamItem.Companion.TYPE_STREAM
21
21
import com.github.libretube.api.obj.Streams
22
22
import com.github.libretube.api.obj.Subtitle
23
+ import com.github.libretube.extensions.parallelMap
24
+ import com.github.libretube.extensions.sha256Sum
23
25
import com.github.libretube.extensions.toID
24
26
import com.github.libretube.helpers.NewPipeExtractorInstance
25
27
import com.github.libretube.helpers.PlayerHelper
@@ -321,13 +323,32 @@ class NewPipeMediaServiceRepository : MediaServiceRepository {
321
323
}
322
324
323
325
override suspend fun getSegments (
324
- videoId : String ,
325
- category : String ,
326
- actionType : String?
327
- ): SegmentData = SegmentData ()
326
+ videoId : String , category : List <String >, actionType : List <String >?
327
+ ): SegmentData = RetrofitInstance .externalApi.getSegments(
328
+ // use hashed video id for privacy
329
+ // https://wiki.sponsor.ajay.app/w/API_Docs#GET_/api/skipSegments/:sha256HashPrefix
330
+ videoId.sha256Sum().substring(0 , 4 ), category, actionType
331
+ ).first { it.videoID == videoId }
328
332
329
333
override suspend fun getDeArrowContent (videoIds : String ): Map <String , DeArrowContent > =
330
- emptyMap()
334
+ videoIds.split(' ,' ).chunked(25 ).flatMap {
335
+ it.parallelMap { videoId ->
336
+ runCatching {
337
+ RetrofitInstance .externalApi.getDeArrowContent(
338
+ // use hashed video id for privacy
339
+ // https://wiki.sponsor.ajay.app/w/API_Docs/DeArrow#GET_/api/branding/:sha256HashPrefix
340
+ videoId.sha256Sum().substring(0 , 4 )
341
+ )
342
+ }.getOrNull()
343
+ }
344
+ }.filterNotNull().reduce { acc, map -> acc + map }.mapValues { (videoId, value) ->
345
+ value.copy(
346
+ thumbnails = value.thumbnails.map { thumbnail ->
347
+ thumbnail.takeIf { it.original } ? : thumbnail.copy(
348
+ thumbnail = " ${DEARROW_THUMBNAIL_URL } ?videoID=$videoId &time=${thumbnail.timestamp} "
349
+ )
350
+ })
351
+ }
331
352
332
353
override suspend fun getSearchResults (searchQuery : String , filter : String ): SearchResult {
333
354
val queryHandler = NewPipeExtractorInstance .extractor.searchQHFactory.fromQuery(
@@ -481,4 +502,8 @@ class NewPipeMediaServiceRepository : MediaServiceRepository {
481
502
comments = commentsInfo.items.map { it.toComment() }
482
503
)
483
504
}
505
+
506
+ companion object {
507
+ private const val DEARROW_THUMBNAIL_URL = " https://dearrow-thumb.ajay.app/api/v1/getThumbnail"
508
+ }
484
509
}
0 commit comments