Skip to content
This repository was archived by the owner on May 1, 2024. It is now read-only.

Commit 09f93fa

Browse files
committed
Update to 0.0.5 --
Changelog: - Add HTTP 403 Error Code Testing
1 parent 73d2d2e commit 09f93fa

File tree

4 files changed

+42
-14
lines changed

4 files changed

+42
-14
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ Then, add dependencies in app level build.gradle:
3636

3737
```kotlin
3838
dependencies {
39-
implementation 'com.github.maxrave-dev:kotlin-youtubeExtractor:0.0.4'
39+
implementation 'com.github.maxrave-dev:kotlin-youtubeExtractor:0.0.5'
4040
}
4141
```
4242

app/build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@ plugins {
55

66
android {
77
namespace 'com.maxrave.exampleApp'
8-
compileSdk 33
8+
compileSdk 34
99

1010
defaultConfig {
1111
applicationId "com.maxrave.exampleApp"
1212
minSdk 24
13-
targetSdk 33
13+
targetSdk 34
1414
versionCode 1
1515
versionName "1.0"
1616

kotlinYoutubeExtractor/build.gradle

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,15 @@ plugins {
44
id 'maven-publish'
55
}
66
group = 'com.github.maxrave-dev'
7-
version = '0.0.4'
7+
version = '0.0.5'
88

99
android {
1010
namespace 'com.maxrave.kotlinyoutubeextractor'
11-
compileSdk 33
11+
compileSdk 34
1212

1313
defaultConfig {
1414
minSdk 24
15-
targetSdk 33
15+
targetSdk 34
1616
versionCode 1
1717
versionName "1.0"
1818

@@ -59,7 +59,7 @@ afterEvaluate {
5959
from components.release
6060
groupId = 'com.github.maxrave-dev'
6161
artifactId = 'kotlin-youtubeExtractor'
62-
version = '0.0.4'
62+
version = '0.0.5'
6363
}
6464
}
6565
}

kotlinYoutubeExtractor/src/main/java/com/maxrave/kotlinyoutubeextractor/YTExtractor.kt

Lines changed: 35 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,10 @@ import android.os.Handler
55
import android.os.Looper
66
import android.util.Log
77
import android.util.SparseArray
8-
import androidx.core.util.forEach
98
import com.evgenii.jsevaluator.JsEvaluator
109
import com.evgenii.jsevaluator.interfaces.JsCallback
11-
import kotlinx.coroutines.CoroutineName
12-
import kotlinx.coroutines.CoroutineScope
1310
import kotlinx.coroutines.DelicateCoroutinesApi
1411
import kotlinx.coroutines.Dispatchers
15-
import kotlinx.coroutines.GlobalScope
16-
import kotlinx.coroutines.Job
17-
import kotlinx.coroutines.SupervisorJob
1812
import kotlinx.coroutines.async
1913
import kotlinx.coroutines.withContext
2014
import org.json.JSONException
@@ -371,6 +365,25 @@ class YTExtractor(val con: Context, val CACHING: Boolean = false, val LOGGING: B
371365
return ytFiles
372366
}
373367

368+
private fun testHttp403Code(url: String?): Boolean {
369+
var urlConnection: HttpURLConnection? = null
370+
try {
371+
val urlObj = URL(url)
372+
urlConnection = urlObj.openConnection() as HttpURLConnection
373+
urlConnection.setRequestProperty("User-Agent", USER_AGENT)
374+
urlConnection.connect()
375+
val responseCode = urlConnection.responseCode
376+
if (responseCode == 403) {
377+
return true
378+
}
379+
} catch (e: Exception) {
380+
e.printStackTrace()
381+
} finally {
382+
urlConnection?.disconnect()
383+
}
384+
return false
385+
}
386+
374387
@Throws(IOException::class)
375388
private fun decipherSignature(encSignatures: SparseArray<String>): Boolean {
376389
// Assume the functions don't change that much
@@ -623,7 +636,22 @@ class YTExtractor(val con: Context, val CACHING: Boolean = false, val LOGGING: B
623636
if (videoID != null) {
624637
try {
625638
state = State.SUCCESS
626-
return@async getStreamUrls()
639+
val temp = getStreamUrls()
640+
try {
641+
if (temp != null) {
642+
if (!testHttp403Code(temp.getAudioOnly().bestQuality()?.url)) {
643+
if (LOGGING) Log.d(
644+
LOG_TAG,
645+
"NO Error"
646+
)
647+
return@async getStreamUrls()
648+
}
649+
}
650+
}
651+
catch (e: java.lang.Exception){
652+
state = State.ERROR
653+
Log.e(LOG_TAG, "Extraction failed cause 403 HTTP Error", e)
654+
}
627655
} catch (e: java.lang.Exception) {
628656
state = State.ERROR
629657
Log.e(LOG_TAG, "Extraction failed", e)

0 commit comments

Comments
 (0)