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

Proposal for Limiting files under 10M, minor formatting change. #2

Closed
wants to merge 2 commits into from

Conversation

wagerpascal
Copy link

I found a possible solution that is also in the OS library at http://stackoverflow.com/questions/8626325/most-efficient-way-to-delete-a-file-if-its-below-a-certain-size that may be able to limit the file size to only above 10M.

Haven't been able to test it (see #1 ).

@mysteriouss
Copy link

mysteriouss commented Apr 29, 2016

HTTP has its own HEAD method to receive the content size of future responses, e.g.

curl -X HEAD 'http://m2.music.126.net/0h5rupavV0az1vzVuChHtQ==/1223756441722122.mp3'
curl: (18) transfer closed with 5662737 bytes remaining to read

however may not be strictly followed.

@@ -55,6 +55,8 @@
songname = d["data"]["songList"][0]["songName"]
artistName = d["data"]["songList"][0]["artistName"]
filename = "./" + songdir + "/"+songname+"-"+artistName+".flac"
if os.path.getsize(filename) < 10000 * 1024: #Source from http://stackoverflow.com/questions/8626325/most-efficient-way-to-delete-a-file-if-its-below-a-certain-size
Copy link
Owner

@atlas-comstock atlas-comstock Apr 30, 2016

Choose a reason for hiding this comment

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

The position of this code is not right.
We should check the file size and delete it after downloading.
Thank you for you pull request. :P

Copy link
Author

Choose a reason for hiding this comment

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

Moved it to the bottom.

Sorry about the delay, I took a look again and think it should go after code.write(f.read())?
@atlas-comstock
Copy link
Owner

@wagerpascal Hi, your commit is conflict now. Could you please make a new patch according the new main.py? If you are busy, I can do that for you.

@wagerpascal wagerpascal closed this May 3, 2016
@atlas-comstock
Copy link
Owner

@mysteriouss You are right. See this commit: 2f20433#diff-5bc02cefb3ea9e27f1a6776eabd1935dR65

  •    headers = requests.head(songlink).headers
    
    •    size = int(headers['Content-Length']) / (1024 *\* 2)
      
      Thank you :)

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.

3 participants