Fail on invalid ILIAS course ids

This commit is contained in:
I-Al-Istannen 2020-05-08 23:47:05 +02:00
parent afa48c2d2d
commit 19c1e3ac6f
3 changed files with 20 additions and 2 deletions

View File

@ -5,6 +5,8 @@ An error logging decorator.
import logging import logging
from typing import Any, Callable from typing import Any, Callable
from rich.console import Console
from .logging import FatalException, PrettyLogger from .logging import FatalException, PrettyLogger
LOGGER = logging.getLogger(__name__) LOGGER = logging.getLogger(__name__)

View File

@ -14,7 +14,7 @@ from urllib.parse import (parse_qs, urlencode, urljoin, urlparse, urlsplit,
import bs4 import bs4
import requests import requests
from ..logging import PrettyLogger from ..logging import FatalException, PrettyLogger
from ..utils import soupify from ..utils import soupify
from .authenticators import IliasAuthenticator from .authenticators import IliasAuthenticator
from .date_demangler import demangle_date from .date_demangler import demangle_date
@ -80,9 +80,18 @@ class IliasCrawler:
self._base_url + "/goto.php", "target", f"crs_{self._course_id}" self._base_url + "/goto.php", "target", f"crs_{self._course_id}"
) )
if not self._is_course_id_valid(root_url):
raise FatalException(
"Invalid course id? The URL the server returned did not contain my id."
)
# And treat it as a folder # And treat it as a folder
return self._crawl_folder(Path(""), root_url) return self._crawl_folder(Path(""), root_url)
def _is_course_id_valid(self, root_url: str) -> bool:
response: requests.Response = self._session.get(root_url)
return self._course_id in response.url
def _switch_on_crawled_type( def _switch_on_crawled_type(
self, self,
path: Path, path: Path,

View File

@ -14,7 +14,7 @@ from .ilias import (IliasAuthenticator, IliasCrawler, IliasDirectoryFilter,
IliasDownloader, IliasDownloadStrategy, IliasDownloader, IliasDownloadStrategy,
KitShibbolethAuthenticator, download_modified_or_new) KitShibbolethAuthenticator, download_modified_or_new)
from .location import Location from .location import Location
from .logging import PrettyLogger from .logging import FatalException, PrettyLogger
from .organizer import Organizer from .organizer import Organizer
from .tmp_dir import TmpDir from .tmp_dir import TmpDir
from .transform import TF, Transform, apply_transform from .transform import TF, Transform, apply_transform
@ -168,11 +168,18 @@ class Pferd(Location):
clean {bool} -- Whether to clean up when the method finishes. clean {bool} -- Whether to clean up when the method finishes.
""" """
tmp_dir = self._tmp_dir.new_subdir() tmp_dir = self._tmp_dir.new_subdir()
if target is None:
PRETTY.starting_synchronizer("None", "DIVA", playlist_id)
raise FatalException("Got 'None' as target directory, aborting")
if isinstance(target, Organizer): if isinstance(target, Organizer):
organizer = target organizer = target
else: else:
organizer = Organizer(self.resolve(to_path(target))) organizer = Organizer(self.resolve(to_path(target)))
PRETTY.starting_synchronizer(organizer.path, "DIVA", playlist_id)
crawler = DivaPlaylistCrawler(playlist_id) crawler = DivaPlaylistCrawler(playlist_id)
downloader = DivaDownloader(tmp_dir, organizer, download_strategy) downloader = DivaDownloader(tmp_dir, organizer, download_strategy)