Add parser for reading from the song's tags or from a local .lrc/.lyric file#79
Add parser for reading from the song's tags or from a local .lrc/.lyric file#79alpemwarrior wants to merge 5 commits into
Conversation
or from the metadata of the file. Supports mp3, ogg, opus and flac formats
…of the mutagen module.
| try: | ||
| out = file["LYRICS"] | ||
| except: | ||
| pass | ||
| try: | ||
| out = file["UNSYNCEDLYRICS"] | ||
| except: | ||
| pass |
There was a problem hiding this comment.
same.
You know, at this point, the whole file[...] retrieval deserves it's own function.
| try: | ||
| out = file["LYRICS"] | ||
| except: | ||
| pass | ||
| try: | ||
| out = file["UNSYNCEDLYRICS"] | ||
| except: | ||
| pass |
| try: | ||
| out = file["LYRICS"] | ||
| except: | ||
| pass | ||
| try: | ||
| out = file["UNSYNCEDLYRICS"] | ||
| except: | ||
| pass |
There was a problem hiding this comment.
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?
| @@ -0,0 +1,123 @@ | |||
| # -*- coding: utf-8 -*- | |||
There was a problem hiding this comment.
I wonder, is it still relevant in 2020, after Python-2's demise?
There was a problem hiding this comment.
Yep, it's useless. I just copied the template from another parser.
|
|
||
| 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.
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.
FWIW there's a modern pathlib out there, but otherwise it's not really much different.
| elif path.isfile(dir + self.title + ".lyric"): | ||
| return open(dir + self.title + ".lyric") | ||
| else: | ||
| return "" |
There was a problem hiding this comment.
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. |
ratijas
left a comment
There was a problem hiding this comment.
That's definitely going somewhere the right way! Just few more nits, if you please.
| @@ -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.
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. | |
| """ |
| def __init__(self, artist, title, song_path): | ||
| self.artist = artist | ||
| self.title = title | ||
| self.lyrics = "" |
| # 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.
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. | |
| """ |
| 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.
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.
yeah returning open() is kinda sketchy anyway.
| out = "" | ||
| for line in file.readlines(): | ||
| out += line | ||
| file.close() |
There was a problem hiding this comment.
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.
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? |
|
dang i sure wish i had read the merge requests before duplicating all that effort lmao. and at the end of it all mine is worse and coded more poorly |
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.