Skip to content

Commit

Permalink
Merge pull request #6 from chazeon/feat-sanitize
Browse files Browse the repository at this point in the history
Sanitize filenames to prevent invalid characters
  • Loading branch information
chazeon authored Jul 2, 2024
2 parents 513ac70 + aa5545b commit 6027d9a
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 5 deletions.
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

0 comments on commit 6027d9a

Please sign in to comment.