Skip to content
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

Sanitize filenames to prevent invalid characters #6

Merged
merged 3 commits into from
Jul 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ authors = [{ name = "Chenxing Luo", email = "chenxing.luo@gmail.com" }]
readme = "README.md"
license = { file = "LICENSE" }
dynamic = ["version"]
dependencies = ["requests", "mutagen", "click", "tabulate", "wcwidth"]
dependencies = ["requests", "mutagen", "click", "tabulate", "wcwidth", "pathvalidate"]
requires-python = ">=3.6"

[project.scripts]
Expand All @@ -17,4 +17,4 @@ Repository = "https://github.com/chazeon/python-vistopia.git"
include = ["vistopia"]

[tool.setuptools.dynamic]
version = {attr = "vistopia.__version__"}
version = {attr = "vistopia.__version__"}
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ mutagen
click
tabulate
wcwidth
pathvalidate
13 changes: 10 additions & 3 deletions vistopia/visitor.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from logging import getLogger
from functools import lru_cache
from typing import Optional
from pathvalidate import sanitize_filename


logger = getLogger(__name__)
Expand Down Expand Up @@ -73,7 +74,9 @@ def save_show(self, id: int,
int(article["sort_number"]) not in episodes:
continue

fname = show_dir / "{}.mp3".format(article["title"])
fname = show_dir / "{}.mp3".format(
sanitize_filename(article["title"])
)
if not fname.exists():
urlretrieve(article["media_key_full_url"], fname)

Expand All @@ -99,7 +102,9 @@ def save_transcript(self, id: int, episodes: Optional[set] = None):
int(article["sort_number"]) not in episodes:
continue

fname = show_dir / "{}.html".format(article["title"])
fname = show_dir / "{}.html".format(
sanitize_filename(article["title"])
)
if not fname.exists():
urlretrieve(article["content_url"], fname)

Expand Down Expand Up @@ -131,7 +136,9 @@ def save_transcript_with_single_file(self, id: int,
if episodes and int(article["sort_number"]) not in episodes:
continue

fname = show_dir / "{}.html".format(article["title"])
fname = show_dir / "{}.html".format(
sanitize_filename(article["title"])
)
if not fname.exists():
command = [
single_file_exec_path,
Expand Down
Loading