Skip to content

Commit

Permalink
Added methods to override in subclass
Browse files Browse the repository at this point in the history
  • Loading branch information
Victor Oomens committed Aug 24, 2022
1 parent c9044ef commit d59faf7
Showing 1 changed file with 21 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,6 @@

public abstract class YouTubeExtractor extends AsyncTask<String, Void, SparseArray<YtFile>> {

static boolean CACHING = true;
static boolean LOGGING = false;

private final static String LOG_TAG = "YouTubeExtractor";
private final static String CACHE_FILE_NAME = "decipher_js_funct";

Expand Down Expand Up @@ -241,7 +238,7 @@ private SparseArray<YtFile> getStreamUrls() throws IOException, InterruptedExcep

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

if (FORMAT_MAP.get(itag) != null) {
if (FORMAT_MAP.get(itag) != null && isFormatEnabled(FORMAT_MAP.get(itag))) {
if (format.has("url")) {
String url = format.getString("url").replace("\\u0026", "&");
ytFiles.append(itag, new YtFile(FORMAT_MAP.get(itag), url));
Expand Down Expand Up @@ -306,7 +303,7 @@ private SparseArray<YtFile> getStreamUrls() throws IOException, InterruptedExcep

String curJsFileName;

if (CACHING
if (isCaching()
&& (decipherJsFileName == null || decipherFunctions == null || decipherFunctionName == null)) {
readDecipherFunctFromCache();
}
Expand All @@ -323,7 +320,7 @@ private SparseArray<YtFile> getStreamUrls() throws IOException, InterruptedExcep
decipherJsFileName = curJsFileName;
}

if (LOGGING)
if (isLogging())
Log.d(LOG_TAG, "Decipher signatures: " + encSignatures.size() + ", videos: " + ytFiles.size());

String signature;
Expand Down Expand Up @@ -353,14 +350,26 @@ private SparseArray<YtFile> getStreamUrls() throws IOException, InterruptedExcep
}

if (ytFiles.size() == 0) {
if (LOGGING)
if (isLogging())
Log.d(LOG_TAG, pageHtml);
return null;
}

return ytFiles;
}

private boolean isFormatEnabled(Format itag) {
return true;
}

public boolean isLogging() {
return false;
}

public boolean isCaching() {
return true;
}

private boolean decipherSignature(final SparseArray<String> encSignatures) throws IOException {
// Assume the functions don't change that much
if (decipherFunctionName == null || decipherFunctions == null) {
Expand All @@ -386,12 +395,12 @@ private boolean decipherSignature(final SparseArray<String> encSignatures) throw
urlConnection.disconnect();
}

if (LOGGING)
if (isLogging())
Log.d(LOG_TAG, "Decipher FunctURL: " + decipherFunctUrl);
Matcher mat = patSignatureDecFunction.matcher(javascriptFile);
if (mat.find()) {
decipherFunctionName = mat.group(1);
if (LOGGING)
if (isLogging())
Log.d(LOG_TAG, "Decipher Functname: " + decipherFunctionName);

Pattern patMainVariable = Pattern.compile("(var |\\s|,|;)" + decipherFunctionName.replace("$", "\\$") +
Expand Down Expand Up @@ -465,10 +474,10 @@ else if (javascriptFile.charAt(i) == '}')
}
}

if (LOGGING)
if (isLogging())
Log.d(LOG_TAG, "Decipher Function: " + decipherFunctions);
decipherViaWebView(encSignatures);
if (CACHING) {
if (isLogging()) {
writeDeciperFunctToChache();
}
} else {
Expand Down Expand Up @@ -582,7 +591,7 @@ public void onResult(String result) {
public void onError(String errorMessage) {
lock.lock();
try {
if (LOGGING)
if (isLogging())
Log.e(LOG_TAG, errorMessage);
jsExecuting.signal();
} finally {
Expand Down

0 comments on commit d59faf7

Please sign in to comment.