diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..7440ced --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ + +back/.users +user/.env diff --git a/back/Dockerfile b/back/Dockerfile new file mode 100644 index 0000000..def62e6 --- /dev/null +++ b/back/Dockerfile @@ -0,0 +1,13 @@ +FROM python:3.10-alpine + +WORKDIR /app + +COPY . . + +RUN pip install --no-cache-dir -r requirements.txt + +EXPOSE 3005 + +RUN pip install gunicorn + +CMD ["gunicorn", "-w", "4", "-b", "0.0.0.0:3005", "--chdir", "/app", "app:app"] \ No newline at end of file diff --git a/back/requirements.txt b/back/requirements.txt new file mode 100644 index 0000000..100caba --- /dev/null +++ b/back/requirements.txt @@ -0,0 +1 @@ +Flask==3.0.2 \ No newline at end of file diff --git a/back/server.py b/back/server.py new file mode 100644 index 0000000..6d90a9f --- /dev/null +++ b/back/server.py @@ -0,0 +1,30 @@ +from flask import Flask, request, jsonify +from flask_cors import CORS +import json + +app = Flask(__name__) +CORS(app, resources={r"/music/*": {"origins": "http://*"}}) + +with open('.users', 'r') as file: + users = json.load(file) + +print(users) + +@app.route('/music/set', methods=['POST']) +def set_content(): + global cache + cache = request.get_json() + if cache['user'] in users and users[cache['user']] == cache['password']: + for key in ['user', 'password']: + if key in cache: + del cache[key] + return jsonify({'message': 'Content set successfully.'}) + else: + return jsonify({'message': 'Invalid user or password.'}) + +@app.route('/music/get', methods=['GET']) +def display_content(): + return jsonify(cache) + +if __name__ == '__main__': + app.run(debug=True) \ No newline at end of file diff --git a/back/server.yaml b/back/server.yaml new file mode 100644 index 0000000..f0a6ad9 --- /dev/null +++ b/back/server.yaml @@ -0,0 +1,63 @@ +name: applemusicexporter +services: + app: + cpu_shares: 90 + command: [] + deploy: + resources: + limits: + memory: 7943M + environment: + - PGID=1000 + - PUID=1000 + - TZ=Europe/Paris + image: applemusicexporter + labels: + icon: https://noh.am/static/assets/music.png + ports: + - target: 3005 + published: "3005" + protocol: tcp + restart: unless-stopped + # volumes: + # - type: bind + # source: /DATA/AppData/applemusicexporter + # target: /hard + x-casaos: + envs: + - container: PUID + description: + en_us: for UserID + - container: PGID + description: + en_us: for GroupID + - container: TZ + description: + en_us: specify a timezone to use, see this list. + devices: [] + cap_add: [] + networks: + - default + privileged: false + container_name: "" +networks: + default: + name: applemusicexporter +x-casaos: + architectures: + - amd64 + - arm64 + author: self + category: self + hostname: "" + icon: https://noh.am/static/assets/music.png + index: / + main: app + port_map: "3005" + scheme: http + store_app_id: applemusicexporter + tagline: + en_us: applemusicexporter + title: + custom: applemusicexporter + en_us: applemusicexporter diff --git a/html.html b/front/html.html similarity index 94% rename from html.html rename to front/html.html index 6853bcd..dc92efc 100644 --- a/html.html +++ b/front/html.html @@ -17,14 +17,14 @@
- +
LogoMusicImage
-

+

diff --git a/player.js b/front/player.js similarity index 93% rename from player.js rename to front/player.js index c1a21a1..9957904 100644 --- a/player.js +++ b/front/player.js @@ -20,7 +20,11 @@ function fetchDataAndAnimate() { const duration = parseFloat(data.duration); const titleSongElement = document.querySelector('.title-song'); - titleSongElement.textContent = name; + // titleSongElement.textContent = name; + titleSongElement.textContent = `${name} - ` + + const titleAlbumElement = document.querySelector('.title-album'); + titleAlbumElement.textContent = album; const artistSongElement = document.querySelector('.name-artist'); artistSongElement.textContent = artist; diff --git a/style.css b/front/style.css similarity index 98% rename from style.css rename to front/style.css index 28afbb9..6aeaf87 100644 --- a/style.css +++ b/front/style.css @@ -53,8 +53,8 @@ body * { } .player img { - width: 84px; - height: 84px; + width: 120px; + height: 120px; object-fit: cover; border-radius: 10px; } diff --git a/server.py b/server.py deleted file mode 100644 index e84a10b..0000000 --- a/server.py +++ /dev/null @@ -1,18 +0,0 @@ -from flask import Flask, request, jsonify -from flask_cors import CORS - -app = Flask(__name__) -CORS(app, resources={r"/music/*": {"origins": "http://127.0.0.1:5500"}}) - -@app.route('/music/set', methods=['POST']) -def set_content(): - global cache - cache = request.get_json() - return jsonify({'message': 'Content set successfully'}) - -@app.route('/music/get', methods=['GET']) -def display_content(): - return jsonify(cache) - -if __name__ == '__main__': - app.run(debug=True) \ No newline at end of file diff --git a/test.applescript b/user/test.applescript similarity index 100% rename from test.applescript rename to user/test.applescript diff --git a/test.py b/user/test.py similarity index 89% rename from test.py rename to user/test.py index 1d60a76..869c54a 100644 --- a/test.py +++ b/user/test.py @@ -3,6 +3,11 @@ import time import json import requests from pprint import pprint +import os +from dotenv import load_dotenv +load_dotenv() +USER = os.getenv("USER") +PASSWORD = os.getenv("PASSWORD") def get_current_song(): return subprocess.check_output(['osascript', 'test.applescript']).decode('utf-8').strip() @@ -15,6 +20,7 @@ def get_track_extras(song, artist, album): json_data = r.json() if json_data["resultCount"] == 1: result = json_data["results"][0] + pprint(result) elif json_data["resultCount"] > 1: result = json_data["results"][0] else : @@ -23,16 +29,19 @@ def get_track_extras(song, artist, album): artwork_url = result["artworkUrl100"] if result else None itunes_url = result["trackViewUrl"] if result else None artist_url = result["artistViewUrl"] if result else None + # album_url = result["collectionViewUrl"] if result else None return (artwork_url, itunes_url, artist_url) def post(currentsong): + currentsong['user'] = USER + currentsong['password'] = PASSWORD data = json.dumps(currentsong) r = requests.post(url+'/music/set', data=data, headers=headers) if r.status_code != 200: return r.status_code else : - return 'Sent' + return r.text url = "http://127.0.0.1:5000" headers = {'Content-Type': 'application/json'} diff --git a/testpost.py b/user/testpost.py similarity index 100% rename from testpost.py rename to user/testpost.py