From fa7e5663270e840d02dbc7dec09d4c24ab2ccc58 Mon Sep 17 00:00:00 2001 From: Puyodead1 <14828766+Puyodead1@users.noreply.github.com> Date: Sat, 27 Nov 2021 12:41:16 -0500 Subject: [PATCH] some fixes for char decoding errors --- .github/stale.yml | 16 ++++++++++++++++ udemy_downloader/UdemyDownloader.py | 18 +++++++++--------- udemy_downloader/vtt_to_srt.py | 2 +- 3 files changed, 26 insertions(+), 10 deletions(-) create mode 100644 .github/stale.yml diff --git a/.github/stale.yml b/.github/stale.yml new file mode 100644 index 0000000..2850c9c --- /dev/null +++ b/.github/stale.yml @@ -0,0 +1,16 @@ +# Number of days of inactivity before an issue becomes stale +daysUntilStale: 60 +# Number of days of inactivity before a stale issue is closed +daysUntilClose: 7 +# Issues with these labels will never be considered stale +exemptLabels: + - pinned + - security +# Label to use when marking an issue as stale +staleLabel: stale +# Comment to post when marking an issue as stale. Set to `false` to disable +markComment: > + This issue has been automatically marked as stale because it has not had + recent activity. It will be closed if no further activity occurs. +# Comment to post when closing a stale issue. Set to `false` to disable +closeComment: true \ No newline at end of file diff --git a/udemy_downloader/UdemyDownloader.py b/udemy_downloader/UdemyDownloader.py index 1b96706..7d18c1f 100644 --- a/udemy_downloader/UdemyDownloader.py +++ b/udemy_downloader/UdemyDownloader.py @@ -191,7 +191,7 @@ def download(url, path, filename): desc=filename) res = requests.get(url, headers=header, stream=True) res.raise_for_status() - with (open(path, 'ab')) as f: + with (open(path, encoding="utf8", mode='ab')) as f: for chunk in res.iter_content(chunk_size=1024): if chunk: f.write(chunk) @@ -681,7 +681,7 @@ def get_course_information(): global course_info, course_id, title, course_title, portal_name if(load_from_file): if os.path.exists(course_info_path): - f = open(course_info_path, 'r') + f = open(course_info_path, encoding="utf8", mode='r') course_info = json.loads(f.read()) else: print("course_info.json not found, falling back to fetching") @@ -699,7 +699,7 @@ def get_course_content(): global course_content if load_from_file: if os.path.exists(course_content_path): - f = open(course_content_path, 'r') + f = open(course_content_path, encoding="utf8", mode='r') course_content = json.loads(f.read()) else: print("course_content.json not found, falling back to fetching") @@ -713,7 +713,7 @@ def get_course_content(): def parse_data(): global _udemy if load_from_file and os.path.exists(_udemy_path): - f = open(_udemy_path, 'r') + f = open(_udemy_path, encoding="utf8", mode='r') _udemy = json.loads(f.read()) else: process_course() @@ -1020,13 +1020,13 @@ def check_dirs(): def try_load_keys(): global keys - f = open(keyfile_path, 'r') + f = open(keyfile_path, encoding="utf8", mode='r') keys = json.loads(f.read()) def try_load_cookies(): global cookies - f = open(cookiefile_path, 'r') + f = open(cookiefile_path, encoding="utf8", mode='r') cookies = f.read() @@ -1074,7 +1074,7 @@ def UdemyDownloader(): if save_to_file: with open(course_info_path, - 'w') as f: + encoding="utf8", mode='w') as f: f.write(json.dumps(course_info)) print("Saved course info to file") @@ -1087,7 +1087,7 @@ def UdemyDownloader(): if save_to_file: with open(course_content_path, - 'w') as f: + encoding="utf8", mode='w') as f: f.write(json.dumps(course_content)) print("Saved course content to file") @@ -1111,7 +1111,7 @@ def UdemyDownloader(): if save_to_file: with open(_udemy_path, - 'w') as f: + encoding="utf8", mode='w') as f: f.write(json.dumps(_udemy)) print("Saved parsed data to file") diff --git a/udemy_downloader/vtt_to_srt.py b/udemy_downloader/vtt_to_srt.py index 1e2cc28..5fc5a32 100644 --- a/udemy_downloader/vtt_to_srt.py +++ b/udemy_downloader/vtt_to_srt.py @@ -8,7 +8,7 @@ def convert(directory, filename): index = 0 vtt_filepath = os.path.join(directory, filename + ".vtt") srt_filepath = os.path.join(directory, filename + ".srt") - srt = open(srt_filepath, "w") + srt = open(srt_filepath, 'w') for caption in WebVTT().read(vtt_filepath): index += 1