Skip to content

Commit

Permalink
fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
antonyhaman committed Mar 21, 2021
1 parent e769069 commit 1be7bd1
Show file tree
Hide file tree
Showing 212 changed files with 6,452 additions and 145 deletions.
5 changes: 4 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
ext.kotlin_version = '1.4.30'
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.6.1'
classpath 'com.android.tools.build:gradle:4.1.2'
classpath 'com.neenbedankt.gradle.plugins:android-apt:1.8'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}

Expand Down
4 changes: 2 additions & 2 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#Fri Jun 07 13:52:28 EEST 2019
#Fri Feb 05 23:03:57 EET 2021
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-6.5-all.zip
17 changes: 13 additions & 4 deletions youtubejextractor/build.gradle
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
apply plugin: 'com.android.library'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'

allprojects {
repositories {
Expand All @@ -7,12 +9,12 @@ allprojects {
}

android {
compileSdkVersion 29
compileSdkVersion 30
defaultConfig {
minSdkVersion 19
targetSdkVersion 29
versionCode 5
versionName "0.3.0"
targetSdkVersion 30
versionCode 6
versionName "0.3.3"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
lintOptions {
Expand Down Expand Up @@ -43,6 +45,9 @@ dependencies {
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'

implementation 'com.hannesdorfmann.parcelableplease:annotation:1.0.2'
annotationProcessor 'com.hannesdorfmann.parcelableplease:processor:1.0.2'

// Retrofit
implementation 'com.squareup.retrofit2:retrofit:2.7.2'
implementation 'com.squareup.retrofit2:converter-gson:2.7.2'
Expand All @@ -58,4 +63,8 @@ dependencies {
implementation 'org.mozilla:rhino:1.7.10'

implementation 'javax.xml.bind:jaxb-api:2.3.1'
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
}
repositories {
mavenCentral()
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@
import android.support.test.runner.AndroidJUnit4;

import com.github.kotvertolet.youtubejextractor.exception.ExtractionException;
import com.github.kotvertolet.youtubejextractor.exception.VideoIsUnavailable;
import com.github.kotvertolet.youtubejextractor.exception.YoutubeRequestException;
import com.github.kotvertolet.youtubejextractor.models.AdaptiveAudioStream;
import com.github.kotvertolet.youtubejextractor.models.AdaptiveVideoStream;
import com.github.kotvertolet.youtubejextractor.models.newModels.VideoPlayerConfig;
import com.github.kotvertolet.youtubejextractor.models.subtitles.Subtitle;
import com.github.kotvertolet.youtubejextractor.models.youtube.playerResponse.MuxedStream;
import com.github.kotvertolet.youtubejextractor.models.youtube.videoData.YoutubeVideoData;
Expand Down Expand Up @@ -34,15 +36,15 @@
public class ExtractionTests extends TestCase {
private YoutubeJExtractor youtubeJExtractor = new YoutubeJExtractor();
private YoutubeNetwork youtubeNetwork = new YoutubeNetwork(new GsonBuilder().create());
private YoutubeVideoData videoData;
private VideoPlayerConfig videoData;

@Test(expected = ExtractionException.class)
public void checkInvalidVideoId() throws YoutubeRequestException, ExtractionException {
@Test(expected = VideoIsUnavailable.class)
public void checkInvalidVideoId() throws YoutubeRequestException, ExtractionException, VideoIsUnavailable {
youtubeJExtractor.extract("invalid_id");
}

@Test
public void checkVideoDataParcel() throws YoutubeRequestException, ExtractionException {
public void checkVideoDataParcel() throws YoutubeRequestException, ExtractionException, VideoIsUnavailable {
String parcelKey = "parcel_key1";
videoData = youtubeJExtractor.extract("rkas-NHQnsI");
Bundle bundle = new Bundle();
Expand All @@ -51,56 +53,57 @@ public void checkVideoDataParcel() throws YoutubeRequestException, ExtractionExc
}

@Test
public void checkVideoWithEncryptedSignature() throws ExtractionException, YoutubeRequestException {
videoData = youtubeJExtractor.extract("xRioA3a6qgg");
public void checkVideoWithEncryptedSignature() throws ExtractionException, YoutubeRequestException, VideoIsUnavailable {
//videoData = youtubeJExtractor.extract("07FYdnEawAQ"); // age restricted
videoData = youtubeJExtractor.extract("kcoisguyvEA");
checkIfStreamsWork(videoData);
}

@Test
public void checkVideoWithoutEncryptedSignature() throws ExtractionException, YoutubeRequestException {
public void checkVideoWithoutEncryptedSignature() throws ExtractionException, YoutubeRequestException, VideoIsUnavailable {
videoData = youtubeJExtractor.extract("jNQXAC9IVRw");
checkIfStreamsWork(videoData);
}

@Test
public void checkVideoWithAgeCheck() throws ExtractionException, YoutubeRequestException {
videoData = youtubeJExtractor.extract("Pk0z3Aj3P5E");
public void checkVideoWithAgeCheck() throws ExtractionException, YoutubeRequestException, VideoIsUnavailable {
videoData = youtubeJExtractor.extract("upvickWORPM");
checkIfStreamsWork(videoData);
}

@Test
public void checkVeryLongVideo() throws ExtractionException, YoutubeRequestException {
public void checkVeryLongVideo() throws ExtractionException, YoutubeRequestException, VideoIsUnavailable {
videoData = youtubeJExtractor.extract("85bkCmaOh4o");
checkIfStreamsWork(videoData);
}

@Test
public void checkVideoWithRestrictedEmbedding() throws ExtractionException, YoutubeRequestException {
public void checkVideoWithRestrictedEmbedding() throws ExtractionException, YoutubeRequestException, VideoIsUnavailable {
videoData = youtubeJExtractor.extract("XcicOBS9mBU");
checkIfStreamsWork(videoData);
}

@Test
public void checkLiveStream() throws YoutubeRequestException, ExtractionException {
public void checkLiveStream() throws YoutubeRequestException, ExtractionException, VideoIsUnavailable {
videoData = youtubeJExtractor.extract("5qap5aO4i9A");
assertTrue(videoData.getVideoDetails().isLiveContent());
assertNotNull(videoData.getStreamingData().getDashManifestUrl());
assertNotNull(videoData.getStreamingData().getHlsManifestUrl());
checkIfStreamsWork(videoData);
}

//@Test
public void checkLiveStreamWithoutAdaptiveStreams() throws YoutubeRequestException, ExtractionException {
videoData = youtubeJExtractor.extract("up0fWFqgC6g");
assertTrue(videoData.getVideoDetails().isLiveContent());
assertNotNull(videoData.getStreamingData().getDashManifestUrl());
assertNotNull(videoData.getStreamingData().getHlsManifestUrl());
assertEquals(0, videoData.getStreamingData().getAdaptiveAudioStreams().size());
assertEquals(0, videoData.getStreamingData().getAdaptiveVideoStreams().size());
}
// @Test
// public void checkLiveStreamWithoutAdaptiveStreams() throws YoutubeRequestException, ExtractionException, VideoIsUnavailable {
// videoData = youtubeJExtractor.extract("up0fWFqgC6g");
// assertTrue(videoData.getVideoDetails().isLiveContent());
// assertNotNull(videoData.getStreamingData().getDashManifestUrl());
// assertNotNull(videoData.getStreamingData().getHlsManifestUrl());
// assertEquals(0, videoData.getStreamingData().getAdaptiveAudioStreams().size());
// assertEquals(0, videoData.getStreamingData().getAdaptiveVideoStreams().size());
// }

@Test
public void checkMuxedStreamNonEncrypted() throws YoutubeRequestException, ExtractionException {
public void checkMuxedStreamNonEncrypted() throws YoutubeRequestException, ExtractionException, VideoIsUnavailable {
videoData = youtubeJExtractor.extract("8QyDmvuts9s");
checkIfStreamsWork(videoData);
}
Expand All @@ -109,7 +112,7 @@ public void checkMuxedStreamNonEncrypted() throws YoutubeRequestException, Extra
public void checkCallbackBasedExtractionSuccessful() {
youtubeJExtractor.extract("iIKxyDRjecU", new JExtractorCallback() {
@Override
public void onSuccess(YoutubeVideoData videoData) {
public void onSuccess(VideoPlayerConfig videoData) {
checkIfStreamsWork(videoData);
}

Expand Down Expand Up @@ -140,7 +143,7 @@ public void testSubtitlesExtraction() {
assertEquals(expectedLastLine, actualLasLine);
}

private void checkIfStreamsWork(YoutubeVideoData videoData) {
private void checkIfStreamsWork(VideoPlayerConfig videoData) {
String streamErrorMask = "Stream wasn't processed correctly, stream details:\\n %s";
Response<ResponseBody> responseBody;
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,13 @@
import com.github.kotvertolet.youtubejextractor.models.youtube.playerResponse.PlayerResponse;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.JsonDeserializationContext;
import com.google.gson.JsonDeserializer;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.JsonParseException;

import java.lang.reflect.Type;

import static com.github.kotvertolet.youtubejextractor.utils.StringUtils.urlDecode;

Expand All @@ -13,20 +19,17 @@ class IGsonFactoryImpl implements IGsonFactory {
@Override
public Gson initGson() {
GsonBuilder gsonBuilder = new GsonBuilder();
JsonDeserializer<Cipher> cipherDeserializer = (json, typeOfT, context) -> {
// JsonObject jsonObject = json.getAsJsonObject();
// String s = jsonObject.get("s").getAsString();
// String sp = jsonObject.get("sp").getAsString();
// String url = urlDecode(jsonObject.get("url").getAsString());
String[] arr = json.getAsString().split("&");
return new Cipher(arr[0].replace("s=", ""), arr[1].replace("sp=", ""), urlDecode(arr[2].replace("url=", "")));
};
JsonDeserializer<PlayerResponse> playerResponseJsonDeserializer = (json, typeOfT, context) -> {
Gson tempGson = new GsonBuilder().registerTypeAdapter(Cipher.class, cipherDeserializer).create();
String jsonRaw = json.getAsString();
return tempGson.fromJson(jsonRaw, PlayerResponse.class);
};
gsonBuilder.registerTypeAdapter(PlayerResponse.class, playerResponseJsonDeserializer);
gsonBuilder.registerTypeAdapter(Cipher.class, new CipherDeserializer());
return gsonBuilder.create();
}

private class CipherDeserializer implements JsonDeserializer<Cipher> {
@Override
public Cipher deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {
String[] arr = json.getAsString().split("&");
return new Cipher(arr[0].replace("s=", ""),
arr[1].replace("sp=", ""),
urlDecode(arr[2].replace("url=", "")));
}
}
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package com.github.kotvertolet.youtubejextractor;

import com.github.kotvertolet.youtubejextractor.exception.YoutubeRequestException;
import com.github.kotvertolet.youtubejextractor.models.youtube.videoData.YoutubeVideoData;
import com.github.kotvertolet.youtubejextractor.models.newModels.VideoPlayerConfig;

public interface JExtractorCallback {

void onSuccess(YoutubeVideoData videoData);
void onSuccess(VideoPlayerConfig videoData);

void onNetworkException(YoutubeRequestException e);

Expand Down
Loading

0 comments on commit 1be7bd1

Please sign in to comment.