mirror of
https://github.com/NohamR/AM-Exporter.git
synced 2026-05-25 19:58:36 +00:00
push
This commit is contained in:
3
.gitignore
vendored
Normal file
3
.gitignore
vendored
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
|
||||||
|
back/.users
|
||||||
|
user/.env
|
||||||
13
back/Dockerfile
Normal file
13
back/Dockerfile
Normal 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
1
back/requirements.txt
Normal file
@@ -0,0 +1 @@
|
|||||||
|
Flask==3.0.2
|
||||||
30
back/server.py
Normal file
30
back/server.py
Normal 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
63
back/server.yaml
Normal 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
|
||||||
@@ -17,14 +17,14 @@
|
|||||||
<div id="boxes">
|
<div id="boxes">
|
||||||
<div id="player" class="player horizontal">
|
<div id="player" class="player horizontal">
|
||||||
<div class="wrapper">
|
<div class="wrapper">
|
||||||
|
|
||||||
<div class="info-wrapper">
|
<div class="info-wrapper">
|
||||||
|
|
||||||
<a href="" class="song-url"><img src="" alt="LogoMusicImage" class="artwork_url"></a>
|
<a href="" class="song-url"><img src="" alt="LogoMusicImage" class="artwork_url"></a>
|
||||||
|
|
||||||
<div class="info">
|
<div class="info">
|
||||||
<a href="" class="song-url">
|
<a href="" class="song-url">
|
||||||
<h1 class="title-song"></h1>
|
<h1 class="title-song"></h1><h1 class="title-album"></h1>
|
||||||
</a>
|
</a>
|
||||||
<a href="" class="artist-url">
|
<a href="" class="artist-url">
|
||||||
<p class="name-artist"></p>
|
<p class="name-artist"></p>
|
||||||
@@ -20,7 +20,11 @@ function fetchDataAndAnimate() {
|
|||||||
const duration = parseFloat(data.duration);
|
const duration = parseFloat(data.duration);
|
||||||
|
|
||||||
const titleSongElement = document.querySelector('.title-song');
|
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');
|
const artistSongElement = document.querySelector('.name-artist');
|
||||||
artistSongElement.textContent = artist;
|
artistSongElement.textContent = artist;
|
||||||
@@ -53,8 +53,8 @@ body * {
|
|||||||
}
|
}
|
||||||
|
|
||||||
.player img {
|
.player img {
|
||||||
width: 84px;
|
width: 120px;
|
||||||
height: 84px;
|
height: 120px;
|
||||||
object-fit: cover;
|
object-fit: cover;
|
||||||
border-radius: 10px;
|
border-radius: 10px;
|
||||||
}
|
}
|
||||||
18
server.py
18
server.py
@@ -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)
|
|
||||||
@@ -3,6 +3,11 @@ import time
|
|||||||
import json
|
import json
|
||||||
import requests
|
import requests
|
||||||
from pprint import pprint
|
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():
|
def get_current_song():
|
||||||
return subprocess.check_output(['osascript', 'test.applescript']).decode('utf-8').strip()
|
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()
|
json_data = r.json()
|
||||||
if json_data["resultCount"] == 1:
|
if json_data["resultCount"] == 1:
|
||||||
result = json_data["results"][0]
|
result = json_data["results"][0]
|
||||||
|
pprint(result)
|
||||||
elif json_data["resultCount"] > 1:
|
elif json_data["resultCount"] > 1:
|
||||||
result = json_data["results"][0]
|
result = json_data["results"][0]
|
||||||
else :
|
else :
|
||||||
@@ -23,16 +29,19 @@ def get_track_extras(song, artist, album):
|
|||||||
artwork_url = result["artworkUrl100"] if result else None
|
artwork_url = result["artworkUrl100"] if result else None
|
||||||
itunes_url = result["trackViewUrl"] if result else None
|
itunes_url = result["trackViewUrl"] if result else None
|
||||||
artist_url = result["artistViewUrl"] 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)
|
return (artwork_url, itunes_url, artist_url)
|
||||||
|
|
||||||
def post(currentsong):
|
def post(currentsong):
|
||||||
|
currentsong['user'] = USER
|
||||||
|
currentsong['password'] = PASSWORD
|
||||||
data = json.dumps(currentsong)
|
data = json.dumps(currentsong)
|
||||||
r = requests.post(url+'/music/set', data=data, headers=headers)
|
r = requests.post(url+'/music/set', data=data, headers=headers)
|
||||||
if r.status_code != 200:
|
if r.status_code != 200:
|
||||||
return r.status_code
|
return r.status_code
|
||||||
else :
|
else :
|
||||||
return 'Sent'
|
return r.text
|
||||||
|
|
||||||
url = "http://127.0.0.1:5000"
|
url = "http://127.0.0.1:5000"
|
||||||
headers = {'Content-Type': 'application/json'}
|
headers = {'Content-Type': 'application/json'}
|
||||||
Reference in New Issue
Block a user