Initial Commit

This commit is contained in:
Thomas Dehaeze 2021-02-28 12:42:54 +01:00
commit 30c3419023
10 changed files with 169 additions and 0 deletions

2
.dockerignore Normal file
View File

@ -0,0 +1,2 @@
LICENSE*
README*

1
.gitignore vendored Normal file
View File

@ -0,0 +1 @@
docker-compose.yml

31
Dockerfile Normal file
View File

@ -0,0 +1,31 @@
FROM ubuntu:20.04
LABEL maintainer="Dehaeze Thomas <dehaeze.thomas@gmail.com>"
ENV \
QOBUZ_NAME="" \
QOBUZ_PASS="" \
PUID="" \
PGID=""
RUN \
groupadd -g 1000 appuser && \
useradd -r -u 1000 -g appuser appuser
RUN \
echo "**** install runtime packages ****" && \
apt-get update && \
apt-get install -y --no-install-recommends \
python3.4 \
python3-pip
WORKDIR /app
RUN pip3 install --upgrade qobuz-dl CherryPy
COPY index.html index.html
COPY main.py main.py
ADD public public
CMD [ "python3", "main.py"]

22
LICENSE Normal file
View File

@ -0,0 +1,22 @@
The MIT License (MIT)
Copyright (c) 2017 Muninn
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

0
README.md Normal file
View File

View File

@ -0,0 +1,10 @@
version: '3'
services:
qobuz:
image: docker-qobuz
ports:
- 8080:8080
environment:
- QOBUZNAME=name@gmail.com
- QOBUZPASS=password123
restart: unless-stopped

16
index.html Normal file
View File

@ -0,0 +1,16 @@
<!DOCTYPE html>
<html>
<head>
<link href="static/style.css" rel="stylesheet">
<script src="http://code.jquery.com/jquery-2.0.3.min.js"></script>
<script type="text/javascript" src="static/script.js"></script>
</head>
<body>
<div id="form">
<input type="text" value="" name="url"/>
<button id="download">Download</button>
</div>
<div id="logoutput">
</div>
</body>
</html>

58
main.py Normal file
View File

@ -0,0 +1,58 @@
import os, os.path
import logging
from io import StringIO
import cherrypy
from qobuz_dl.core import QobuzDL
email = os.environ['QOBUZNAME']
password = os.environ['QOBUZPASS']
log_stream = StringIO()
log_handler = logging.StreamHandler(log_stream)
logger = logging.getLogger('qobuz_dl')
logger.setLevel(logging.INFO)
for handler in logger.handlers:
logger.removeHandler(handler)
logger.addHandler(log_handler)
qobuz = QobuzDL(quality=7, directory='/downloads')
qobuz.get_tokens() # get 'app_id' and 'secrets' attrs
qobuz.initialize_client(email, password, qobuz.app_id, qobuz.secrets)
class Stringdownload(object):
@cherrypy.expose
def index(self):
return open('index.html')
@cherrypy.expose
class StringdownloadWebService(object):
@cherrypy.tools.accept(media='text/plain')
def GET(self):
return cherrypy.session['mystring']
def POST(self, url=''):
log_stream.truncate(0)
qobuz.handle_url(url)
return log_stream.getvalue()
if __name__ == '__main__':
conf = {
'/': {
'tools.sessions.on': True,
'tools.staticdir.root': os.path.abspath(os.getcwd())
},
'/download': {
'request.dispatch': cherrypy.dispatch.MethodDispatcher(),
'tools.response_headers.on': True,
'tools.response_headers.headers': [('Content-Type', 'text/plain')],
},
'/static': {
'tools.staticdir.on': True,
'tools.staticdir.dir': 'public'
}
}
webapp = Stringdownload()
webapp.download = StringdownloadWebService()
cherrypy.quickstart(webapp, '/', conf)

15
public/script.js Normal file
View File

@ -0,0 +1,15 @@
$(document).ready(function() {
$("#download").click(function(e) {
dl_button = $(this);
dl_button.html('Downloading...');
$("#logoutput").html('Loading...');
$.post("/download", {"url": $("input[name='url']").val()})
.done(function(string) {
dl_button.html('Download');
$("#logoutput").html(string);
});
e.preventDefault();
});
});

14
public/style.css Normal file
View File

@ -0,0 +1,14 @@
input {
width: 25em;
}
#form {
text-align: center;
margin: 2em;
}
#logoutput {
margin: 2em;
white-space: pre-wrap;
font-family: monospace;
}