Add option to skip videos in sync_url

This commit is contained in:
I-Al-Istannen 2020-10-06 17:15:10 +02:00
parent a519cbe05d
commit 73c3eb0984
2 changed files with 18 additions and 4 deletions

View File

@ -249,6 +249,9 @@ class IliasCrawler:
element: bs4.Tag = soup.find(id="headerimage") element: bs4.Tag = soup.find(id="headerimage")
if "opencast" in element.attrs["src"].lower(): if "opencast" in element.attrs["src"].lower():
PRETTY.warning(f"Switched to crawling a video at {folder_path}") PRETTY.warning(f"Switched to crawling a video at {folder_path}")
if not self.dir_filter(folder_path, IliasElementType.VIDEO_FOLDER):
PRETTY.not_searching(folder_path, "user filter")
return []
return self._crawl_video_directory(folder_path, url) return self._crawl_video_directory(folder_path, url)
result: List[IliasCrawlerEntry] = [] result: List[IliasCrawlerEntry] = []

View File

@ -6,12 +6,12 @@ A simple script to download a course by name from ILIAS.
import argparse import argparse
from pathlib import Path from pathlib import Path
from urllib.parse import parse_qs, urlparse from urllib.parse import urlparse
from PFERD import Pferd from PFERD import Pferd
from PFERD.cookie_jar import CookieJar from PFERD.cookie_jar import CookieJar
from PFERD.ilias.authenticators import KitShibbolethAuthenticator from PFERD.ilias import (IliasCrawler, IliasElementType,
from PFERD.ilias.crawler import IliasCrawler KitShibbolethAuthenticator)
from PFERD.utils import to_path from PFERD.utils import to_path
@ -19,6 +19,7 @@ def main() -> None:
parser = argparse.ArgumentParser() parser = argparse.ArgumentParser()
parser.add_argument("--test-run", action="store_true") parser.add_argument("--test-run", action="store_true")
parser.add_argument('-c', '--cookies', nargs='?', default=None, help="File to store cookies in") parser.add_argument('-c', '--cookies', nargs='?', default=None, help="File to store cookies in")
parser.add_argument('-f', '--no-videos', nargs='?', default=None, help="Don't download videos")
parser.add_argument('url', help="URL to the course page") parser.add_argument('url', help="URL to the course page")
parser.add_argument('folder', nargs='?', default=None, help="Folder to put stuff into") parser.add_argument('folder', nargs='?', default=None, help="Folder to put stuff into")
args = parser.parse_args() args = parser.parse_args()
@ -47,9 +48,19 @@ def main() -> None:
# Initialize pferd at the location of the script # Initialize pferd at the location of the script
pferd = Pferd(Path(__file__).parent, test_run=args.test_run) pferd = Pferd(Path(__file__).parent, test_run=args.test_run)
def dir_filter(_: Path, element: IliasElementType) -> bool:
if args.no_videos:
return element not in [IliasElementType.VIDEO_FILE, IliasElementType.VIDEO_FOLDER]
return True
pferd.enable_logging() pferd.enable_logging()
# fetch # fetch
pferd.ilias_kit_folder(target=folder, full_url=args.url, cookies=args.cookies) pferd.ilias_kit_folder(
target=folder,
full_url=args.url,
cookies=args.cookies,
dir_filter=dir_filter
)
if __name__ == "__main__": if __name__ == "__main__":