Skip to content

Commit

Permalink
Better filename slugify
Browse files Browse the repository at this point in the history
  • Loading branch information
Blatzar committed Oct 9, 2020
1 parent 94e9320 commit bb7613d
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions anime_downloader/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -242,12 +242,13 @@ def get_json(url, params=None):

def slugify(file_name):
file_name = str(file_name).strip().replace(' ', '_')
return re.sub(r'(?u)[^-\w.]', '', file_name)
# First group removes filenames starting with a dot making them hidden.
# Second group removes anything not in it, for example '"/\|
return re.sub(r'(^\.)|([^-\w.!+-])', '', file_name)


def format_filename(filename, episode):
zerosTofill = math.ceil(math.log10(episode._parent._len))

rep_dict = {
'anime_title': slugify(episode._parent.title),
'ep_no': str(episode.ep_no).zfill(zerosTofill),
Expand Down Expand Up @@ -421,3 +422,4 @@ def type_cast_value(self, ctx, value):
return ast.literal_eval(value)
except:
raise click.BadParameter(value)

0 comments on commit bb7613d

Please sign in to comment.