Allow changes to run under Python 3
parent
97b3656c2e
commit
48ea9cea77
|
@ -3,6 +3,8 @@ __all__ = ['aes_encrypt', 'key_expansion', 'aes_ctr_decrypt', 'aes_decrypt_text'
|
||||||
import base64
|
import base64
|
||||||
from math import ceil
|
from math import ceil
|
||||||
|
|
||||||
|
from .utils import bytes_to_intlist
|
||||||
|
|
||||||
BLOCK_SIZE_BYTES = 16
|
BLOCK_SIZE_BYTES = 16
|
||||||
|
|
||||||
def aes_ctr_decrypt(data, key, counter):
|
def aes_ctr_decrypt(data, key, counter):
|
||||||
|
@ -16,7 +18,7 @@ def aes_ctr_decrypt(data, key, counter):
|
||||||
@returns {int[]} decrypted data
|
@returns {int[]} decrypted data
|
||||||
"""
|
"""
|
||||||
expanded_key = key_expansion(key)
|
expanded_key = key_expansion(key)
|
||||||
block_count = int(ceil(float(len(data)) / BLOCK_SIZE_BYTES))
|
block_count = int(ceil(float(len(data)) // BLOCK_SIZE_BYTES))
|
||||||
|
|
||||||
decrypted_data=[]
|
decrypted_data=[]
|
||||||
for i in range(block_count):
|
for i in range(block_count):
|
||||||
|
@ -40,7 +42,7 @@ def key_expansion(data):
|
||||||
data = data[:] # copy
|
data = data[:] # copy
|
||||||
rcon_iteration = 1
|
rcon_iteration = 1
|
||||||
key_size_bytes = len(data)
|
key_size_bytes = len(data)
|
||||||
expanded_key_size_bytes = (key_size_bytes/4 + 7) * BLOCK_SIZE_BYTES
|
expanded_key_size_bytes = (key_size_bytes // 4 + 7) * BLOCK_SIZE_BYTES
|
||||||
|
|
||||||
while len(data) < expanded_key_size_bytes:
|
while len(data) < expanded_key_size_bytes:
|
||||||
temp = data[-4:]
|
temp = data[-4:]
|
||||||
|
@ -72,7 +74,7 @@ def aes_encrypt(data, expanded_key):
|
||||||
@param {int[]} expanded_key 176/208/240-Byte expanded key
|
@param {int[]} expanded_key 176/208/240-Byte expanded key
|
||||||
@returns {int[]} 16-Byte cipher
|
@returns {int[]} 16-Byte cipher
|
||||||
"""
|
"""
|
||||||
rounds = len(expanded_key) / BLOCK_SIZE_BYTES - 1
|
rounds = len(expanded_key) // BLOCK_SIZE_BYTES - 1
|
||||||
|
|
||||||
data = xor(data, expanded_key[:BLOCK_SIZE_BYTES])
|
data = xor(data, expanded_key[:BLOCK_SIZE_BYTES])
|
||||||
for i in range(1, rounds+1):
|
for i in range(1, rounds+1):
|
||||||
|
@ -99,11 +101,11 @@ def aes_decrypt_text(data, password, key_size_bytes):
|
||||||
"""
|
"""
|
||||||
NONCE_LENGTH_BYTES = 8
|
NONCE_LENGTH_BYTES = 8
|
||||||
|
|
||||||
data = map(lambda c: ord(c), base64.b64decode(data))
|
data = bytes_to_intlist(base64.b64decode(data))
|
||||||
password = map(lambda c: ord(c), password.encode('utf-8'))
|
password = bytes_to_intlist(password.encode('utf-8'))
|
||||||
|
|
||||||
key = password[:key_size_bytes] + [0]*(key_size_bytes - len(password))
|
key = password[:key_size_bytes] + [0]*(key_size_bytes - len(password))
|
||||||
key = aes_encrypt(key[:BLOCK_SIZE_BYTES], key_expansion(key)) * (key_size_bytes / BLOCK_SIZE_BYTES)
|
key = aes_encrypt(key[:BLOCK_SIZE_BYTES], key_expansion(key)) * (key_size_bytes // BLOCK_SIZE_BYTES)
|
||||||
|
|
||||||
nonce = data[:NONCE_LENGTH_BYTES]
|
nonce = data[:NONCE_LENGTH_BYTES]
|
||||||
cipher = data[NONCE_LENGTH_BYTES:]
|
cipher = data[NONCE_LENGTH_BYTES:]
|
||||||
|
@ -143,7 +145,7 @@ MIX_COLUMN_MATRIX = ((2,3,1,1),
|
||||||
(3,1,1,2))
|
(3,1,1,2))
|
||||||
|
|
||||||
def sub_bytes(data):
|
def sub_bytes(data):
|
||||||
return map(lambda x: SBOX[x], data)
|
return [SBOX[x] for x in data]
|
||||||
|
|
||||||
def rotate(data):
|
def rotate(data):
|
||||||
return data[1:] + [data[0]]
|
return data[1:] + [data[0]]
|
||||||
|
@ -156,7 +158,7 @@ def key_schedule_core(data, rcon_iteration):
|
||||||
return data
|
return data
|
||||||
|
|
||||||
def xor(data1, data2):
|
def xor(data1, data2):
|
||||||
return map(lambda (x,y): x^y, zip(data1, data2))
|
return [x^y for x, y in zip(data1, data2)]
|
||||||
|
|
||||||
def mix_column(data):
|
def mix_column(data):
|
||||||
data_mixed = []
|
data_mixed = []
|
||||||
|
|
|
@ -5,6 +5,7 @@ import sys
|
||||||
|
|
||||||
from .common import InfoExtractor
|
from .common import InfoExtractor
|
||||||
from ..utils import (
|
from ..utils import (
|
||||||
|
compat_str,
|
||||||
compat_urllib_parse_urlparse,
|
compat_urllib_parse_urlparse,
|
||||||
compat_urllib_request,
|
compat_urllib_request,
|
||||||
|
|
||||||
|
@ -79,13 +80,16 @@ class YouPornIE(InfoExtractor):
|
||||||
links = re.findall(LINK_RE, download_list_html)
|
links = re.findall(LINK_RE, download_list_html)
|
||||||
|
|
||||||
# Get link of hd video
|
# Get link of hd video
|
||||||
encrypted_video_url = self._html_search_regex(r'var encryptedURL = \'(?P<encrypted_video_url>[a-zA-Z0-9+/]+={0,2})\';',
|
encrypted_video_url = self._html_search_regex(
|
||||||
|
r'var encrypted(?:Quality[0-9]+)?URL = \'(?P<encrypted_video_url>[a-zA-Z0-9+/]+={0,2})\';',
|
||||||
webpage, u'encrypted_video_url')
|
webpage, u'encrypted_video_url')
|
||||||
video_url = unicode( aes_decrypt_text(encrypted_video_url, video_title, 32), 'utf-8')
|
video_url = aes_decrypt_text(encrypted_video_url, video_title, 32)
|
||||||
|
print(video_url)
|
||||||
|
assert isinstance(video_url, compat_str)
|
||||||
if video_url.split('/')[6].split('_')[0] == u'720p': # only add if 720p to avoid duplicates
|
if video_url.split('/')[6].split('_')[0] == u'720p': # only add if 720p to avoid duplicates
|
||||||
links = [video_url] + links
|
links = [video_url] + links
|
||||||
|
|
||||||
if(len(links) == 0):
|
if not links:
|
||||||
raise ExtractorError(u'ERROR: no known formats available for video')
|
raise ExtractorError(u'ERROR: no known formats available for video')
|
||||||
|
|
||||||
self.to_screen(u'Links found: %d' % len(links))
|
self.to_screen(u'Links found: %d' % len(links))
|
||||||
|
@ -122,7 +126,7 @@ class YouPornIE(InfoExtractor):
|
||||||
self._print_formats(formats)
|
self._print_formats(formats)
|
||||||
return
|
return
|
||||||
|
|
||||||
req_format = self._downloader.params.get('format', None)
|
req_format = self._downloader.params.get('format', 'best')
|
||||||
self.to_screen(u'Format: %s' % req_format)
|
self.to_screen(u'Format: %s' % req_format)
|
||||||
|
|
||||||
if req_format is None or req_format == 'best':
|
if req_format is None or req_format == 'best':
|
||||||
|
|
|
@ -708,3 +708,13 @@ class DateRange(object):
|
||||||
return self.start <= date <= self.end
|
return self.start <= date <= self.end
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return '%s - %s' % ( self.start.isoformat(), self.end.isoformat())
|
return '%s - %s' % ( self.start.isoformat(), self.end.isoformat())
|
||||||
|
|
||||||
|
|
||||||
|
def bytes_to_intlist(bs):
|
||||||
|
if not bs:
|
||||||
|
return []
|
||||||
|
if isinstance(bs[0], int): # Python 3
|
||||||
|
return list(bs)
|
||||||
|
else:
|
||||||
|
return [ord(c) for c in bs]
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue