forked from z-huang/InnerTune
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from gechoto/newpipe-deobfuscate
PR z-huang#1774
- Loading branch information
Showing
13 changed files
with
196 additions
and
57 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
53 changes: 53 additions & 0 deletions
53
innertube/src/main/java/com/zionhuang/innertube/NewPipeDownloaderImpl.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package com.zionhuang.innertube | ||
|
||
import com.zionhuang.innertube.models.YouTubeClient | ||
import okhttp3.OkHttpClient | ||
import okhttp3.RequestBody.Companion.toRequestBody | ||
import org.schabi.newpipe.extractor.downloader.Downloader | ||
import org.schabi.newpipe.extractor.downloader.Request | ||
import org.schabi.newpipe.extractor.downloader.Response | ||
import org.schabi.newpipe.extractor.exceptions.ReCaptchaException | ||
import java.io.IOException | ||
|
||
object NewPipeDownloaderImpl : Downloader() { | ||
|
||
private val client = OkHttpClient.Builder().build() | ||
|
||
@Throws(IOException::class, ReCaptchaException::class) | ||
override fun execute(request: Request): Response { | ||
val httpMethod = request.httpMethod() | ||
val url = request.url() | ||
val headers = request.headers() | ||
val dataToSend = request.dataToSend() | ||
|
||
val requestBuilder = okhttp3.Request.Builder() | ||
.method(httpMethod, dataToSend?.toRequestBody()) | ||
.url(url) | ||
.addHeader("User-Agent", YouTubeClient.USER_AGENT_WEB) | ||
|
||
headers.forEach { (headerName, headerValueList) -> | ||
if (headerValueList.size > 1) { | ||
requestBuilder.removeHeader(headerName) | ||
headerValueList.forEach { headerValue -> | ||
requestBuilder.addHeader(headerName, headerValue) | ||
} | ||
} else if (headerValueList.size == 1) { | ||
requestBuilder.header(headerName, headerValueList[0]) | ||
} | ||
} | ||
|
||
val response = client.newCall(requestBuilder.build()).execute() | ||
|
||
if (response.code == 429) { | ||
response.close() | ||
|
||
throw ReCaptchaException("reCaptcha Challenge requested", url) | ||
} | ||
|
||
val responseBodyToReturn = response.body?.string() | ||
|
||
val latestUrl = response.request.url.toString() | ||
return Response(response.code, response.message, response.headers.toMultimap(), responseBodyToReturn, latestUrl) | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.