Skip to content

Commit

Permalink
Improve trimming parentheses in title
Browse files Browse the repository at this point in the history
  • Loading branch information
igrek51 committed Feb 21, 2021
1 parent 2572a9d commit e77a519
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 5 deletions.
4 changes: 2 additions & 2 deletions publish.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
rm -rf build/
rm -rf dist/

python3.7 setup.py sdist bdist_wheel
python3 setup.py sdist bdist_wheel

#python3.6 -m twine upload --repository-url https://test.pypi.org/legacy/ dist/*
python3.7 -m twine upload dist/*
python3 -m twine upload dist/*
6 changes: 5 additions & 1 deletion tests/test_metadata.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from trimmer.metadata import extract_artist_title
from trimmer.metadata import extract_artist_title, trim_parentheses


def test_trimming_dots_spaces():
Expand All @@ -11,3 +11,7 @@ def test_removing_brackets():
artist, title = extract_artist_title('Pink Floyd - Welcome To The Machine (Live, Delicate Sound Of Thunder) [2019 Remix]')
assert artist == 'Pink Floyd'
assert title == 'Welcome To The Machine'


def test_trim_parentheses():
assert trim_parentheses('Welcome To The Machine (Live at Pompeii)') == 'Welcome To The Machine'
4 changes: 2 additions & 2 deletions trimmer/downloader.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import youtube_dl
from nuclear.sublog import wrap_context, log

from trimmer.metadata import extract_artist_title
from trimmer.metadata import extract_artist_title, trim_parentheses


def download_from_youtube(url: str) -> str:
Expand Down Expand Up @@ -62,6 +62,6 @@ def fetch_youtube_metadata(url: str) -> Tuple[str, str, str]:
def extract_youtube_artist_title(url: str) -> Tuple[str, str]:
artist, track, full_title = fetch_youtube_metadata(url)
if artist and track:
return artist, track
return artist, trim_parentheses(track)

return extract_artist_title(full_title)
5 changes: 5 additions & 0 deletions trimmer/metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,8 @@ def extract_artist_title(name: str) -> Tuple[str, str]:
title = re.sub(r"[. ]+$", "", title.strip())

return artist, title


def trim_parentheses(name: str) -> str:
name = re.sub(r"\(.+?\)", "", name)
return name.strip()
1 change: 1 addition & 0 deletions trimmer/trim_source.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ def trim_url(url: str, user_artist: Optional[str], user_title: Optional[str],
log.info('artist & title extracted from youtube page', artist=yt_artist, title=yt_title)
artist = user_artist or enter_or_default('Artist', default=yt_artist)
title = user_title or enter_or_default('Title', default=yt_title)
log.info('song name set', name=f'{artist} - {title}')

mp3_file = download_from_youtube(url)
if output:
Expand Down

0 comments on commit e77a519

Please sign in to comment.