Skip to content

Commit

Permalink
Test GPG Signing
Browse files Browse the repository at this point in the history
  • Loading branch information
Emily3403 committed Jan 20, 2024
1 parent c7b670a commit ae7668b
Show file tree
Hide file tree
Showing 9 changed files with 43 additions and 103 deletions.
2 changes: 1 addition & 1 deletion aur
Submodule aur updated from 50cf21 to aa3cc7
11 changes: 5 additions & 6 deletions src/isisdl/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
import isisdl.compress as compress
from isisdl.api.crud import authenticate_new_session
from isisdl.api.download_urls import download_media_urls, gather_media_urls
from isisdl.api.endpoints import UserCourseListAPI
from isisdl.api.endpoints import UserCourseListAPI, UserIDAPI
from isisdl.backend import sync_database
from isisdl.backend.config import init_wizard, config_wizard
from isisdl.backend.crud import read_config, read_user
from isisdl.backend.crud import read_config, read_user, create_default_config, store_user
from isisdl.backend.request_helper import CourseDownloader
from isisdl.db_conf import init_database, DatabaseSessionMaker
from isisdl.settings import is_first_time, is_static, forbidden_chars, has_ffmpeg, fstype, is_windows, working_dir_location, python_executable, is_macos, is_online
Expand Down Expand Up @@ -45,13 +45,12 @@ async def _new_main() -> None:
return

courses = await UserCourseListAPI.get(db, session, user, config)
# courses = read_courses(db)
if courses is None:
return

urls = await gather_media_urls(db, session, courses)
# if urls is None:
# return
urls = await gather_media_urls(db, session, courses, config)
if not urls:
return None

# urls = read_downloadable_media_containers(db)
downloaded_content = await download_media_urls(db, urls)
Expand Down
22 changes: 19 additions & 3 deletions src/isisdl/api/crud.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@
from sqlalchemy import select
from sqlalchemy.orm import Session as DatabaseSession

from isisdl.api.models import AuthenticatedSession, Course, MediaURL
from isisdl.api.models import AuthenticatedSession, Course, MediaURL, MediaType
from isisdl.backend.models import User, Config
from isisdl.db_conf import add_or_update_objects_to_database
from isisdl.utils import datetime_fromtimestamp_with_None
from isisdl.utils import datetime_fromtimestamp_with_None, flat_map
from isisdl.version import __version__


Expand Down Expand Up @@ -85,10 +85,26 @@ def parse_courses_from_API(db: DatabaseSession, courses: list[dict[str, Any]], c
{"preferred_name"}
)

def parse_videos_from_API(db: DatabaseSession, videos: list[dict[str, Any]], config: Config) -> list[MediaURL] | None:
if config.dl_download_videos is False:
return []

vid = list(
flat_map(
lambda it: it.get("videos", [{}]) | {"courseid": it.get("courseid")},
map(lambda it: it.get("data", {}), videos)
)
)

existing_videos = {it.course_id: it for it in read_media_urls(db) if it.media_type == MediaType.video}


pass


def read_courses(db: DatabaseSession) -> list[Course]:
return list(db.execute(select(Course)).scalars().all())


def read_downloadable_media_containers(db: DatabaseSession) -> list[MediaURL]:
def read_media_urls(db: DatabaseSession) -> list[MediaURL]:
return list(db.execute(select(MediaURL)).scalars().all())
8 changes: 5 additions & 3 deletions src/isisdl/api/download_urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,19 @@

from sqlalchemy.orm import Session as DatabaseSession

from isisdl.api.endpoints import VideoListAPI
from isisdl.api.endpoints import VideoListAPI, DocumentListAPI
from isisdl.api.models import MediaContainer, MediaURL, AuthenticatedSession, Course

__all__ = ["download_media_urls"]

from isisdl.backend.models import Config

async def gather_media_urls(db: DatabaseSession, session: AuthenticatedSession, courses: list[Course]) -> list[MediaURL]:

async def gather_media_urls(db: DatabaseSession, session: AuthenticatedSession, courses: list[Course], config: Config) -> list[MediaURL]:
urls = []
for response in asyncio.as_completed([
# DocumentListAPI.get(db, session, courses),
VideoListAPI.get(session, courses)]
VideoListAPI.get(db, session, courses, config)]
):
urls.extend(await response)

Expand Down
43 changes: 13 additions & 30 deletions src/isisdl/api/endpoints.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

from sqlalchemy.orm import Session as DatabaseSession

