Skip to content

Commit

Permalink
Merge pull request #122 from knowbee/hotfix/fix-syntax-warning-for-wsl
Browse files Browse the repository at this point in the history
fix: SyntaxWarning: invalid escape sequence
  • Loading branch information
knowbee authored Mar 20, 2024
2 parents 6626959 + 9b924bf commit 463267d
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 13 deletions.
2 changes: 1 addition & 1 deletion llvd/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# -*- encoding: utf-8 -*-
"""Linkedin Learning Video Downloader."""
__version__ = "3.0.7"
__version__ = "3.0.8"
35 changes: 23 additions & 12 deletions llvd/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
import sys
from llvd import config
import subprocess


class App:
def __init__(
self, email, password, course_slug, resolution, caption, exercise, throttle
Expand Down Expand Up @@ -77,11 +79,11 @@ def run(self, cookies=None, headers={}):
self.cookies["JSESSIONID"] = cookies.get("JSESSIONID")
self.cookies["li_at"] = cookies.get("li_at")

self.headers=headers
self.headers = headers
self.headers["Csrf-Token"] = cookies.get("JSESSIONID")

# remove empty files
command = 'find . -depth -type f -size 0 -exec rm {} +'
command = "find . -depth -type f -size 0 -exec rm {} +"
subprocess.run(command, shell=True)

# proceed to download
Expand Down Expand Up @@ -203,7 +205,11 @@ def download_courses_from_path(self):
self.download_entire_course(skip_done_alert=suppress)

except EmptyCourseList as e:
click.echo(click.style(f"EmptyCourseList: Error parsing learning path.\n{e}", fg="red"))
click.echo(
click.style(
f"EmptyCourseList: Error parsing learning path.\n{e}", fg="red"
)
)

except Exception as e:
click.echo(
Expand Down Expand Up @@ -248,11 +254,13 @@ def fetch_chapter(self, chapter, chapters_pad_length, delay):
current_files = []
for file in os.listdir(chapter_path):
if file.endswith(".mp4") and ". " in file:
ff = re.split("\d+\. ", file)[1].replace(".mp4", "")
ff = re.split(r"\d+\. ", file)[1].replace(".mp4", "")
current_files.append(ff)

# unique videos by checking if the video name is in the current files
videos = [video for video in videos if clean_name(video["title"]) not in current_files]
videos = [
video for video in videos if clean_name(video["title"]) not in current_files
]

for video in videos:
self.current_video_index = video_index + len(current_files)
Expand Down Expand Up @@ -356,7 +364,9 @@ def download_entire_course(self, *args, **kwargs):
)

except requests.exceptions.TooManyRedirects:
click.echo(click.style(f"TooManyRedirects: Your cookie is expired", fg="red"))
click.echo(
click.style(f"TooManyRedirects: Your cookie is expired", fg="red")
)
except KeyError as e:
click.echo(click.style(f"KeyError: That course is not found {e}", fg="red"))

Expand All @@ -375,11 +385,12 @@ def download_entire_course(self, *args, **kwargs):
fg="red",
)
)
except json.decoder.JSONDecodeError as e:
click.echo(click.style(
f"The course is locked, you probably "
f"need a premium account",
fg="red")
except json.decoder.JSONDecodeError as e:
click.echo(
click.style(
f"The course is locked, you probably " f"need a premium account",
fg="red",
)
)
except Exception as e:
if os.path.exists(
Expand Down

0 comments on commit 463267d

Please sign in to comment.