Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[YouTube] Parse and execute deobfuscation code without JavaScript #529

Closed
wants to merge 1 commit into from

Conversation

Stypox
Copy link
Member

@Stypox Stypox commented Jan 28, 2021

  • I carefully read the contribution guidelines and agree to them.
  • I have tested the API against NewPipe.
  • [not needed] I agree to create a pull request for NewPipe as soon as possible to make it compatible with the changed API.

See #520 (comment)

I don't know if this can be merged safely, it is more of an experiment. @FireMasterK

This is the JS this PR parses, which is built by loadDeobfuscationCode():

var Aw = {
	bQ: function(a,b) {
		var c = a[0];
		a[0] = a[b%a.length];
		a[b%a.length] = c
	},
	RY: function(a) {
		a.reverse()
	},
	aD: function(a,b) {
		a.splice(0,b)
	}
};
var Bw = function(a) {
	a = a.split("");
	Aw.bQ(a,35);
	Aw.aD(a,3);
	Aw.RY(a,30);
	Aw.bQ(a,44);
	Aw.aD(a,1);
	return a.join("")
};

Debug APK: app-debug.zip

@FireMasterK
Copy link
Member

There's a strange unrelated error when I try that apk:

Exception

  • User Action: searched
  • Request: test
  • Content Country: IN
  • Content Language: en-IN
  • App Language: en_IN
  • Service: YouTube
  • Version: 0.20.8
  • OS: Linux Android 10 - 29
Crash log

java.lang.RuntimeException: This is a runtime error, k = 29
	at org.schabi.newpipe.DownloaderImpl.execute(DownloaderImpl.java:235)
	at org.schabi.newpipe.extractor.downloader.Downloader.get(Downloader.java:70)
	at org.schabi.newpipe.extractor.services.youtube.YoutubeParsingHelper.getJsonResponse(YoutubeParsingHelper.java:605)
	at org.schabi.newpipe.extractor.services.youtube.extractors.YoutubeSearchExtractor.onFetchPage(YoutubeSearchExtractor.java:66)
	at org.schabi.newpipe.extractor.Extractor.fetchPage(Extractor.java:54)
	at org.schabi.newpipe.extractor.search.SearchInfo.getInfo(SearchInfo.java:29)
	at org.schabi.newpipe.util.ExtractorHelper.lambda$searchFor$0(ExtractorHelper.java:80)
	at org.schabi.newpipe.util.-$$Lambda$ExtractorHelper$qyxpuXgomWa-cbONQns-pd7zxm0.call(Unknown Source:8)
	at io.reactivex.rxjava3.internal.operators.single.SingleFromCallable.subscribeActual(SingleFromCallable.java:43)
	at io.reactivex.rxjava3.core.Single.subscribe(Single.java:4813)
	at io.reactivex.rxjava3.internal.operators.single.SingleSubscribeOn$SubscribeOnObserver.run(SingleSubscribeOn.java:89)
	at io.reactivex.rxjava3.core.Scheduler$DisposeTask.run(Scheduler.java:614)
	at io.reactivex.rxjava3.internal.schedulers.ScheduledRunnable.run(ScheduledRunnable.java:65)
	at io.reactivex.rxjava3.internal.schedulers.ScheduledRunnable.call(ScheduledRunnable.java:56)
	at java.util.concurrent.FutureTask.run(FutureTask.java:266)
	at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:301)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
	at java.lang.Thread.run(Thread.java:919)


The implementation code wise seems to be good. (From a glance)

@Stypox
Copy link
Member Author

Stypox commented Jan 28, 2021

@FireMasterK oh, I uploaded the wrong apk, sorry. I updated it now.

@FireMasterK
Copy link
Member

It works great! It also appears that it might also decipher these videos faster too. (Likely due to not needing to recreate a script context everytime.)

@Stypox
Copy link
Member Author

Stypox commented Jan 28, 2021

It works great! It also appears that it might also decipher these videos faster too. (Likely due to not needing to recreate a script context everytime.)

Yeah, that's the whole point :-D

@FireMasterK
Copy link
Member

I just want to add, Invidious does this already so I think it should be safe to merge
See: https://github.com/iv-org/invidious/blob/master/src/invidious/helpers/signatures.cr

@XiangRongLin
Copy link
Collaborator

@Stypox can you rebase and see if the test pass?

@Stypox
Copy link
Member Author

Stypox commented Feb 16, 2021

@XiangRongLin it passed! The stream urls could still lead to 404 errors due to a wrong deobfuscation, since that's not tested, but the deobfuscation process would have probably raised an IndexOutOfBound exception at some point if something was wrong. So I think everything is fine.

