-
Notifications
You must be signed in to change notification settings - Fork 62
download subtitles and presentations and handle groups #91
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
peter-tanner
wants to merge
6
commits into
soraxas:master
Choose a base branch
from
peter-tanner:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
7370181
Add vtt subtitle download `-s`
peter-tanner 2c71d8e
Add retry on error
peter-tanner 13c5eb6
Handle groups/folders in courses and strip illegal filenames
peter-tanner a70245c
Add `--dump-json`, fix course names, don't re-download subtitles
peter-tanner 6448dda
Download attached media for echo cloud videos
peter-tanner 377047c
Add --dump-json to readme
peter-tanner File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -59,3 +59,6 @@ target/ | |
| bin/ | ||
| default_out_path/ | ||
| _browser_user_data_dir/ | ||
|
|
||
| .vscode/ | ||
| _browser_persistent_session/ | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,24 +1,26 @@ | ||
| import functools | ||
| import json | ||
| import re | ||
| import sys | ||
|
|
||
| import requests | ||
| import selenium | ||
| import logging | ||
|
|
||
| from .utils import strip_illegal_path | ||
| from .videos import EchoVideos, EchoCloudVideos | ||
|
|
||
| _LOGGER = logging.getLogger(__name__) | ||
|
|
||
|
|
||
| class EchoCourse(object): | ||
| def __init__(self, uuid, hostname=None, alternative_feeds=False): | ||
| def __init__(self, uuid, hostname=None, alternative_feeds=False, subtitles=False): | ||
| self._course_id = None | ||
| self._course_name = None | ||
| self._uuid = uuid | ||
| self._videos = None | ||
| self._driver = None | ||
| self._alternative_feeds = alternative_feeds | ||
| self._subtitles = subtitles | ||
| if hostname is None: | ||
| self._hostname = "https://view.streaming.sydney.edu.au:8443" | ||
| else: | ||
|
|
@@ -139,7 +141,11 @@ def get_videos(self): | |
| course_data_json = self._get_course_data() | ||
| videos_json = course_data_json["data"] | ||
| self._videos = EchoCloudVideos( | ||
| videos_json, self._driver, self.hostname, self._alternative_feeds | ||
| videos_json, | ||
| self._driver, | ||
| self.hostname, | ||
| self._alternative_feeds, | ||
| self._subtitles, | ||
| ) | ||
| # except KeyError as e: | ||
| # print("Unable to parse course videos from JSON (course_data)") | ||
|
|
@@ -173,20 +179,29 @@ def course_id(self): | |
| return self._course_id | ||
|
|
||
| @property | ||
| @functools.lru_cache | ||
| def course_name(self): | ||
| if self._course_name is None: | ||
| # try each available video as some video might be special has contains | ||
| # no information about the course. | ||
| for v in self.course_data["data"]: | ||
| try: | ||
| self._course_name = v["lesson"]["video"]["published"]["courseName"] | ||
| break | ||
| except KeyError: | ||
| pass | ||
| if self._course_name is None: | ||
| # no available course name found...? | ||
| self._course_name = "[[UNTITLED]]" | ||
| return self._course_name | ||
| cookies = { | ||
| cookie["name"]: cookie["value"] for cookie in self._driver.get_cookies() | ||
| } | ||
| response = requests.get( | ||
| "https://echo360.net.au/user/enrollments", cookies=cookies | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is hardcoding the hostname. Should this comes from the user provided link? |
||
| ) | ||
| if response.status_code == 200: | ||
| course_list = response.json()["data"] | ||
| for sections_parts in course_list: | ||
| matching = [ | ||
| x | ||
| for x in sections_parts["userSections"] | ||
| if x["sectionId"] == self._uuid | ||
| ] | ||
| if len(matching) > 0: | ||
| course = matching[0] | ||
| return strip_illegal_path( | ||
| f"{course['courseCode']} - {course['sectionName']} {course['courseName']}" | ||
| ) | ||
|
|
||
| return "[[UNTITLED]]" | ||
|
|
||
| @property | ||
| def nice_name(self): | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,5 @@ | ||
| from datetime import datetime | ||
| import json | ||
| import dateutil.parser | ||
| import os | ||
| import sys | ||
|
|
@@ -6,7 +8,7 @@ | |
|
|
||
| from .course import EchoCloudCourse | ||
| from .echo_exceptions import EchoLoginError | ||
| from .utils import naive_versiontuple, PERSISTENT_SESSION_FOLDER | ||
| from .utils import naive_versiontuple, PERSISTENT_SESSION_FOLDER, strip_illegal_path | ||
|
|
||
| import pip_ensure_version | ||
| from pick import pick | ||
|
|
@@ -191,6 +193,7 @@ def __init__( | |
| webdriver_to_use="phantomjs", | ||
| interactive_mode=False, | ||
| persistent_session=False, | ||
| dump_json=False, | ||
| ): | ||
| self._course = course | ||
| root_path = os.path.dirname(os.path.abspath(sys.modules["__main__"].__file__)) | ||
|
|
@@ -200,6 +203,7 @@ def __init__( | |
| self._date_range = date_range | ||
| self._username = username | ||
| self._password = password | ||
| self._dump_json = dump_json | ||
| self.interactive_mode = interactive_mode | ||
|
|
||
| self.regex_replace_invalid = re.compile(r"[\\\\/:*?\"<>|]") | ||
|
|
@@ -342,14 +346,26 @@ def download_all(self): | |
| self.login() | ||
| sys.stdout.write(">> Retrieving echo360 Course Info... ") | ||
| sys.stdout.flush() | ||
| videos = self._course.get_videos().videos | ||
| print("Done!") | ||
|
|
||
| # change the output directory to be inside a folder named after the course | ||
| self._output_dir = os.path.join( | ||
| self._output_dir, "{0}".format(self._course.nice_name).strip() | ||
| ) | ||
| # replace invalid character for folder | ||
| self.regex_replace_invalid.sub("_", self._output_dir) | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should this still be applied? to avoid invalid chars |
||
| if isinstance(self._course, EchoCloudCourse): | ||
| self._output_dir = os.path.join( | ||
| self._output_dir, | ||
| "{0}".format(self._course.nice_name).strip(), | ||
| ) | ||
| if self._output_dir and not os.path.isdir(self._output_dir): | ||
| os.makedirs(self._output_dir) | ||
| if self._dump_json: | ||
| dump_json_path = os.path.join( | ||
| self._output_dir, | ||
| f"course_{datetime.now().replace(microsecond=0).isoformat().replace(':','_')}.json", | ||
| ) | ||
| with open(dump_json_path, "w") as f: | ||
| f.write(json.dumps(self._course._get_course_data())) | ||
|
|
||
| videos = self._course.get_videos().videos | ||
| print("Done!") | ||
|
|
||
| filtered_videos = [video for video in videos if self._in_date_range(video.date)] | ||
| videos_to_be_download = [] | ||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does the enrollment methods always works for all institution? Should it be used as a fallback (one way or the other) instead?