-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
IMAGES = IMAGE_QUALITY =
- Loading branch information
Showing
10 changed files
with
239 additions
and
49 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,12 +16,13 @@ | |
author="tharindu.dev", | ||
author_email="[email protected]", | ||
url="https://github.com/truethari/thumb-gen", | ||
keywords="thumbnails video screenshot", | ||
license='MIT', | ||
project_urls={ | ||
"Bug Tracker": "https://github.com/truethari/thumb-gen/issues", | ||
}, | ||
classifiers=[ | ||
"Programming Language :: Python :: 3", | ||
"Programming Language :: Python :: 3.6", | ||
], | ||
packages=['thumb_gen'], | ||
include_package_data=True, | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,82 @@ | ||
IMAGES = 12 | ||
IMAGE_QUALITY = 100 | ||
import os | ||
import sys | ||
import pathlib | ||
import configparser | ||
|
||
def get_datadir() -> pathlib.Path: | ||
|
||
""" | ||
Returns a parent directory path | ||
where persistent application data can be stored. | ||
# linux: ~/.local/share | ||
# macOS: ~/Library/Application Support | ||
# windows: C:/Users/<USER>/AppData/Roaming | ||
""" | ||
|
||
home = pathlib.Path.home() | ||
|
||
if sys.platform == "win32": | ||
return home / "AppData/Roaming" | ||
elif sys.platform == "linux": | ||
return home / ".local/share" | ||
elif sys.platform == "darwin": | ||
return home / "Library/Application Support" | ||
|
||
def create_config(IMAGES=12, IMAGE_QUALITY=80): | ||
my_datadir = get_datadir() / "thumb-gen" | ||
|
||
try: | ||
my_datadir.mkdir(parents=True) | ||
|
||
except FileExistsError: | ||
pass | ||
|
||
finally: | ||
configfile_path = str(my_datadir) + "/config.ini" | ||
config_object = configparser.ConfigParser() | ||
config_object["DEFAULT"] = {"images": IMAGES, "image_quality": IMAGE_QUALITY} | ||
with open(configfile_path, 'w') as conf: | ||
config_object.write(conf) | ||
|
||
return True | ||
|
||
def modify_config(options, value_1, value_2=0): | ||
my_datadir = get_datadir() / "thumb-gen" | ||
configfile_path = str(my_datadir) + "/config.ini" | ||
config_object = configparser.ConfigParser() | ||
|
||
config_object.read(configfile_path) | ||
userinfo = config_object["DEFAULT"] | ||
|
||
if options == "images_image_quality": | ||
userinfo["images"] = str(value_1) | ||
userinfo["image_quality"] = str(value_2) | ||
elif options == "images": | ||
userinfo["images"] = str(value_1) | ||
elif options == "image_quality": | ||
userinfo["image_quality"] = str(value_1) | ||
|
||
with open(configfile_path, 'w') as conf: | ||
config_object.write(conf) | ||
|
||
return True | ||
|
||
def read_config(option): | ||
my_datadir = get_datadir() / "thumb-gen" | ||
configfile_path = str(my_datadir) + "/config.ini" | ||
config_object = configparser.ConfigParser() | ||
|
||
if os.path.isfile(configfile_path): | ||
config_object.read(configfile_path) | ||
default = config_object["DEFAULT"] | ||
else: | ||
create_config_return = create_config() | ||
if create_config_return: | ||
config_object.read(configfile_path) | ||
default = config_object["DEFAULT"] | ||
|
||
if option == 'images': | ||
return int(default['images']) | ||
elif option == 'image_quality': | ||
return int(default['image_quality']) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.