-
Notifications
You must be signed in to change notification settings - Fork 40
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
Add parser for reading from the song's tags or from a local .lrc/.lyric file #79
base: master
Are you sure you want to change the base?
Conversation
or from the metadata of the file. Supports mp3, ogg, opus and flac formats
…of the mutagen module.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice going! Just a few comments from me.
PS GitHub's ordering of comments is messed up, comparing to their top-to-bottom order, but you should get the idea.
lLyrics/LocalParser.py
Outdated
try: | ||
out = file["LYRICS"] | ||
except: | ||
pass | ||
try: | ||
out = file["UNSYNCEDLYRICS"] | ||
except: | ||
pass |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same.
You know, at this point, the whole file[...] retrieval deserves it's own function.
lLyrics/LocalParser.py
Outdated
try: | ||
out = file["LYRICS"] | ||
except: | ||
pass | ||
try: | ||
out = file["UNSYNCEDLYRICS"] | ||
except: | ||
pass |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same.
lLyrics/LocalParser.py
Outdated
try: | ||
out = file["LYRICS"] | ||
except: | ||
pass | ||
try: | ||
out = file["UNSYNCEDLYRICS"] | ||
except: | ||
pass |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is weird. In case both indexing operations succeed, second would just overwrite the variable. If they are mutually exclusive, could you explicitly mark them as such, please?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nope, you are right
lLyrics/LocalParser.py
Outdated
@@ -0,0 +1,123 @@ | |||
# -*- coding: utf-8 -*- |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder, is it still relevant in 2020, after Python-2's demise?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep, it's useless. I just copied the template from another parser.
@@ -94,7 +95,7 @@ | |||
LYRICS_ARTIST_REPLACE = [("/", "-"), (" & ", " and ")] | |||
|
|||
LYRICS_SOURCES = ["Lyricwiki.org", "Letras.terra.com.br", "Metrolyrics.com", "AZLyrics.com", "Lyricsmania.com", | |||
"Vagalume.com.br", "Genius.com", "Darklyrics.com", "Chartlyrics.com"] | |||
"Vagalume.com.br", "Genius.com", "Darklyrics.com", "Chartlyrics.com", "Local File"] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there any i18n opportunity for plugins?
# along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
|
||
import urllib | ||
import os.path as path |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FWIW there's a modern pathlib out there, but otherwise it's not really much different.
lLyrics/LocalParser.py
Outdated
elif path.isfile(dir + self.title + ".lyric"): | ||
return open(dir + self.title + ".lyric") | ||
else: | ||
return "" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So, this function returns either opened file object or a string. Sounds a little bit off. Better return None
as usual, and check for it via is
operator. Return type will be Optional[file]
(well, kind of — since the open's real type would be _io._IOBase
or its derivative).
Thanks for the feedback! I'll rewrite it and update it. No idea about how the translation stuff works, but I'll look into it. |
I have looked into the translation stuff and it should be easy to do. Can't update any of them tho. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's definitely going somewhere the right way! Just few more nits, if you please.
lLyrics/LocalParser.py
Outdated
@@ -0,0 +1,105 @@ | |||
# Parses lyrics from a .lyric or .lrc file or from the tags of the song |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't get it why this repository has no global LICENSE file, or why GPL text is fragmented via blank lines like that, but one thing is for sure: doc comments should be separate, inside triple double quotes and come after license text.
Also, lets call it "track" instead of "song". Even audio books and podcasts have 'lyrics' in them sometimes.
# Parses lyrics from a .lyric or .lrc file or from the tags of the song | |
""" | |
Parses lyrics from a .lyric or .lrc file or from the tags of the track. | |
""" |
lLyrics/LocalParser.py
Outdated
def __init__(self, artist, title, song_path): | ||
self.artist = artist | ||
self.title = title | ||
self.lyrics = "" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unused member self.lyrics
.
lLyrics/LocalParser.py
Outdated
# This only checks for .lrc or .lyric files with the same name as the song or with the same "cleaned" name as | ||
# the song. If you have files in any other format, please add it to this function. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Doc comments
# This only checks for .lrc or .lyric files with the same name as the song or with the same "cleaned" name as | |
# the song. If you have files in any other format, please add it to this function. | |
""" | |
This only checks for .lrc or .lyric files with the same name as the song or with the same "cleaned" name as | |
the song. If you have files in any other format, please add it to this function. | |
""" |
lLyrics/LocalParser.py
Outdated
elif path.endswith("flac"): | ||
out = self.get_flac_lyrics(path) | ||
if out is None: | ||
file = self.check_for_file(dir, file_name) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Name suggests it only checks, but in fact it opens a path and returns opened file. Since open
calls are not guarded anyway, wouldn't it make more sense to return a string path here, and call open
only once?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah returning open() is kinda sketchy anyway.
lLyrics/LocalParser.py
Outdated
out = "" | ||
for line in file.readlines(): | ||
out += line | ||
file.close() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No need to read line-by-line, and no need to manually close it with
this syntax:
file.close() | |
with open(path) as file: | |
out = file.read() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
neat! Didn't know you could do that.
Thanks again for your time and feedback! |
Hi, @dmo60. I think this is ready to squash & merge. Do you think you can take a look? |
@dmo60 Sorry to bump you on this, but it is kind of stagnating. Is there anything blocking from merge & release? Alternatively, you could add me as a maintainer. I am skillful with Python and many other stuff, and I got a load of free time lately. |
@dmo60 Hello, any news for merging this into master? |
The user can select "Local File" as a source, which will fetch lyrics from the song's metadata (mp3, ogg, opus and flac only) or from a .lrc or .lyric file with the same filename in the same path.
Also edited the README to mention the use of the mutagen library.