Skip to content

Conversation

@devalnor
Copy link
Contributor

Fix issue #166
Inspired from youtube-dl
Not tested on Windows but it work on OSX and probably on Unix based system.

Fix issue scdl-org#166
Inspired from youtube-dl
Not tested on Windows but it work on OSX and probably on Unix based system.
@flyingrub
Copy link
Collaborator

Hi ! thanks for your PR ! Unfortunately your patch is crashing on my laptop.

Traceback (most recent call last):
  File "/usr/bin/scdl", line 11, in <module>
    load_entry_point('scdl==1.6.6', 'console_scripts', 'scdl')()
  File "/usr/lib/python3.6/site-packages/scdl-1.6.6-py3.6.egg/scdl/scdl.py", line 159, in main
  File "/usr/lib/python3.6/site-packages/scdl-1.6.6-py3.6.egg/scdl/scdl.py", line 236, in parse_url
  File "/usr/lib/python3.6/site-packages/scdl-1.6.6-py3.6.egg/scdl/scdl.py", line 463, in download_track
NameError: name 'datetime' is not defined

scdl/scdl.py Outdated
logger.debug(e)
else:
logger.error("This type of audio doesn't support tagging...")

Copy link
Collaborator

Choose a reason for hiding this comment

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

You have trailing whitespace here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh! My bad. It's totally unprofessional.
My first and last time I submit patch directly with the github editor code.
Specially when it's late in the night >_<

logger.info('\nTrack n°{0}'.format(counter))
download_track(track)

def try_utime(path, filetime):
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why are you wrapping this in a try catch ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The idea was inspired from youtube-dl.

But in general using a try catch will prevent breaking change of your code. And like I said I did not test it on Windows.

scdl/scdl.py Outdated
audio['COMM'] = mutagen.id3.COMM(encoding=3, text=track['description'])
audio['TYER'] = mutagen.id3.TYER(encoding=3, text=track['created_at'][:4])
audio['WOAS'] = mutagen.id3.WOAS(url=track['permalink_url'])

Copy link
Collaborator

Choose a reason for hiding this comment

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

Trailing whitespace.


#Try to change the real creation date
created_at = track['created_at']
filetime = int(time.mktime(datetime.strptime(created_at, '%Y/%m/%d %H:%M:%S %z').timetuple()))
Copy link
Collaborator

Choose a reason for hiding this comment

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

datetime doesn't seem initialized.

Copy link
Collaborator

Choose a reason for hiding this comment

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

You can have a look at 0736cb0#diff-834ccb1f68cfeac6d63b0b550a320ba0R467 for inspiration

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Missing import.
from datetime import datetime

scdl/scdl.py Outdated
#Try to change the real creation date
created_at = track['created_at']
filetime = int(time.mktime(datetime.strptime(created_at, '%Y/%m/%d %H:%M:%S %z').timetuple()))
try_utime(os.path.join(os.getcwd(), filename),filetime)
Copy link
Collaborator

Choose a reason for hiding this comment

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

You can use relative path here :)
try_utime(filename, filetime)

@flyingrub
Copy link
Collaborator

There is still trailing whitespace. Also the id3 tag editing doesn't seems to work. You can have a look at #147.

Copy link
Contributor Author

@devalnor devalnor left a comment

Choose a reason for hiding this comment

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

Tested and working well on OSX.
You can check ID3 tags results with eyed3 (nice tool btw)


#Try to change the real creation date
created_at = track['created_at']
filetime = int(time.mktime(datetime.strptime(created_at, '%Y/%m/%d %H:%M:%S %z').timetuple()))
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Missing import.
from datetime import datetime

else:
logger.error('Artwork can not be set.')
audio.save()
audio.save(v2_version=3)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Changed TagID to 2.3 instead of 2.4.
More stable and fix the date issue:
https://stackoverflow.com/questions/18026516/some-mutagen-tags-dont-work

shutil.copyfileobj(response.raw, out_file)
out_file.seek(0)

track_date = datetime.strptime(track['created_at'], "%Y/%m/%d %H:%M:%S %z")
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Inspired from @sublimo's fork.

@flyingrub
Copy link
Collaborator

@flyingrub
Copy link
Collaborator

Audio source URL: b'http://soundcloud.com/le_lab/digital-harmonic\x00'

You need to add .encode('utf8') to the string there.

@devalnor
Copy link
Contributor Author

Audio source URL are not encode in utf-8 why do you want to do that?

@flyingrub
Copy link
Collaborator

flyingrub commented Aug 20, 2017

The string is a python bytecode object. That's why there is a b'...'

@devalnor
Copy link
Contributor Author

@flyingrub after testing, I can't reproduce your issue.
If I encode the string in utf8 like you suggest by doing track['permalink_url'].encode('utf8'), eyeD3 return Audio source URL: b'http://soundcloud.com/...' but without I have a correct string Audio source URL: http://soundcloud.com/...

Is there something that I missing or can you explain me more the issue?

@flyingrub
Copy link
Collaborator

OK. So I was using eyeD3 with python3 and it seems that it doesn't support well the encoding when it run on python3. After using it on python2 it works well.

@flyingrub flyingrub closed this Aug 30, 2017
@flyingrub flyingrub reopened this Aug 30, 2017
@flyingrub flyingrub merged commit 7bde733 into scdl-org:master Aug 30, 2017
@devalnor devalnor deleted the patch-1 branch September 1, 2017 10:29
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.

2 participants