Skip to content

Commit

Permalink
Bump to 2.3.10
Browse files Browse the repository at this point in the history
  • Loading branch information
C0D3D3V committed Jul 3, 2024
1 parent e258125 commit f45a9c9
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 6 deletions.
17 changes: 12 additions & 5 deletions moodle_dl/moodle/moodle_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
from moodle_dl.moodle.request_helper import RequestHelper
from moodle_dl.moodle.result_builder import ResultBuilder
from moodle_dl.types import Course, MoodleDlOpts, MoodleURL
from moodle_dl.utils import determine_ext
from moodle_dl.utils import determine_ext, is_base_64


class MoodleService:
Expand Down Expand Up @@ -48,13 +48,20 @@ def extract_token(address: str) -> str:
splitted = address.split('token=')

if len(splitted) < 2:
print("this might not be the correct url. Did you maybe only paste the token instead of the whole url?")
return None

decoded = str(base64.b64decode(splitted[1]))
if is_base_64(address):
decoded = str(base64.b64decode(address))
else:
logging.error(
'This might not be the correct url. The token was not found in the input.'
+ ' Have you perhaps only inserted the token instead of the whole URL?'
)
return None
else:
decoded = str(base64.b64decode(splitted[1]))

splitted = decoded.split(':::')
if len(splitted) < 2:
logging.error('The token could not be decrypted. Did you perhaps not copy the complete url?')
return None

token = re.sub(r'[^A-Za-z0-9]+', '', splitted[1])
Expand Down
8 changes: 8 additions & 0 deletions moodle_dl/utils.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import base64
import collections
import contextlib
import email.utils
Expand Down Expand Up @@ -77,6 +78,13 @@ def get_nested(from_dict: Dict, key: str, default=None):
return default


def is_base_64(s):
try:
return base64.b64encode(base64.b64decode(s)) == s
except Exception: # pylint: disable=broad-exception-caught
return False


# Templates for internet shortcut files, which are plain text files.
DOT_URL_LINK_TEMPLATE = '''\
[InternetShortcut]
Expand Down
2 changes: 1 addition & 1 deletion moodle_dl/version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = '2.3.9'
__version__ = '2.3.10'

0 comments on commit f45a9c9

Please sign in to comment.