Skip to content

Commit

Permalink
Change config method
Browse files Browse the repository at this point in the history
  • Loading branch information
vitiko98 committed Nov 2, 2020
1 parent 5295777 commit 700adc6
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 54 deletions.
12 changes: 5 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,10 @@ pip3 install -r requirements.txt --user
pip3 install windows-curses
pip3 install -r requirements.txt
```
#### Add your credentials to `config.json`
```json
{
"email": "",
"password": ""
}
#### Add your credentials to `config.py`
```python
email = "[email protected]"
password = "your_password"
```
#### Run Qobuz-DL
##### Linux / MAC OS
Expand All @@ -53,7 +51,7 @@ optional arguments:
-i run Qo-Dl-curses on URL input mode
-q int quality (5, 6, 7, 27) (default: 6) [320, LOSSLESS, 24B <96KHZ, 24B >96KHZ]
-l int limit of search results by type (default: 10)
-d PATH custom directory for downloads
-d PATH custom directory for downloads (default: 'Qobuz Downloads')
```
## A note about Qo-DL
`Qobuz-DL` is inspired in the discontinued Qo-DL-Reborn. This program uses two modules from Qo-DL: `qopy` and `spoofer`, both written by Sorrow446 and DashLt.
Expand Down
4 changes: 0 additions & 4 deletions config.json

This file was deleted.

13 changes: 13 additions & 0 deletions config.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Qobuz credentials (Don't remove the quotes!)
email = "[email protected]"
password = "your_password"

# Default folder where the releases are downloaded
default_folder = "Qobuz Downloads"

# Default per type results limit
default_limit = 10

# Default quality for url input mode. This will be ignored in interactive mode
# (5, 6, 7, 27) [320, LOSSLESS, 24B <96KHZ, 24B >96KHZ]
default_quality = 6
60 changes: 23 additions & 37 deletions main.py
Original file line number Diff line number Diff line change
@@ -1,48 +1,46 @@
import argparse
import itertools
import json
import os
import re
import sys

from pick import pick

from qo_utils import qopy
from qo_utils import downloader
import config
from qo_utils import downloader, qopy
from qo_utils.search import Search


def getArgs():
parser = argparse.ArgumentParser(prog="python3 main.py")
parser.add_argument("-a", action="store_true", help="enable albums-only search")
parser.add_argument(
"-i", action="store_true", help="run Qo-Dl-curses on URL input mode"
"-i",
metavar="Album/track URL",
help="run Qobuz-Dl on URL input mode (download by url)",
)
parser.add_argument(
"-q", metavar="int", default=6, help="quality (5, 6, 7, 27) (default: 6)"
"-q",
metavar="int",
default=config.default_quality,
help="quality for url input mode (5, 6, 7, 27) (default: 6)",
)
parser.add_argument(
"-l",
metavar="int",
default=10,
default=config.default_limit,
help="limit of search results by type (default: 10)",
)
parser.add_argument(
"-d",
metavar="PATH",
default="Qobuz Downloads",
help="custom directory for downloads",
default=config.default_folder,
help="custom directory for downloads (default: '{}')".format(
config.default_folder
),
)
return parser.parse_args()


def getSession():
print("Logging...")
with open("config.json") as f:
config = json.load(f)
return qopy.Client(config["email"], config["password"])


def musicDir(dir):
fix = os.path.normpath(dir)
if not os.path.isdir(fix):
Expand All @@ -64,19 +62,16 @@ def searchSelected(Qz, path, albums, ids, types, quality):
quality = q[quality[1]]
for alb, id_, type_ in zip(albums, ids, types):
for al in alb:
if type_[al[1]]:
downloader.iterateIDs(Qz, id_[al[1]], path, quality, True)
else:
downloader.iterateIDs(Qz, id_[al[1]], path, quality, False)
downloader.iterateIDs(
Qz, id_[al[1]], path, quality, True if type_[al[1]] else False
)


def fromUrl(Qz, path, link, quality):
if "/track/" in link:
id = get_id(link)
downloader.iterateIDs(Qz, id, path, quality, False)
else:
id = get_id(link)
downloader.iterateIDs(Qz, id, path, quality, True)
id = get_id(link)
downloader.iterateIDs(
Qz, id, path, str(quality), False if "/track/" in link else True
)


def interactive(Qz, path, limit, tracks=True):
Expand Down Expand Up @@ -118,23 +113,14 @@ def interactive(Qz, path, limit, tracks=True):
sys.exit("\nBye")


def inputMode(Qz, path, quality):
while True:
try:
link = input("\nAlbum/track URL: [Ctrl + c to quit]\n- ")
fromUrl(Qz, path, link, quality)
except KeyboardInterrupt:
sys.exit("\nBye")


def main():
arguments = getArgs()
directory = musicDir(arguments.d) + "/"
Qz = getSession()
Qz = qopy.Client(config.email, config.password)
if not arguments.i:
interactive(Qz, directory, arguments.l, not arguments.a)
else:
inputMode(Qz, directory, arguments.q)
fromUrl(Qz, directory, arguments.i, arguments.q)


if __name__ == "__main__":
Expand Down
8 changes: 2 additions & 6 deletions qo_utils/qopy.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,8 @@
import requests

from qo_utils import spoofbuz
from qo_utils.exceptions import (
AuthenticationError,
IneligibleError,
InvalidAppIdError,
InvalidAppSecretError,
)
from qo_utils.exceptions import (AuthenticationError, IneligibleError,
InvalidAppIdError, InvalidAppSecretError)


class Client:
Expand Down

0 comments on commit 700adc6

Please sign in to comment.