Skip to content

Commit

Permalink
Fix for #22, cipher param renamed to match youtube data format
Browse files Browse the repository at this point in the history
  • Loading branch information
antonyhaman committed Jun 1, 2020
1 parent d3cb8b8 commit f344825
Show file tree
Hide file tree
Showing 63 changed files with 188 additions and 100 deletions.
8 changes: 4 additions & 4 deletions youtubejextractor/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ android {
defaultConfig {
minSdkVersion 19
targetSdkVersion 29
versionCode 1
versionCode 2
versionName "0.2.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
Expand All @@ -15,12 +15,12 @@ android {

buildTypes {
release {
minifyEnabled false
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
consumerProguardFiles 'proguard-rules.pro'
}
debug {
testCoverageEnabled false
testCoverageEnabled true
minifyEnabled false
}
}
Expand All @@ -40,7 +40,7 @@ dependencies {
// Retrofit
implementation 'com.squareup.retrofit2:retrofit:2.7.2'
implementation 'com.squareup.retrofit2:converter-gson:2.7.2'
implementation 'com.squareup.okhttp3:logging-interceptor:3.8.0'
implementation 'com.squareup.okhttp3:logging-interceptor:3.12.2'

// Gson
implementation 'com.google.code.gson:gson:2.8.6'
Expand Down
14 changes: 4 additions & 10 deletions youtubejextractor/proguard-rules.pro
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@
-printmapping out.map
-keepparameternames
-renamesourcefileattribute SourceFile
-keepattributes Exceptions,InnerClasses,Signature,Deprecated,
SourceFile,LineNumberTable,EnclosingMethod
-keepattributes Exceptions,InnerClasses,Signature,Deprecated,SourceFile,LineNumberTable,EnclosingMethod

# Preserve all annotations.

Expand Down Expand Up @@ -47,18 +46,13 @@
# If your code contains serializable classes that have to be backward
# compatible, please refer to the manual.

-keep class * implements java.io.Serializable

-keepclassmembers class * implements java.io.Serializable {
static final long serialVersionUID;
static final java.io.ObjectStreamField[] serialPersistentFields;
private void writeObject(java.io.ObjectOutputStream);
private void readObject(java.io.ObjectInputStream);
java.lang.Object writeReplace();
java.lang.Object readResolve();
}

# Your library may contain more items that need to be preserved;
# typically classes that are dynamically created using Class.forName:

# -keep public class mypackage.MyClass
# -keep public interface mypackage.MyInterface
# -keep public class * implements mypackage.MyInterface
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,7 @@
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.not;
import static org.hamcrest.Matchers.nullValue;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;

@RunWith(AndroidJUnit4.class)
public class ExtractionTests extends TestCase {
Expand Down Expand Up @@ -88,7 +85,7 @@ public void checkLiveStream() throws YoutubeRequestException, ExtractionExceptio
}

@Test
public void checkMuxedStreamNonEncrypted() throws YoutubeRequestException, ExtractionException {
public void checkMuxedStreamNonEncrypted() throws YoutubeRequestException, ExtractionException {
videoData = youtubeJExtractor.extract("8QyDmvuts9s");
checkIfStreamsWork(videoData);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,9 @@
import com.google.code.regexp.Pattern;
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.JsonParseException;

import java.io.IOException;
import java.lang.reflect.Type;
import java.net.URL;
import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -189,22 +185,16 @@ private void decryptYoutubeStreams(PlayerResponse youtubeVideoData) throws Extra

private Gson initGson() {
GsonBuilder gsonBuilder = new GsonBuilder();
JsonDeserializer<Cipher> cipherDeserializer = new JsonDeserializer<Cipher>() {
@Override
public Cipher deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {
Cipher cipher = gson.fromJson(urlParamsToJson(json.getAsString()), Cipher.class);
cipher.setUrl(urlDecode(cipher.getUrl()));
return cipher;
}
JsonDeserializer<Cipher> cipherDeserializer = (json, typeOfT, context) -> {
Cipher cipher = gson.fromJson(urlParamsToJson(json.getAsString()), Cipher.class);
cipher.setUrl(urlDecode(cipher.getUrl()));
return cipher;
};

JsonDeserializer<PlayerResponse> playerResponseJsonDeserializer = new JsonDeserializer<PlayerResponse>() {
@Override
public PlayerResponse deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {
Gson tempGson = new GsonBuilder().registerTypeAdapter(Cipher.class, cipherDeserializer).create();
String jsonRaw = json.getAsString();
return tempGson.fromJson(jsonRaw, PlayerResponse.class);
}
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);
return gsonBuilder.create();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@

import com.github.kotvertolet.youtubejextractor.models.youtube.playerResponse.AdaptiveStream;

public abstract class StreamItem implements Parcelable {
import java.io.Serializable;

public abstract class StreamItem implements Parcelable, Serializable {

protected String extension;
protected String codec;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
import com.github.kotvertolet.youtubejextractor.models.youtube.playerResponse.PlayerResponse;
import com.google.gson.annotations.SerializedName;

public class Args {
import java.io.Serializable;

public class Args implements Serializable {

@SerializedName("show_content_thumbnail")
private boolean showContentThumbnail;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

import com.google.gson.annotations.SerializedName;

public class Assets {
import java.io.Serializable;

public class Assets implements Serializable {

@SerializedName("css")
private String css;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

import com.google.gson.annotations.SerializedName;

public class Attrs {
import java.io.Serializable;

public class Attrs implements Serializable {

@SerializedName("id")
private String id;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

import com.google.gson.annotations.SerializedName;

public class VideoPlayerConfig {
import java.io.Serializable;

public class VideoPlayerConfig implements Serializable {

@SerializedName("args")
private Args args;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package com.github.kotvertolet.youtubejextractor.models.youtube.playerResponse;

public class ActionButton {
import java.io.Serializable;

public class ActionButton implements Serializable {

private ButtonRenderer buttonRenderer;

public ButtonRenderer getButtonRenderer() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
package com.github.kotvertolet.youtubejextractor.models.youtube.playerResponse;

public class AdaptiveStream {
import com.google.gson.annotations.SerializedName;

import java.io.Serializable;

public class AdaptiveStream implements Serializable {

private int itag;
@SerializedName("signatureCipher")
private Cipher cipher;
private IndexRange indexRange;
private String projectionType;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package com.github.kotvertolet.youtubejextractor.models.youtube.playerResponse;

public class AtrUrl {
import java.io.Serializable;

public class AtrUrl implements Serializable {

private String baseUrl;
private int elapsedMediaTimeSeconds;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package com.github.kotvertolet.youtubejextractor.models.youtube.playerResponse;

public class Attestation {
import java.io.Serializable;

public class Attestation implements Serializable {

private PlayerAttestationRenderer playerAttestationRenderer;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package com.github.kotvertolet.youtubejextractor.models.youtube.playerResponse;

public class AudioConfig {
import java.io.Serializable;

public class AudioConfig implements Serializable {

private double perceptualLoudnessDb;
private double loudnessDb;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package com.github.kotvertolet.youtubejextractor.models.youtube.playerResponse;

public class BotguardData {
import java.io.Serializable;

public class BotguardData implements Serializable {

private String interpreterUrl;
private String program;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package com.github.kotvertolet.youtubejextractor.models.youtube.playerResponse;

public class ButtonRenderer {
import java.io.Serializable;

public class ButtonRenderer implements Serializable {

private String trackingParams;
private String size;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package com.github.kotvertolet.youtubejextractor.models.youtube.playerResponse;

import java.io.Serializable;

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

public class Cipher {
public class Cipher implements Serializable {

private String s;
private String sp;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package com.github.kotvertolet.youtubejextractor.models.youtube.playerResponse;

public class ColorInfo {
import java.io.Serializable;

public class ColorInfo implements Serializable {

private String primaries;
private String matrixCoefficients;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package com.github.kotvertolet.youtubejextractor.models.youtube.playerResponse;

public class Description {
import java.io.Serializable;

public class Description implements Serializable {

private String simpleText;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package com.github.kotvertolet.youtubejextractor.models.youtube.playerResponse;

public class DismissButton {
import java.io.Serializable;

public class DismissButton implements Serializable {

private ButtonRenderer buttonRenderer;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package com.github.kotvertolet.youtubejextractor.models.youtube.playerResponse;

public class DynamicReadaheadConfig {
import java.io.Serializable;

public class DynamicReadaheadConfig implements Serializable {

private int readAheadGrowthRateMs;
private int maxReadAheadMediaTimeMs;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package com.github.kotvertolet.youtubejextractor.models.youtube.playerResponse;

public class Embed {
import java.io.Serializable;

public class Embed implements Serializable {

private int width;
private String flashUrl;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package com.github.kotvertolet.youtubejextractor.models.youtube.playerResponse;

public class FeedbackEndpoint {
import java.io.Serializable;

public class FeedbackEndpoint implements Serializable {

private UiActions uiActions;
private String feedbackToken;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package com.github.kotvertolet.youtubejextractor.models.youtube.playerResponse;

public class ImpressionEndpointsItem {
import java.io.Serializable;

public class ImpressionEndpointsItem implements Serializable {

private FeedbackEndpoint feedbackEndpoint;
private String clickTrackingParams;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package com.github.kotvertolet.youtubejextractor.models.youtube.playerResponse;

public class IndexRange {
import java.io.Serializable;

public class IndexRange implements Serializable {

private String start;
private String end;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package com.github.kotvertolet.youtubejextractor.models.youtube.playerResponse;

public class InitRange {
import java.io.Serializable;

public class InitRange implements Serializable {

private String start;
private String end;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
package com.github.kotvertolet.youtubejextractor.models.youtube.playerResponse;

import java.io.Serializable;
import java.util.List;

public class MealbarPromoRenderer {
public class MealbarPromoRenderer implements Serializable {

private String triggerCondition;
private String trackingParams;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package com.github.kotvertolet.youtubejextractor.models.youtube.playerResponse;

public class MediaCommonConfig {
import java.io.Serializable;

public class MediaCommonConfig implements Serializable {

private DynamicReadaheadConfig dynamicReadaheadConfig;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
package com.github.kotvertolet.youtubejextractor.models.youtube.playerResponse;

import java.io.Serializable;
import java.util.List;

public class MessageTextsItem {
public class MessageTextsItem implements Serializable {

private List<RunsItem> runs;

Expand Down
Loading

0 comments on commit f344825

Please sign in to comment.