Skip to content

Commit

Permalink
get urls directly, see TeamNewPipe/NewPipeExtractor#562
Browse files Browse the repository at this point in the history
  • Loading branch information
kvnp committed Aug 11, 2021
1 parent 5c7e50f commit 3a6a7e8
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 169 deletions.
42 changes: 21 additions & 21 deletions react/modules/remote/API.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import {

import { settings } from "../../modules/storage/SettingsStorage";
import { getHttpResponse, getUrl } from "./HTTP";
import { enableDecryption, signatureTimestamp, isDecryptionWorking } from "./Decrypt";

export const headers_simple = {"User-Agent": "Mozilla/5.0 (X11; Linux x86_64; rv:79.0) Gecko/20100101 Firefox/79.0"};
const headers_ytm = {
Expand All @@ -37,13 +36,6 @@ async function getConfig(path) {

configuration = extractConfiguration(response);

let baseUrl = configuration
.WEB_PLAYER_CONTEXT_CONFIGS
.WEB_PLAYER_CONTEXT_CONFIG_ID_MUSIC_WATCH
.jsUrl

enableDecryption({baseUrl});

apiKey = configuration
.WEB_PLAYER_CONTEXT_CONFIGS
.WEB_PLAYER_CONTEXT_CONFIG_ID_MUSIC_WATCH
Expand All @@ -55,7 +47,25 @@ function getRequestBody() {
context: {
client: {
clientName: "WEB_REMIX",
clientVersion: "0.1",
clientVersion: "1.20210630.00.00"
}
}
};

if (settings.transmitLanguage) {
body.context.client["gl"] = getGL();
body.context.client["hl"] = getHL();
}

return body;
}

function getRequestBodyStream() {
let body = {
context: {
client: {
clientName: "ANDROID",
clientVersion: "16.02"
}
}
};
Expand Down Expand Up @@ -205,11 +215,6 @@ export async function fetchAudioInfo({videoId, playlistId, controllerCallback})
let body = getRequestBody();
body.context["user"] = { lockedSafetyMode: settings.safetyMode }
body["videoId"] = videoId;

if (!isDecryptionWorking())
await enableDecryption({videoId});

body["playbackContext"] = {contentPlaybackContext: {signatureTimestamp: signatureTimestamp}};

if (playlistId)
body["playlistId"] = playlistId;
Expand All @@ -226,17 +231,12 @@ export async function fetchAudioInfo({videoId, playlistId, controllerCallback})
}

export async function fetchAudioStream({videoId, controllerCallback}) {
let url = "https://music.youtube.com/youtubei/v1/player?key=" + apiKey;
let url = "https://youtubei.googleapis.com/youtubei/v1/player?key=" + apiKey;

let body = getRequestBody();
let body = getRequestBodyStream();
body.context["user"] = { lockedSafetyMode: settings.safetyMode }
body["videoId"] = videoId;

if (!isDecryptionWorking())
await enableDecryption({videoId});

body["playbackContext"] = {contentPlaybackContext: {signatureTimestamp: signatureTimestamp}};

let response = await getHttpResponse(url, {
method: "POST",
headers: headers_ytm,
Expand Down
127 changes: 0 additions & 127 deletions react/modules/remote/Decrypt.js

This file was deleted.

23 changes: 2 additions & 21 deletions react/modules/remote/Extractor.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import { msToMin, msToMMSS, textToSec } from "../utils/Time";
import Track from "../models/music/track";
import Playlist from "../models/music/playlist";
import { decodeNestedURI } from "../utils/Decoder";
import { getSignature } from "./Decrypt";
import { hackTracks } from "../../components/collections/FlatEntries";

export function extractConfiguration(html) {
Expand Down Expand Up @@ -688,26 +686,9 @@ export function digestBrowseResults(json, browseId) {
}

export async function digestStreams(parse) {
let videoId = parse.videoDetails.videoId;

for (let i = 0; i < parse.streamingData.adaptiveFormats.length; i++) {
if (parse.streamingData.adaptiveFormats[i].mimeType.split("/")[0] == "audio") {
if (parse.streamingData.adaptiveFormats[i].signatureCipher) {
let signatureCipher = parse.streamingData.adaptiveFormats[i].signatureCipher;

let sigArray = decodeNestedURI(signatureCipher).split("&");
let stream = sigArray[2].slice(4);
let s = await getSignature(videoId, sigArray[0].substring(2));

for (let j = 0; j < sigArray.length; j++)
if (j != 0 & j != 2)
stream += "&" + sigArray[j];

stream += "&sig=" + s;
return stream;
} else
return parse.streamingData.adaptiveFormats[i].url;
}
if (parse.streamingData.adaptiveFormats[i].mimeType.split("/")[0] == "audio")
return parse.streamingData.adaptiveFormats[i].url;
}
}

Expand Down

0 comments on commit 3a6a7e8

Please sign in to comment.