-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from jdaviderb/update-decipher
update decipher object
- Loading branch information
Showing
16 changed files
with
12,113 additions
and
79 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,14 @@ | ||
# This configuration was generated by | ||
# `rubocop --auto-gen-config` | ||
# on 2019-09-03 01:03:51 -0500 using RuboCop version 0.74.0. | ||
# on 2019-09-17 22:24:06 -0500 using RuboCop version 0.74.0. | ||
# The point is for the user to remove these configuration records | ||
# one by one as the offenses are removed from the code base. | ||
# Note that changes in the inspected code, or installation of new | ||
# versions of RuboCop, may require this file to be generated again. | ||
|
||
# Offense count: 5 | ||
# Configuration parameters: MinNameLength, AllowNamesEndingInNumbers, AllowedNames, ForbiddenNames. | ||
# AllowedNames: io, id, to, by, on, in, at, ip, db | ||
Naming/UncommunicativeMethodParamName: | ||
Exclude: | ||
- 'lib/youtube_audio/decipher.rb' | ||
# Offense count: 4 | ||
# Cop supports --auto-correct. | ||
# Configuration parameters: AutoCorrect, AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, IgnoredPatterns. | ||
# URISchemes: http, https | ||
Metrics/LineLength: | ||
Max: 109 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5,982 changes: 5,982 additions & 0 deletions
5,982
fixtures/vcr_cassettes/youtube/player_base_js.yml
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
# frozen_string_literal: true | ||
|
||
module YoutubeAudio | ||
class ExtractDecodeFunction | ||
attr_reader :player_script | ||
CIPHER_TEST = Regexp.new('([\\w$]+)\\s*=\\s*function\\((\\w+)\\)\\{\\s*\\2=\\s*\\2\\.split\\(""\\)\\s*;') | ||
|
||
def initialize(player_script) | ||
@player_script = player_script | ||
end | ||
|
||
def cipher_helper_object_name | ||
@cipher_helper_object_name ||= | ||
decipher_function.scan(/\;([a-zA-Z0-9]{0,255})\./).flatten.first | ||
end | ||
|
||
def cipher_helpers_object | ||
object_decibper_index = player_script.index("var #{cipher_helper_object_name}={") | ||
object_decibper_index_end = player_script[object_decibper_index..-1].index('};') | ||
player_script[object_decibper_index..object_decibper_index + object_decibper_index_end] | ||
end | ||
|
||
def decipher_function | ||
@decipher_function ||= | ||
player_script.scan(Regexp.new(function_pattern)).flatten.first | ||
end | ||
|
||
def decryption_function | ||
@decryption_function ||= player_script.scan(CIPHER_TEST).flatten.first | ||
end | ||
|
||
private | ||
|
||
def function_pattern | ||
@function_pattern ||= | ||
'(' + decryption_function + '=function\\([a-zA-Z0-9_]+\\)\\{.+?\\})' | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
# frozen_string_literal: true | ||
|
||
module YoutubeAudio | ||
VERSION = '0.1.0' | ||
VERSION = '0.2.0' | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,26 @@ | ||
# frozen_string_literal: true | ||
|
||
RSpec.describe YoutubeAudio::Decipher do | ||
subject { described_class.new } | ||
let(:player_base_url) do | ||
'/yts/jsbin/player-plasma-ias-phone-en_US-vflZqC1Iu/base.js' | ||
end | ||
|
||
subject { described_class.new(player_base_url) } | ||
|
||
describe '#decipher' do | ||
let(:signature) do | ||
'qLALgxI2AwRAIgbG7LwidtAcuTBa1Rw8hp5sUXLESfIyXM2MHr4m6jDtUCIARjHJ-5Y' \ | ||
'KOvBfrSPrfc9N62UwxcUvy4kVFNQRL_2glvvlg' | ||
end | ||
let(:decipher) do | ||
'ALgxI2wwRAIgbG7LwidtAcuTBa1Rs8hp5qUXLESfIyXM2MHr4m6jDtUCIARjHJ-5' \ | ||
'YKOvBfrSPrfc9N62UwxcUvy4kVFNQRL_2glv' | ||
'vgg2_LRQNFVk4yvUcxwU26N9cfrPSrfBvOKY5-JHjRAICUtDj6m4rHM2MXyIfSELX' \ | ||
'Uslph8wR1aBTucAtdiwL7GbgIARwA2Ixq' | ||
end | ||
|
||
it 'returns decipher signature' do | ||
expect(subject.decipher(signature)).to eq(decipher) | ||
VCR.use_cassette('youtube/player_base.js') do | ||
expect(subject.decipher(signature)).to eq(decipher) | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters