Skip to content

Commit

Permalink
Merge pull request #19 from Parth-Vader/guidir
Browse files Browse the repository at this point in the history
GUI for selecting directory added
  • Loading branch information
Parth-Vader committed Dec 2, 2017
2 parents c35496d + c1165ae commit 49706fb
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 13 deletions.
27 changes: 14 additions & 13 deletions moboff.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,11 @@
import subprocess
import json
import click
from utils import select_directory

real_path_of_MobOff = os.path.dirname(os.path.realpath(__file__))


@click.group()
def cli():
"""A command line tool to download, convert
Expand Down Expand Up @@ -56,14 +58,15 @@ def download(link, newdevice, video, delete):
data = json.load(json_file)
api_key = data['user']['api_key']
device = data['user']['device']
directory = data['user']['directory']
else:
click.secho(
"Please run `moboff initialise` first.",
fg='red',
bold=True)
quit()

os.chdir('Music')
os.chdir(directory)

if video is True:
downloadcommand = ["youtube-dl",
Expand Down Expand Up @@ -152,23 +155,21 @@ def initialise():

for i, device in enumerate(pb.devices, 1):
print("{0} : {1}".format(i, device))

device_id = int(rawinput()) - 1

os.chdir(real_path_of_MobOff)
if not os.path.exists('Music'):
os.makedirs('Music')
click.secho(
"The music would be downloaded to {0}/Music".format(os.getcwd()))
click.secho("Please Select a directory for store the Downloads", bold=True)
directory = select_directory()

click.secho("The music would be downloaded to {0}".format(directory))

data = {
'user': {
'api_key': api_key,
'device': str(pb.devices[device_id]),
}
}
'user': {
'api_key': api_key,
'device': str(pb.devices[device_id]),
'directory': directory,
}
}
with open('moboff_cfg.json', 'w') as outfile:
json.dump(data, outfile)

Expand Down
12 changes: 12 additions & 0 deletions utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
try:
from Tkinter import Tk
import tkFileDialog as filedialog
except ImportError:
from tkinter import Tk, filedialog


def select_directory():
root = Tk()
root.withdraw()
current_directory = filedialog.askdirectory()
return current_directory

0 comments on commit 49706fb

Please sign in to comment.