jsaddiction / TrailerTech

Download Trailers for you movies
MIT License
13 stars 4 forks source link

downloadApple() gets stuck at times #19

Closed cgomesu closed 3 years ago

cgomesu commented 3 years ago

I'm not sure if it's a rate limit thing by apple or a local connectivity issue but downloadApple() will get stuck at times. I noticed that you're using .iter_content with the Apple downloader that might have something to do with this. youtube-dl seems to know how to handle this because I've not noticed any issues there. Maybe we could add a timeout to each request? Just adding here for future reference. Have you noticed this behavior before?

jsaddiction commented 3 years ago

I've not noticed the behavior you are referring to. When you say stuck, what exactly are you seeing?

cgomesu commented 3 years ago

Last message that shows up is "Attempting to download video at (...). Please wait...". I did not debug it but I'm pretty sure it's related to the following code block in the downloader.py file:

    def downloadApple(self, fileName, destinationDirectory, link):
        log.info('Attempting to download video at "{}". Please Wait...'.format(link))
        tempPath = os.path.join(DL_DIRECTORY, fileName)
        destinationPath = os.path.join(destinationDirectory, fileName)
        headers = {'User-Agent': 'Quick_time/7.6.2'}
        r = requests.get(link, stream=True, headers=headers)
        with open(tempPath, 'wb') as f:
            for chunk in r.iter_content(chunk_size=1024): 
                if chunk: # filter out keep-alive new chunks
                    f.write(chunk)
                    f.flush()
        if r.status_code == 200:
            self._moveTo(tempPath, destinationPath)
            return True
        else:
            log.warning('Failed to download from {}.'.format(link))
            return False

I should be able to debug this over the next weekend and come back to you with a more detailed description of the issue then.

jsaddiction commented 3 years ago

Fixed by pull request #20

cgomesu commented 3 years ago

Just tested the changes you've made and can confirm that the issue was solved. Thanks, @jsaddiction ! I'm gonna leave the program running this week and will let you know if I notice anything unusual.

jsaddiction commented 3 years ago

Awesome! thanks for testing @cgomesu If you encounter any other issues we can reopen this issue and continue troubleshooting