Skip to content
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

Some changes to track parsing #1

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open

Conversation

NoMore201
Copy link
Collaborator

For explanation about commits, check the full commit message

Domenico Iezzi added 4 commits January 31, 2018 11:57
Tracks may have tracknumber and discnumber formatted as "x/y" where:

- x is the current track/disc number
- y is the total number of tracks/discs

For example this is the case for tracks downloaded from Google Play
Music. Now `parse_resource` function considers this particular case,
otherwise will stick with the normal behaviour
Since date tag inside tracks is a string, it can have any possible
value. Previous code tried to parse date as an integer, but for example
strings such as "2017-11-12 14:34" can't be cast to an integer value.

As a workaround, date is now parsed as is, and the application client
should handle its value as it sees fit
track_number = None
if total_tracks == "0":
total_tracks = None
if type(track_number) is str and len(track_number) == 1:
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use rjust to pad here, like: track_number.rjust(2, "0").

if disc_number == "0":
disc_number = None
if total_discs == "0":
total_discs = None
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why track_number is padded and disc_number is not?

@@ -101,8 +101,7 @@ def parse_resource(res, path):
res.track.isrc = parse('isrc', media.tags)

raw_date = parse('date', media.tags)
if raw_date not in [None, '']:
res.track.date = date(int(raw_date), 1, 1)
res.track.date = raw_date
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we just do some better parsing? Check out dateutil.parser.parse.

@n1zzo
Copy link
Owner

n1zzo commented Jan 31, 2018

Hi, I've reviewed some of your commits,
please give them a look!

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants