Skip to content

Commit

Permalink
improved regex
Browse files Browse the repository at this point in the history
  • Loading branch information
jenslys committed Mar 8, 2022
1 parent bdf181c commit bb361ed
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 8 deletions.
19 changes: 12 additions & 7 deletions nrkdl/nrkdl.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from __future__ import unicode_literals
import os
import yt_dlp
from yt_dlp.postprocessor import MetadataParserPP
import argparse
import re

Expand Down Expand Up @@ -39,13 +40,6 @@ def progress_hooks(d):
file_tuple = os.path.split(os.path.abspath(d["filename"]))
print("Done downloading {}".format(file_tuple[1]))

# ! Regex rename (temp solution)
# Exit - 1x2 - 2. Horer og hummer på Hankø → Exit - 1x2 - Horer og hummer på Hankø
pattern = r"[0-9]+[.]+[ ]"
subst = ""
result = re.sub(pattern, subst, d["filename"], 0, re.MULTILINE)
os.rename(d["filename"], result)

if d["status"] == "downloading":
print("Downloading:", d["filename"])
print("Progress:", d["_percent_str"])
Expand All @@ -68,6 +62,7 @@ def download():
ydl_opts = {
"writesubtitles": args.write_subs,
"subtitleslangs": ["all"],
"verbose": False,
"outtmpl": folder_name + "/" + filename,
"quiet": True,
"skip_download": False,
Expand Down Expand Up @@ -106,6 +101,16 @@ def download():
"preferredcodec": "mp3",
},
)

if "/serie/" in args.url:
ydl_opts["postprocessors"].append(
{
"key": "MetadataParser",
"when": "pre_process",
"actions": [(MetadataParserPP.Actions.REPLACE, "episode", r"\d+\.+\s", "")],
},
)

with yt_dlp.YoutubeDL(ydl_opts) as ydl:
ydl.download([args.url])
except Exception as e:
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

setuptools.setup(
name="nrkdl",
version="1.0.3",
version="1.0.4",
author="jenlys",
description="Download movies/tv-shows from nrk.no",
long_description=long_description,
Expand Down

0 comments on commit bb361ed

Please sign in to comment.