Example #1
0
    def download_image(self, image):
        def action():
            image_path = os.path.join(self.temp_dir, image.temp_filename)
            logger.info('Downloading {0}'.format(image.url))
            with closing(requests.get(image.url, stream=True)) as response:
                assert response.headers['Content-Type'] == 'image/jpeg', \
                    'Wrong image Content-Type: {0}'.format(response.headers['Content-Type'])
                stream_download(image_path, response)

        retry_action(action)
Example #2
0
    def download_image(self, image):
        def action():
            image_path = os.path.join(self.temp_dir, image.temp_filename)
            logger.info('Downloading {0}'.format(image.url))
            with closing(requests.get(image.url, stream=True)) as response:
                assert response.headers['Content-Type'] == 'image/jpeg', \
                    'Wrong image Content-Type: {0}'.format(response.headers['Content-Type'])
                stream_download(image_path, response)

        retry_action(action)
Example #3
0
    def download_goodie(self, goodie):
        def action():
            goodie_path = os.path.join(self.temp_dir, goodie.temp_filename)
            logger.info('Downloading {0}'.format(goodie.url))
            with closing(requests.get(goodie.url, stream=True)) as response:
                assert response.headers['Content-Type'] == 'application/{0}'.format(
                    goodie.extension), \
                    'Wrong goodie Content-Type: {0}'.format(response.headers['Content-Type'])
                stream_download(goodie_path, response)

        retry_action(action)
Example #4
0
    def download_goodie(self, goodie):
        def action():
            goodie_path = os.path.join(self.temp_dir, goodie.temp_filename)
            logger.info('Downloading {0}'.format(goodie.url))
            with closing(requests.get(goodie.url, stream=True)) as response:
                assert response.headers['Content-Type'] == 'application/{0}'.format(
                    goodie.extension), \
                    'Wrong goodie Content-Type: {0}'.format(response.headers['Content-Type'])
                stream_download(goodie_path, response)

        retry_action(action)
Example #5
0
    def upload_spectral(self, track):
        if hasattr(track, 'spectral_url'):
            return track.spectral_url
        spectral_path = self.manager.get_filenames(track)[1]
        resp = []

        def do_upload():
            resp.append(self.imgur_client.upload_from_path(q_enc(spectral_path)))

        retry_action(do_upload)
        track.spectral_url = resp[0]['link']
        return track.spectral_url
Example #6
0
    def upload_spectral(self, track):
        if hasattr(track, 'spectral_url'):
            return track.spectral_url
        spectral_path = self.manager.get_filenames(track)[1]
        resp = []

        def do_upload():
            resp.append(
                self.imgur_client.upload_from_path(q_enc(spectral_path)))

        retry_action(do_upload)
        track.spectral_url = resp[0]['link']
        return track.spectral_url
Example #7
0
    def download_track(self, track):
        def action():
            track_path = os.path.join(self.temp_dir, track.temp_filename)
            logger.debug('Getting track {0} download URL'.format(track.id))
            logger.info('Downloading {0}'.format(track.url))
            if 'wimpmusic' in track.url or 'compute-1.amazonaws.com' in track.url:
                stream_reconstruct_download(track_path, track.url)
            else:
                with closing(requests.get(track.url, stream=True)) as response:
                    assert response.headers['Content-Type'] == 'audio/flac', \
                        'Wrong track Content-Type: {0}'.format(response.headers['Content-Type'])
                    stream_download(track_path, response)

        retry_action(action)
Example #8
0
    def download_track(self, track):
        def action():
            track_path = os.path.join(self.temp_dir, track.temp_filename)
            logger.debug('Getting track {0} download URL'.format(track.id))
            logger.info('Downloading {0}'.format(track.url))
            if 'wimpmusic' in track.url or 'compute-1.amazonaws.com' in track.url:
                stream_reconstruct_download(track_path, track.url)
            else:
                with closing(requests.get(track.url, stream=True)) as response:
                    assert response.headers['Content-Type'] == 'audio/flac', \
                        'Wrong track Content-Type: {0}'.format(response.headers['Content-Type'])
                    stream_download(track_path, response)

        retry_action(action)