from isisdl.api.crud import parse_courses_from_API, read_downloadable_media_containers
from isisdl.api.crud import parse_courses_from_API, read_media_urls, parse_videos_from_API
from isisdl.api.models import AuthenticatedSession, Course, Error, MediaType, MediaURL
from isisdl.backend.models import User, Config
from isisdl.db_conf import add_or_update_objects_to_database
Expand Down Expand Up @@ -96,14 +96,14 @@ def json_data(cls, session: AuthenticatedSession) -> dict[str, Any]:

@classmethod
async def _get(cls, session: AuthenticatedSession, data: dict[str, Any] | list[dict[str, Any]] | None = None) -> Any | None:
async with session.get(cls.url, data=cls.enrich_data(session, data), ) as response:
async with session.get(cls.url, params={"sesskey": session.session_key}, json=cls.enrich_data(session, data)) as response:

if isinstance(response, Error) or not response.ok:
return None

try:
match await response.json():
case {"errorcode": _} | {"exception": _}:
match x := await response.json():
case {"error": _} | {"errorcode": _} | {"exception": _}:
return None

case valid:
Expand All @@ -113,20 +113,21 @@ async def _get(cls, session: AuthenticatedSession, data: dict[str, Any] | list[d
return None


return await super()._get_(session, , post_json=True, params={"sesskey": session.session_key})


class VideoListAPI(AjaxAPIEndpoint):
function = "mod_videoservice_get_videos"

@classmethod
async def get(cls, session: AuthenticatedSession, courses: list[Course]) -> Any:
data = [{
async def get(cls, db: DatabaseSession, session: AuthenticatedSession, courses: list[Course], config: Config) -> Any:
response = await super()._get(session, [{
"args": {"courseid": course.id},
"index": i
} for i, course in enumerate(courses)]
} for i, course in enumerate(courses)])

if response is None:
return None

return await super()._get(session, data)
return parse_videos_from_API(db, response, config)


class UserIDAPI(MoodleAPIEndpoint):
Expand Down Expand Up @@ -154,24 +155,6 @@ async def get(cls, db: DatabaseSession, session: AuthenticatedSession, user: Use
return parse_courses_from_API(db, response, config)


class CourseListAPI(MoodleAPIEndpoint):
# TODO: check out core_course_get_courses_by_field
function = "core_course_search_courses"

@classmethod
async def get(cls, session: AuthenticatedSession) -> Any:
return cls._get(session, data={"criterianame": "search", "criteriavalue": "", })


class TestAPI(MoodleAPIEndpoint):
function = "core_course_get_course_module"


class TestAjaxAPI(MoodleAPIEndpoint):
url = "https://isis.tu-berlin.de/lib/ajax/service.php"
function = ""


class DocumentListAPI(MoodleAPIEndpoint):
function = "core_course_get_contents"

Expand Down Expand Up @@ -288,7 +271,7 @@ async def get(cls, db: DatabaseSession, session: AuthenticatedSession, courses:

files = cls._filter_duplicates_from_files(normalized_files_with_duplicates)

existing_containers = {(it.course_id, normalize_url(it.url)): it for it in read_downloadable_media_containers(db)}
existing_containers = {(it.course_id, normalize_url(it.url)): it for it in read_media_urls(db) if it.media_type in {MediaType.document, MediaType.extern}}

return add_or_update_objects_to_database(
db, existing_containers, files, MediaURL, lambda x: (x["course_id"], normalize_url(x["fileurl"])),
Expand Down Expand Up @@ -372,7 +355,7 @@ async def old_get(cls, db: DatabaseSession, session: AuthenticatedSession, cours
"timemodified": next((name for file in files if (name := file["timemodified"]) is not None), None),
})

existing_containers = {(it.course_id, it.url): it for it in read_downloadable_media_containers(db)}
existing_containers = {(it.course_id, it.url): it for it in read_media_urls(db)}

return add_or_update_objects_to_database(
db, existing_containers, new_data, MediaURL, lambda x: (x["course_id"], x["fileurl"]),
Expand Down
23 changes: 0 additions & 23 deletions src/isisdl/changelog/1.3/1.3.13.md

This file was deleted.

3 changes: 0 additions & 3 deletions src/isisdl/changelog/1.3/1.3.14.md

This file was deleted.

12 changes: 0 additions & 12 deletions src/isisdl/changelog/1.3/1.3.15.md

This file was deleted.

22 changes: 0 additions & 22 deletions src/isisdl/changelog/1.4/1.4.0.md

This file was deleted.

0 comments on commit ae7668b

Please sign in to comment.