Ejemplo n.º 1
0
    def download_picasa_media(self):
        log.info(u'Downloading Picasa Only Files ...')
        # noinspection PyTypeChecker
        for media in DatabaseMedia.get_media_by_search(
                self._root_folder,
                self._db,
                media_type=MediaType.PICASA,
                start_date=self.startDate,
                end_date=self.endDate,
                skip_linked=True):
            if os.path.exists(media.local_full_path):
                continue

            log.info(u"Downloading %s ..." % media.local_full_path)
            tmp_path = os.path.join(media.local_folder, '.gphotos.tmp')

            if not os.path.isdir(media.local_folder):
                os.makedirs(media.local_folder)

            res = Utils.retry(5, urllib.urlretrieve, media.url, tmp_path)
            if res:
                os.rename(tmp_path, media.local_full_path)
                # set the access date to create date since there is nowhere
                # else to put it on linux (and is useful for debugging)
                os.utime(media.local_full_path, (Utils.to_timestamp(
                    media.modify_date), Utils.to_timestamp(media.create_date)))
            else:
                log.warning(u"WARNING: failed to download %s",
                            media.local_path)
Ejemplo n.º 2
0
    def download_drive_media(self):
        log.info(u'Downloading Drive Files ...')
        # noinspection PyTypeChecker
        for media in DatabaseMedia.get_media_by_search(
                self._root_folder,
                self._db,
                media_type=MediaType.DRIVE,
                start_date=self.startDate,
                end_date=self.endDate):
            if os.path.exists(media.local_full_path):
                if Utils.to_timestamp(media.modify_date) > \
                        os.path.getctime(media.local_full_path):
                    log.warning(u'{} was modified'.format(
                        media.local_full_path))
                else:
                    continue

            if not os.path.isdir(media.local_folder):
                os.makedirs(media.local_folder)
            temp_filename = os.path.join(self._root_folder, '.temp-photo')

            log.info(u'downloading {} ...'.format(media.local_full_path))
            f = self._googleDrive.CreateFile({'id': media.id})
            try:
                Utils.retry(10, f.GetContentFile, temp_filename)
                if os.path.exists(media.local_full_path):
                    os.remove(media.local_full_path)
                os.rename(temp_filename, media.local_full_path)
                # set the access date to create date since there is nowhere
                # else to put it on linux (and is useful for debugging)
                os.utime(media.local_full_path, (Utils.to_timestamp(
                    media.modify_date), Utils.to_timestamp(media.create_date)))
            except ApiRequestError:
                log.error(u'DOWNLOAD FAILURE for {}'.format(
                    media.local_full_path))