From 30c34190236b56e40c6d77373635bb68377c1646 Mon Sep 17 00:00:00 2001 From: Thomas Dehaeze Date: Sun, 28 Feb 2021 12:42:54 +0100 Subject: [PATCH] Initial Commit --- .dockerignore | 2 ++ .gitignore | 1 + Dockerfile | 31 ++++++++++++++++++++ LICENSE | 22 +++++++++++++++ README.md | 0 docker-compose.yml.example | 10 +++++++ index.html | 16 +++++++++++ main.py | 58 ++++++++++++++++++++++++++++++++++++++ public/script.js | 15 ++++++++++ public/style.css | 14 +++++++++ 10 files changed, 169 insertions(+) create mode 100644 .dockerignore create mode 100644 .gitignore create mode 100644 Dockerfile create mode 100644 LICENSE create mode 100644 README.md create mode 100644 docker-compose.yml.example create mode 100644 index.html create mode 100644 main.py create mode 100644 public/script.js create mode 100644 public/style.css diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..ba2e4f7 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,2 @@ +LICENSE* +README* diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..1120be9 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +docker-compose.yml diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..730785e --- /dev/null +++ b/Dockerfile @@ -0,0 +1,31 @@ +FROM ubuntu:20.04 + +LABEL maintainer="Dehaeze Thomas " + +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"] diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..147271e --- /dev/null +++ b/LICENSE @@ -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. + diff --git a/README.md b/README.md new file mode 100644 index 0000000..e69de29 diff --git a/docker-compose.yml.example b/docker-compose.yml.example new file mode 100644 index 0000000..aca9c3d --- /dev/null +++ b/docker-compose.yml.example @@ -0,0 +1,10 @@ +version: '3' +services: + qobuz: + image: docker-qobuz + ports: + - 8080:8080 + environment: + - QOBUZNAME=name@gmail.com + - QOBUZPASS=password123 + restart: unless-stopped diff --git a/index.html b/index.html new file mode 100644 index 0000000..b20dac1 --- /dev/null +++ b/index.html @@ -0,0 +1,16 @@ + + + + + + + + +
+ + +
+
+
+ + diff --git a/main.py b/main.py new file mode 100644 index 0000000..eeb062f --- /dev/null +++ b/main.py @@ -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) diff --git a/public/script.js b/public/script.js new file mode 100644 index 0000000..587c869 --- /dev/null +++ b/public/script.js @@ -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(); + }); +}); diff --git a/public/style.css b/public/style.css new file mode 100644 index 0000000..c7956f9 --- /dev/null +++ b/public/style.css @@ -0,0 +1,14 @@ +input { + width: 25em; +} + +#form { + text-align: center; + margin: 2em; +} + +#logoutput { + margin: 2em; + white-space: pre-wrap; + font-family: monospace; +}