Esempio n. 1
0
    def upload(self, file, caption=''):
        media = Media(file)
        path = media.getPath()

        try:
            media_id = self._session.upload_photo(path)
            self._session.configure_photo(media_id, caption)
        finally:
            pass
Esempio n. 2
0
    def upload(self, file, caption='', story=False):
        upload_completed = True
        media = Media(file)

        res = None
        try:

            if media.is_image():
                image_data, image_size = media.prepare(story)
                # print('image size: {} with ratio of: {}'.format(image_size, image_size[0]/image_size[1]))
                if story:
                    res = self.client.post_photo_story(image_data, image_size)
                else:
                    res = self.client.post_photo(image_data,
                                                 image_size,
                                                 caption=caption)
            elif media.is_video():
                video_data, video_size, video_duration, video_thumbnail = media.prepare(
                    story)
                if story:
                    res = self.client.post_video_story(video_data, video_size,
                                                       video_duration,
                                                       video_thumbnail)
                else:
                    res = self.client.post_video(video_data,
                                                 video_size,
                                                 video_duration,
                                                 video_thumbnail,
                                                 caption=caption)
            else:
                raise Exception(
                    'Media is not a recognized file type, use only images and videos.'
                )

            # print(res)

        except Exception as e:
            #   print('Error is >>\n    ' + str(e))
            #   print('\nSomething went bad.\nPlease retry or send an issue on https://github.com/b3nab/instapy-cli\n')
            upload_completed = False
            raise IOError(
                str(e),
                '\nSomething went bad.\nPlease retry or send an issue on https://github.com/b3nab/instapy-cli\n'
            )

        finally:
            # media_status = 'YES' if media.isDownloaded() else 'NO'
            # print('Media is a downloaded file? ' + media_status)
            if media.isDownloaded():
                media.removeMedia()
            if upload_completed:
                print('Done.')
            else:
                raise IOError("Unable to upload.")
            return res
Esempio n. 3
0
    def upload(self, file, caption=''):
        media = Media(file)
        path = media.getPath()
        upload_completed = True

        try:
            media_id = self._session.upload_photo(path)
            self._session.configure_photo(media_id, caption)
        except Exception as e:
            print('Error is >>\n    ' + str(e))
            print(
                '\nSomething went bad.\nPlease retry or send an issue on https://github.com/b3nab/instapy-cli\n'
            )
            upload_completed = False
        finally:
            if upload_completed:
                print('Done.')
            # media_status = 'YES' if media.isDownloaded() else 'NO'
            # print('Media is a downloaded file? ' + media_status)
            if media.isDownloaded():
                media.removeMedia()