Skip to content

Commit

Permalink
Add Gyazo direct image url option
Browse files Browse the repository at this point in the history
  • Loading branch information
migueldemoura committed Dec 4, 2018
1 parent 4c4fe88 commit f964833
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 3 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ If an external file is found, Myazo extends the default config with the provided
| Key | Default | Description |
|--------------------|----------------------------------------|-----------------------------------------------------|
| gyazo_server | False | Controls whether to use Gyazo's servers |
| gyazo_direct_link | True | Controls whether to open Gyazo direct image url |
| upload_script | 'https://myazo.example.com/upload.php' | Full path to the upload.php file |
| secret | 'hunter2' | Secret token |
| clear_metadata | True | Controls clearing screenshot metadata before upload |
Expand Down
1 change: 1 addition & 0 deletions client/config.ini.example
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
[Myazo]
gyazo_server = False
gyazo_direct_link = True
upload_script = https://myazo.example.com/upload.php
secret = hunter2
clear_metadata = True
Expand Down
12 changes: 9 additions & 3 deletions client/myazo.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#!/usr/bin/env python3

from configparser import ConfigParser
from pathlib import Path
from subprocess import run
import os
import platform
Expand All @@ -15,6 +16,7 @@
config = ConfigParser()
config.read_dict({'Myazo': {
'gyazo_server': False, # If True, upload_script and secret are ignored
'gyazo_direct_link': True, # Ignored if gyazo_server is False
'upload_script': 'https://myazo.example.com/upload.php',
'secret': 'hunter2',
'clear_metadata': True,
Expand Down Expand Up @@ -68,7 +70,6 @@
img = open(tmp_file, 'rb')

if config.get('gyazo_server'):
# If an error occurred, it'll output an error image url
r = requests.post(
'https://upload.gyazo.com/upload.cgi',
files={'imagedata': img}
Expand All @@ -84,7 +85,12 @@
print('Error: Failed to upload screenshot. Server returned status code {}.'.format(r.status_code))
exit(-2)

url = r.text
if config.get('gyazo_server') and config.get('gyazo_direct_link'):
# Convert the Gyazo link to a direct image
# https://gyazo.com/hash > https://i.gyazo.com/hash.extension
url = r.text.replace('//', '//i.') + Path(tmp_file).suffix
else:
url = r.text

if config.getboolean('open_browser'):
webbrowser.open(url)
Expand All @@ -94,4 +100,4 @@
print(url)

img.close()
os.remove(tmp_file)
os.remove(tmp_file)

0 comments on commit f964833

Please sign in to comment.