Skip to content
This repository was archived by the owner on Oct 28, 2023. It is now read-only.

Migrated to androidX and fixed null ytFile for adaptiveFormats #223

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions advancedDownloader/build.gradle
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
apply plugin: 'com.android.application'

android {
compileSdkVersion 28
compileSdkVersion 32

defaultConfig {
applicationId "at.huber.youtubeDownloader"
minSdkVersion 14
targetSdkVersion 22
targetSdkVersion 32
versionCode 5
versionName "2.1"
}
Expand Down
3 changes: 2 additions & 1 deletion advancedDownloader/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@
android:name=".DownloadActivity"
android:theme="@style/AppTheme"
android:excludeFromRecents="true"
android:taskAffinity="">
android:taskAffinity=""
android:exported="false">

<intent-filter>
<action android:name="android.intent.action.SEND" />
Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ buildscript {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.6.2'
classpath 'com.android.tools.build:gradle:7.1.3'

// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
Expand Down
2 changes: 2 additions & 0 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
android.enableJetifier=true
android.useAndroidX=true
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-5.6.4-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-7.2-all.zip
4 changes: 2 additions & 2 deletions sampleApp/build.gradle
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
apply plugin: 'com.android.application'

android {
compileSdkVersion 28
compileSdkVersion 32

defaultConfig {
applicationId "at.huber.sampleDownload"
minSdkVersion 14
//noinspection ExpiredTargetSdkVersion
targetSdkVersion 22
targetSdkVersion 32
versionCode 2
versionName "2.1"
}
Expand Down
3 changes: 2 additions & 1 deletion sampleApp/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
android:name=".SampleDownloadActivity"
android:excludeFromRecents="true"
android:taskAffinity=""
android:theme="@style/AppTheme">
android:theme="@style/AppTheme"
android:exported="false">
<intent-filter>
<action android:name="android.intent.action.SEND" />
<category android:name="android.intent.category.DEFAULT" />
Expand Down
16 changes: 7 additions & 9 deletions youtubeExtractor/build.gradle
Original file line number Diff line number Diff line change
@@ -1,23 +1,21 @@
apply plugin: 'com.android.library'

android {
compileSdkVersion 28
compileSdkVersion 32

defaultConfig {
minSdkVersion 14
targetSdkVersion 28
versionCode 2
versionName "2.1"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
targetSdkVersion 32
testInstrumentationRunner 'androidx.test.runner.AndroidJUnitRunner'
}
}

dependencies {
implementation('com.github.evgenyneu:js-evaluator-for-android:v4.0.0') {
implementation('com.github.evgenyneu:js-evaluator-for-android:v5.0.0') {
exclude module: 'appcompat-v7'
}
implementation 'com.android.support:support-annotations:28.0.0'
implementation 'androidx.annotation:annotation:1.3.0'

androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test:rules:1.0.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
androidTestImplementation 'androidx.test:rules:1.4.0'
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

import android.os.Handler;
import android.os.Looper;
import android.support.test.InstrumentationRegistry;
import android.support.test.filters.FlakyTest;
import android.support.test.runner.AndroidJUnit4;
import androidx.test.platform.app.InstrumentationRegistry;
import androidx.test.filters.FlakyTest;
import androidx.test.ext.junit.runners.AndroidJUnit4;
import android.util.Log;
import android.util.SparseArray;

Expand All @@ -17,7 +17,7 @@
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;

import static android.support.test.InstrumentationRegistry.getInstrumentation;
import static androidx.test.platform.app.InstrumentationRegistry.getInstrumentation;
import static junit.framework.TestCase.assertEquals;
import static junit.framework.TestCase.assertNotNull;
import static junit.framework.TestCase.assertNotSame;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -227,62 +227,66 @@ private SparseArray<YtFile> getStreamUrls() throws IOException, InterruptedExcep
JSONObject ytPlayerResponse = new JSONObject(mat.group(1));
JSONObject streamingData = ytPlayerResponse.getJSONObject("streamingData");

JSONArray formats = streamingData.getJSONArray("formats");
for (int i = 0; i < formats.length(); i++) {

JSONObject format = formats.getJSONObject(i);

// FORMAT_STREAM_TYPE_OTF(otf=1) requires downloading the init fragment (adding
// `&sq=0` to the URL) and parsing emsg box to determine the number of fragment that
// would subsequently requested with (`&sq=N`) (cf. youtube-dl)
String type = format.optString("type");
if (type != null && type.equals("FORMAT_STREAM_TYPE_OTF"))
continue;

int itag = format.getInt("itag");

if (FORMAT_MAP.get(itag) != null) {
if (format.has("url")) {
String url = format.getString("url").replace("\\u0026", "&");
ytFiles.append(itag, new YtFile(FORMAT_MAP.get(itag), url));
} else if (format.has("signatureCipher")) {

mat = patSigEncUrl.matcher(format.getString("signatureCipher"));
Matcher matSig = patSignature.matcher(format.getString("signatureCipher"));
if (mat.find() && matSig.find()) {
String url = URLDecoder.decode(mat.group(1), "UTF-8");
String signature = URLDecoder.decode(matSig.group(1), "UTF-8");
if (streamingData.has("formats")) {
JSONArray formats = streamingData.getJSONArray("formats");
for (int i = 0; i < formats.length(); i++) {

JSONObject format = formats.getJSONObject(i);

// FORMAT_STREAM_TYPE_OTF(otf=1) requires downloading the init fragment (adding
// `&sq=0` to the URL) and parsing emsg box to determine the number of fragment that
// would subsequently requested with (`&sq=N`) (cf. youtube-dl)
String type = format.optString("type");
if (type != null && type.equals("FORMAT_STREAM_TYPE_OTF"))
continue;

int itag = format.getInt("itag");

if (FORMAT_MAP.get(itag) != null) {
if (format.has("url")) {
String url = format.getString("url").replace("\\u0026", "&");
ytFiles.append(itag, new YtFile(FORMAT_MAP.get(itag), url));
encSignatures.append(itag, signature);
} else if (format.has("signatureCipher")) {

mat = patSigEncUrl.matcher(format.getString("signatureCipher"));
Matcher matSig = patSignature.matcher(format.getString("signatureCipher"));
if (mat.find() && matSig.find()) {
String url = URLDecoder.decode(mat.group(1), "UTF-8");
String signature = URLDecoder.decode(matSig.group(1), "UTF-8");
ytFiles.append(itag, new YtFile(FORMAT_MAP.get(itag), url));
encSignatures.append(itag, signature);
}
}
}
}
}

JSONArray adaptiveFormats = streamingData.getJSONArray("adaptiveFormats");
for (int i = 0; i < adaptiveFormats.length(); i++) {

JSONObject adaptiveFormat = adaptiveFormats.getJSONObject(i);
if (streamingData.has("adaptiveFormats")) {
JSONArray adaptiveFormats = streamingData.getJSONArray("adaptiveFormats");
for (int i = 0; i < adaptiveFormats.length(); i++) {

String type = adaptiveFormat.optString("type");
if (type != null && type.equals("FORMAT_STREAM_TYPE_OTF"))
continue;
JSONObject adaptiveFormat = adaptiveFormats.getJSONObject(i);

int itag = adaptiveFormat.getInt("itag");
String type = adaptiveFormat.optString("type");
if (type != null && type.equals("FORMAT_STREAM_TYPE_OTF"))
continue;

if (FORMAT_MAP.get(itag) != null) {
if (adaptiveFormat.has("url")) {
String url = adaptiveFormat.getString("url").replace("\\u0026", "&");
ytFiles.append(itag, new YtFile(FORMAT_MAP.get(itag), url));
} else if (adaptiveFormat.has("signatureCipher")) {
int itag = adaptiveFormat.getInt("itag");

mat = patSigEncUrl.matcher(adaptiveFormat.getString("signatureCipher"));
Matcher matSig = patSignature.matcher(adaptiveFormat.getString("signatureCipher"));
if (mat.find() && matSig.find()) {
String url = URLDecoder.decode(mat.group(1), "UTF-8");
String signature = URLDecoder.decode(matSig.group(1), "UTF-8");
if (FORMAT_MAP.get(itag) != null) {
if (adaptiveFormat.has("url")) {
String url = adaptiveFormat.getString("url").replace("\\u0026", "&");
ytFiles.append(itag, new YtFile(FORMAT_MAP.get(itag), url));
encSignatures.append(itag, signature);
} else if (adaptiveFormat.has("signatureCipher")) {

mat = patSigEncUrl.matcher(adaptiveFormat.getString("signatureCipher"));
Matcher matSig = patSignature.matcher(adaptiveFormat.getString("signatureCipher"));
if (mat.find() && matSig.find()) {
String url = URLDecoder.decode(mat.group(1), "UTF-8");
String signature = URLDecoder.decode(matSig.group(1), "UTF-8");
ytFiles.append(itag, new YtFile(FORMAT_MAP.get(itag), url));
encSignatures.append(itag, signature);
}
}
}
}
Expand Down