Skip to content

Commit

Permalink
Switch codebase to use compat_b64decode
Browse files Browse the repository at this point in the history
  • Loading branch information
dstftw committed Jan 23, 2018
1 parent 5d7d805 commit cf28207
Show file tree
Hide file tree
Showing 21 changed files with 70 additions and 65 deletions.
4 changes: 2 additions & 2 deletions youtube_dl/aes.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
from __future__ import unicode_literals

import base64
from math import ceil

from .compat import compat_b64decode
from .utils import bytes_to_intlist, intlist_to_bytes

BLOCK_SIZE_BYTES = 16
Expand Down Expand Up @@ -180,7 +180,7 @@ def aes_decrypt_text(data, password, key_size_bytes):
"""
NONCE_LENGTH_BYTES = 8

data = bytes_to_intlist(base64.b64decode(data.encode('utf-8')))
data = bytes_to_intlist(compat_b64decode(data))
password = bytes_to_intlist(password.encode('utf-8'))

key = password[:key_size_bytes] + [0] * (key_size_bytes - len(password))
Expand Down
6 changes: 3 additions & 3 deletions youtube_dl/downloader/f4m.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
from __future__ import division, unicode_literals

import base64
import io
import itertools
import time

from .fragment import FragmentFD
from ..compat import (
compat_b64decode,
compat_etree_fromstring,
compat_urlparse,
compat_urllib_error,
Expand Down Expand Up @@ -312,7 +312,7 @@ def _parse_bootstrap_node(self, node, base_url):
boot_info = self._get_bootstrap_from_url(bootstrap_url)
else:
bootstrap_url = None
bootstrap = base64.b64decode(node.text.encode('ascii'))
bootstrap = compat_b64decode(node.text)
boot_info = read_bootstrap_info(bootstrap)
return boot_info, bootstrap_url

Expand Down Expand Up @@ -349,7 +349,7 @@ def real_download(self, filename, info_dict):
live = boot_info['live']
metadata_node = media.find(_add_ns('metadata'))
if metadata_node is not None:
metadata = base64.b64decode(metadata_node.text.encode('ascii'))
metadata = compat_b64decode(metadata_node.text)
else:
metadata = None

Expand Down
10 changes: 6 additions & 4 deletions youtube_dl/extractor/adn.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
# coding: utf-8
from __future__ import unicode_literals

import base64
import json
import os

from .common import InfoExtractor
from ..aes import aes_cbc_decrypt
from ..compat import compat_ord
from ..compat import (
compat_b64decode,
compat_ord,
)
from ..utils import (
bytes_to_intlist,
ExtractorError,
Expand Down Expand Up @@ -48,9 +50,9 @@ def _get_subtitles(self, sub_path, video_id):

# http://animedigitalnetwork.fr/components/com_vodvideo/videojs/adn-vjs.min.js
dec_subtitles = intlist_to_bytes(aes_cbc_decrypt(
bytes_to_intlist(base64.b64decode(enc_subtitles[24:])),
bytes_to_intlist(compat_b64decode(enc_subtitles[24:])),
bytes_to_intlist(b'\x1b\xe0\x29\x61\x38\x94\x24\x00\x12\xbd\xc5\x80\xac\xce\xbe\xb0'),
bytes_to_intlist(base64.b64decode(enc_subtitles[:24]))
bytes_to_intlist(compat_b64decode(enc_subtitles[:24]))
))
subtitles_json = self._parse_json(
dec_subtitles[:-compat_ord(dec_subtitles[-1])].decode(),
Expand Down
10 changes: 6 additions & 4 deletions youtube_dl/extractor/bigflix.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
# coding: utf-8
from __future__ import unicode_literals

import base64
import re

from .common import InfoExtractor
from ..compat import compat_urllib_parse_unquote
from ..compat import (
compat_b64decode,
compat_urllib_parse_unquote,
)


class BigflixIE(InfoExtractor):
Expand Down Expand Up @@ -39,8 +41,8 @@ def _real_extract(self, url):
webpage, 'title')

def decode_url(quoted_b64_url):
return base64.b64decode(compat_urllib_parse_unquote(
quoted_b64_url).encode('ascii')).decode('utf-8')
return compat_b64decode(compat_urllib_parse_unquote(
quoted_b64_url)).decode('utf-8')

formats = []
for height, encoded_url in re.findall(
Expand Down
4 changes: 2 additions & 2 deletions youtube_dl/extractor/chilloutzone.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
from __future__ import unicode_literals

import re
import base64
import json

from .common import InfoExtractor
from .youtube import YoutubeIE
from ..compat import compat_b64decode
from ..utils import (
clean_html,
ExtractorError
Expand Down Expand Up @@ -58,7 +58,7 @@ def _real_extract(self, url):

base64_video_info = self._html_search_regex(
r'var cozVidData = "(.+?)";', webpage, 'video data')
decoded_video_info = base64.b64decode(base64_video_info.encode('utf-8')).decode('utf-8')
decoded_video_info = compat_b64decode(base64_video_info).decode('utf-8')
video_info_dict = json.loads(decoded_video_info)

# get video information from dict
Expand Down
5 changes: 2 additions & 3 deletions youtube_dl/extractor/chirbit.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
# coding: utf-8
from __future__ import unicode_literals

import base64
import re

from .common import InfoExtractor
from ..compat import compat_b64decode
from ..utils import parse_duration


Expand Down Expand Up @@ -44,8 +44,7 @@ def _real_extract(self, url):

# Reverse engineered from https://chirb.it/js/chirbit.player.js (look
# for soundURL)
audio_url = base64.b64decode(
data_fd[::-1].encode('ascii')).decode('utf-8')
audio_url = compat_b64decode(data_fd[::-1]).decode('utf-8')

title = self._search_regex(
r'class=["\']chirbit-title["\'][^>]*>([^<]+)', webpage, 'title')
Expand Down
6 changes: 3 additions & 3 deletions youtube_dl/extractor/crunchyroll.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@

import re
import json
import base64
import zlib

from hashlib import sha1
from math import pow, sqrt, floor
from .common import InfoExtractor
from ..compat import (
compat_b64decode,
compat_etree_fromstring,
compat_urllib_parse_urlencode,
compat_urllib_request,
Expand Down Expand Up @@ -272,8 +272,8 @@ class CrunchyrollIE(CrunchyrollBaseIE):
}

def _decrypt_subtitles(self, data, iv, id):
data = bytes_to_intlist(base64.b64decode(data.encode('utf-8')))
iv = bytes_to_intlist(base64.b64decode(iv.encode('utf-8')))
data = bytes_to_intlist(compat_b64decode(data))
iv = bytes_to_intlist(compat_b64decode(iv))
id = int(id)

def obfuscate_key_aux(count, modulo, start):
Expand Down
3 changes: 2 additions & 1 deletion youtube_dl/extractor/daisuki.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
aes_cbc_decrypt,
aes_cbc_encrypt,
)
from ..compat import compat_b64decode
from ..utils import (
bytes_to_intlist,
bytes_to_long,
Expand Down Expand Up @@ -93,7 +94,7 @@ def _real_extract(self, url):

rtn = self._parse_json(
intlist_to_bytes(aes_cbc_decrypt(bytes_to_intlist(
base64.b64decode(encrypted_rtn)),
compat_b64decode(encrypted_rtn)),
aes_key, iv)).decode('utf-8').rstrip('\0'),
video_id)

Expand Down
4 changes: 2 additions & 2 deletions youtube_dl/extractor/dumpert.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
# coding: utf-8
from __future__ import unicode_literals

import base64
import re

from .common import InfoExtractor
from ..compat import compat_b64decode
from ..utils import (
qualities,
sanitized_Request,
Expand Down Expand Up @@ -42,7 +42,7 @@ def _real_extract(self, url):
r'data-files="([^"]+)"', webpage, 'data files')

files = self._parse_json(
base64.b64decode(files_base64.encode('utf-8')).decode('utf-8'),
compat_b64decode(files_base64).decode('utf-8'),
video_id)

quality = qualities(['flv', 'mobile', 'tablet', '720p'])
Expand Down
8 changes: 4 additions & 4 deletions youtube_dl/extractor/einthusan.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
# coding: utf-8
from __future__ import unicode_literals

import base64
import json

from .common import InfoExtractor
from ..compat import (
compat_urlparse,
compat_b64decode,
compat_str,
compat_urlparse,
)
from ..utils import (
extract_attributes,
Expand Down Expand Up @@ -36,9 +36,9 @@ class EinthusanIE(InfoExtractor):

# reversed from jsoncrypto.prototype.decrypt() in einthusan-PGMovieWatcher.js
def _decrypt(self, encrypted_data, video_id):
return self._parse_json(base64.b64decode((
return self._parse_json(compat_b64decode((
encrypted_data[:10] + encrypted_data[-1] + encrypted_data[12:-1]
).encode('ascii')).decode('utf-8'), video_id)
)).decode('utf-8'), video_id)

def _real_extract(self, url):
video_id = self._match_id(url)
Expand Down
5 changes: 2 additions & 3 deletions youtube_dl/extractor/hotnewhiphop.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
from __future__ import unicode_literals

import base64

from .common import InfoExtractor
from ..compat import compat_b64decode
from ..utils import (
ExtractorError,
HEADRequest,
Expand Down Expand Up @@ -48,7 +47,7 @@ def _real_extract(self, url):
if 'mediaKey' not in mkd:
raise ExtractorError('Did not get a media key')

redirect_url = base64.b64decode(video_url_base64).decode('utf-8')
redirect_url = compat_b64decode(video_url_base64).decode('utf-8')
redirect_req = HEADRequest(redirect_url)
req = self._request_webpage(
redirect_req, video_id,
Expand Down
5 changes: 2 additions & 3 deletions youtube_dl/extractor/infoq.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@

from __future__ import unicode_literals

import base64

from ..compat import (
compat_b64decode,
compat_urllib_parse_unquote,
compat_urlparse,
)
Expand Down Expand Up @@ -61,7 +60,7 @@ def _extract_rtmp_video(self, webpage):
encoded_id = self._search_regex(
r"jsclassref\s*=\s*'([^']*)'", webpage, 'encoded id', default=None)

real_id = compat_urllib_parse_unquote(base64.b64decode(encoded_id.encode('ascii')).decode('utf-8'))
real_id = compat_urllib_parse_unquote(compat_b64decode(encoded_id).decode('utf-8'))
playpath = 'mp4:' + real_id

return [{
Expand Down
4 changes: 2 additions & 2 deletions youtube_dl/extractor/leeco.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
# coding: utf-8
from __future__ import unicode_literals

import base64
import datetime
import hashlib
import re
import time

from .common import InfoExtractor
from ..compat import (
compat_b64decode,
compat_ord,
compat_str,
compat_urllib_parse_urlencode,
Expand Down Expand Up @@ -329,7 +329,7 @@ def get_play_json(cf, timestamp):
raise ExtractorError('Letv cloud returned an unknwon error')

def b64decode(s):
return base64.b64decode(s.encode('utf-8')).decode('utf-8')
return compat_b64decode(s).decode('utf-8')

formats = []
for media in play_json['data']['video_info']['media'].values():
Expand Down
11 changes: 5 additions & 6 deletions youtube_dl/extractor/mangomolo.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
# coding: utf-8
from __future__ import unicode_literals

import base64

from .common import InfoExtractor
from ..compat import compat_urllib_parse_unquote
from ..utils import (
int_or_none,
from ..compat import (
compat_b64decode,
compat_urllib_parse_unquote,
)
from ..utils import int_or_none


class MangomoloBaseIE(InfoExtractor):
Expand Down Expand Up @@ -51,4 +50,4 @@ class MangomoloLiveIE(MangomoloBaseIE):
_IS_LIVE = True

def _get_real_id(self, page_id):
return base64.b64decode(compat_urllib_parse_unquote(page_id).encode()).decode()
return compat_b64decode(compat_urllib_parse_unquote(page_id)).decode()
1 change: 0 additions & 1 deletion youtube_dl/extractor/mixcloud.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
from __future__ import unicode_literals

import base64
import functools
import itertools
import re
Expand Down
11 changes: 7 additions & 4 deletions youtube_dl/extractor/ooyala.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
from __future__ import unicode_literals

import re
import base64

from .common import InfoExtractor
from ..compat import compat_str
from ..compat import (
compat_b64decode,
compat_str,
compat_urllib_parse_urlencode,
)
from ..utils import (
determine_ext,
ExtractorError,
Expand All @@ -12,7 +16,6 @@
try_get,
unsmuggle_url,
)
from ..compat import compat_urllib_parse_urlencode


class OoyalaBaseIE(InfoExtractor):
Expand Down Expand Up @@ -44,7 +47,7 @@ def _extract(self, content_tree_url, video_id, domain='example.org', supportedfo
url_data = try_get(stream, lambda x: x['url']['data'], compat_str)
if not url_data:
continue
s_url = base64.b64decode(url_data.encode('ascii')).decode('utf-8')
s_url = compat_b64decode(url_data).decode('utf-8')
if not s_url or s_url in urls:
continue
urls.append(s_url)
Expand Down
Loading

0 comments on commit cf28207

Please sign in to comment.