@XiangRongLin
Copy link
Collaborator

I'm going to use the app with this extractor for the next few days. If nothing comes app, it can be merged

@FireMasterK
Copy link
Member

YouTube has already updated their deobfuscation code once since this PR was opened, it should be safe imo if it still works :D

final String[] stringSteps = deobfuscationCode.split(containerName + "\\.");
boolean first = true;
cachedDeobfuscationFunctions = new ArrayList<>();
for (final String step : stringSteps) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since this is an array you can just use a for i loop with i=1 instead of the weird first=true setup

@XiangRongLin
Copy link
Collaborator

XiangRongLin commented Feb 23, 2021

This occured in my preunified version with this extractor. I searched for the video and clicked on it. then the error came.

it works on my preunified with extractor v0.20.10 and yesterday it worked too on deobf extractor

Exception

Crash log

org.schabi.newpipe.extractor.stream.StreamInfo$StreamExtractException: Could not get any stream. See error variable to get further details.
	at org.schabi.newpipe.extractor.stream.StreamInfo.extractStreams(StreamInfo.java:194)
	at org.schabi.newpipe.extractor.stream.StreamInfo.getInfo(StreamInfo.java:72)
	at org.schabi.newpipe.extractor.stream.StreamInfo.getInfo(StreamInfo.java:64)
	at org.schabi.newpipe.util.ExtractorHelper.lambda$getStreamInfo$3(ExtractorHelper.java:116)
	at org.schabi.newpipe.util.-$$Lambda$ExtractorHelper$YTHJjScxCJNO1LTCqs3IKy35iyY.call(Unknown Source:4)
	at io.reactivex.internal.operators.single.SingleFromCallable.subscribeActual(SingleFromCallable.java:44)
	at io.reactivex.Single.subscribe(Single.java:3666)
	at io.reactivex.internal.operators.single.SingleDoOnSuccess.subscribeActual(SingleDoOnSuccess.java:35)
	at io.reactivex.Single.subscribe(Single.java:3666)
	at io.reactivex.internal.operators.maybe.MaybeFromSingle.subscribeActual(MaybeFromSingle.java:41)
	at io.reactivex.Maybe.subscribe(Maybe.java:4290)
	at io.reactivex.internal.operators.maybe.MaybeConcatArray$ConcatMaybeObserver.drain(MaybeConcatArray.java:153)
	at io.reactivex.internal.operators.maybe.MaybeConcatArray$ConcatMaybeObserver.request(MaybeConcatArray.java:78)
	at io.reactivex.internal.operators.flowable.FlowableElementAtMaybe$ElementAtSubscriber.onSubscribe(FlowableElementAtMaybe.java:66)
	at io.reactivex.internal.operators.maybe.MaybeConcatArray.subscribeActual(MaybeConcatArray.java:42)
	at io.reactivex.Flowable.subscribe(Flowable.java:14935)
	at io.reactivex.internal.operators.flowable.FlowableElementAtMaybe.subscribeActual(FlowableElementAtMaybe.java:36)
	at io.reactivex.Maybe.subscribe(Maybe.java:4290)
	at io.reactivex.internal.operators.maybe.MaybeToSingle.subscribeActual(MaybeToSingle.java:46)
	at io.reactivex.Single.subscribe(Single.java:3666)
	at io.reactivex.internal.operators.single.SingleSubscribeOn$SubscribeOnObserver.run(SingleSubscribeOn.java:89)
	at io.reactivex.Scheduler$DisposeTask.run(Scheduler.java:578)
	at io.reactivex.internal.schedulers.ScheduledRunnable.run(ScheduledRunnable.java:66)
	at io.reactivex.internal.schedulers.ScheduledRunnable.call(ScheduledRunnable.java:57)
	at java.util.concurrent.FutureTask.run(FutureTask.java:266)
	at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:301)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
	at java.lang.Thread.run(Thread.java:923)


@XiangRongLin
Copy link
Collaborator

XiangRongLin commented Feb 23, 2021

this one too https://www.youtube.com/watch?v=WDH_nJM3djc.

Search query: summer joe

Other videos work, as far as i tried

Edit: Now it's working again

@FireMasterK
Copy link
Member

This will become redundant if we implement #562

@AudricV AudricV added enhancement New feature or request youtube service, https://www.youtube.com/ labels Mar 5, 2021
@Stypox Stypox closed this Sep 3, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request youtube service, https://www.youtube.com/
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants