Skip to content

Commit

Permalink
[script.module.youtube.dl] 23.12.01
Browse files Browse the repository at this point in the history
  • Loading branch information
joaopa00 committed Dec 2, 2023
1 parent fdaa93d commit fdf229a
Show file tree
Hide file tree
Showing 153 changed files with 11,676 additions and 3,021 deletions.
2 changes: 1 addition & 1 deletion script.module.youtube.dl/addon.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<addon id="script.module.youtube.dl" name="youtube-dl Control" version="21.303.0" provider-name="ytdl-org,ruuk,sy6sy2,wwark">
<addon id="script.module.youtube.dl" name="youtube-dl Control" version="23.04.01" provider-name="ytdl-org,ruuk,sy6sy2,wwark">
<requires>
<import addon="xbmc.python" version="2.26.0"/>
<import addon="script.module.addon.signals" version="0.0.5"/>
Expand Down
404 changes: 314 additions & 90 deletions script.module.youtube.dl/lib/youtube_dl/YoutubeDL.py

Large diffs are not rendered by default.

39 changes: 36 additions & 3 deletions script.module.youtube.dl/lib/youtube_dl/aes.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,18 @@
BLOCK_SIZE_BYTES = 16


def pkcs7_padding(data):
"""
PKCS#7 padding
@param {int[]} data cleartext
@returns {int[]} padding data
"""

remaining_length = BLOCK_SIZE_BYTES - len(data) % BLOCK_SIZE_BYTES
return data + [remaining_length] * remaining_length


def aes_ctr_decrypt(data, key, counter):
"""
Decrypt with aes in counter mode
Expand Down Expand Up @@ -76,8 +88,7 @@ def aes_cbc_encrypt(data, key, iv):
previous_cipher_block = iv
for i in range(block_count):
block = data[i * BLOCK_SIZE_BYTES: (i + 1) * BLOCK_SIZE_BYTES]
remaining_length = BLOCK_SIZE_BYTES - len(block)
block += [remaining_length] * remaining_length
block = pkcs7_padding(block)
mixed_block = xor(block, previous_cipher_block)

encrypted_block = aes_encrypt(mixed_block, expanded_key)
Expand All @@ -88,6 +99,28 @@ def aes_cbc_encrypt(data, key, iv):
return encrypted_data


def aes_ecb_encrypt(data, key):
"""
Encrypt with aes in ECB mode. Using PKCS#7 padding
@param {int[]} data cleartext
@param {int[]} key 16/24/32-Byte cipher key
@returns {int[]} encrypted data
"""
expanded_key = key_expansion(key)
block_count = int(ceil(float(len(data)) / BLOCK_SIZE_BYTES))

encrypted_data = []
for i in range(block_count):
block = data[i * BLOCK_SIZE_BYTES: (i + 1) * BLOCK_SIZE_BYTES]
block = pkcs7_padding(block)

encrypted_block = aes_encrypt(block, expanded_key)
encrypted_data += encrypted_block

return encrypted_data


def key_expansion(data):
"""
Generate key schedule
Expand Down Expand Up @@ -303,7 +336,7 @@ def xor(data1, data2):


def rijndael_mul(a, b):
if(a == 0 or b == 0):
if (a == 0 or b == 0):
return 0
return RIJNDAEL_EXP_TABLE[(RIJNDAEL_LOG_TABLE[a] + RIJNDAEL_LOG_TABLE[b]) % 0xFF]

Expand Down
36 changes: 28 additions & 8 deletions script.module.youtube.dl/lib/youtube_dl/cache.py
Original file line number Diff line number Diff line change
@@ -1,29 +1,40 @@
from __future__ import unicode_literals

import errno
import io
import json
import os
import re
import shutil
import traceback

from .compat import compat_getenv
from .compat import (
compat_getenv,
compat_open as open,
)
from .utils import (
error_to_compat_str,
expand_path,
is_outdated_version,
try_get,
write_json_file,
)
from .version import __version__


class Cache(object):

_YTDL_DIR = 'youtube-dl'
_VERSION_KEY = _YTDL_DIR + '_version'
_DEFAULT_VERSION = '2021.12.17'

def __init__(self, ydl):
self._ydl = ydl

def _get_root_dir(self):
res = self._ydl.params.get('cachedir')
if res is None:
cache_root = compat_getenv('XDG_CACHE_HOME', '~/.cache')
res = os.path.join(cache_root, 'youtube-dl')
res = os.path.join(cache_root, self._YTDL_DIR)
return expand_path(res)

def _get_cache_fn(self, section, key, dtype):
Expand All @@ -50,13 +61,22 @@ def store(self, section, key, data, dtype='json'):
except OSError as ose:
if ose.errno != errno.EEXIST:
raise
write_json_file(data, fn)
write_json_file({self._VERSION_KEY: __version__, 'data': data}, fn)
except Exception:
tb = traceback.format_exc()
self._ydl.report_warning(
'Writing cache to %r failed: %s' % (fn, tb))

def load(self, section, key, dtype='json', default=None):
def _validate(self, data, min_ver):
version = try_get(data, lambda x: x[self._VERSION_KEY])
if not version: # Backward compatibility
data, version = {'data': data}, self._DEFAULT_VERSION
if not is_outdated_version(version, min_ver or '0', assume_new=False):
return data['data']
self._ydl.to_screen(
'Discarding old cache from version {version} (needs {min_ver})'.format(**locals()))

def load(self, section, key, dtype='json', default=None, min_ver=None):
assert dtype in ('json',)

if not self.enabled:
Expand All @@ -65,13 +85,13 @@ def load(self, section, key, dtype='json', default=None):
cache_fn = self._get_cache_fn(section, key, dtype)
try:
try:
with io.open(cache_fn, 'r', encoding='utf-8') as cachef:
return json.load(cachef)
with open(cache_fn, 'r', encoding='utf-8') as cachef:
return self._validate(json.load(cachef), min_ver)
except ValueError:
try:
file_size = os.path.getsize(cache_fn)
except (OSError, IOError) as oe:
file_size = str(oe)
file_size = error_to_compat_str(oe)
self._ydl.report_warning(
'Cache retrieval from %s failed (%s)' % (cache_fn, file_size))
except IOError:
Expand Down
Loading

0 comments on commit fdf229a

Please sign in to comment.