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

Improvement: use file extension if filetype.guess fails #73

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions instapy_cli/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,9 +138,10 @@ def upload(self, file, caption='', story=False):


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')
# 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'
Expand Down
15 changes: 10 additions & 5 deletions instapy_cli/media.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,20 @@ def __init__(self, file, ratio='post'):
# if file is a local file
else:
self.media_path = file

self.check_type()

def check_type(self):
self.media_ext = filetype.guess(self.media_path).extension

ext = filetype.guess(self.media_path)
if None is self.media_ext:
absolute_path = os.path.abspath(self.media_path)
self.media_ext = os.path.splitext(absolute_path)[-1].replace(".", "")
else:
self.media_ext = ext.extension

def is_image(self):
return True if self.media_ext in ['jpg', 'png', 'gif'] else False
Copy link

Choose a reason for hiding this comment

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

This will fail on .jpeg filetypes if using the fallback. Could do this:

Suggested change
return True if self.media_ext in ['jpg', 'png', 'gif'] else False
return True if self.media_ext in ['jpg', 'jpeg', 'png', 'gif'] else False


def is_video(self):
return True if self.media_ext in ['mp4', 'mov', 'avi'] else False

Expand Down