This commit is contained in:
√(noham)²
2024-03-03 00:19:19 +01:00
parent 695acf733e
commit 6a293919d4
12 changed files with 129 additions and 24 deletions

3
.gitignore vendored Normal file
View File

@@ -0,0 +1,3 @@
back/.users
user/.env

13
back/Dockerfile Normal file
View File

@@ -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"]

1
back/requirements.txt Normal file
View File

@@ -0,0 +1 @@
Flask==3.0.2

30
back/server.py Normal file
View File

@@ -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)

63
back/server.yaml Normal file
View File

@@ -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

View File

@@ -17,14 +17,14 @@
<div id="boxes">
<div id="player" class="player horizontal">
<div class="wrapper">
<div class="info-wrapper">
<a href="" class="song-url"><img src="" alt="LogoMusicImage" class="artwork_url"></a>
<div class="info">
<a href="" class="song-url">
<h1 class="title-song"></h1>
<h1 class="title-song"></h1><h1 class="title-album"></h1>
</a>
<a href="" class="artist-url">
<p class="name-artist"></p>

View File

@@ -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;

View File

@@ -53,8 +53,8 @@ body * {
}
.player img {
width: 84px;
height: 84px;
width: 120px;
height: 120px;
object-fit: cover;
border-radius: 10px;
}

View File

@@ -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)

View File

@@ -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'}