Skip to content

Commit

Permalink
feat: 🎉 ✨ Added Emby Support
Browse files Browse the repository at this point in the history
  • Loading branch information
JamsRepos committed Apr 18, 2024
1 parent 0ba2a78 commit c882992
Show file tree
Hide file tree
Showing 25 changed files with 1,235 additions and 12 deletions.
2 changes: 2 additions & 0 deletions apps/wizarr-backend/wizarr_backend/api/routes/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
from .mfa_api import api as mfa_api
from .utilities_api import api as utilities_api
from .jellyfin_api import api as jellyfin_api
from .emby_api import api as emby_api
from .healthcheck_api import api as healthcheck_api
from .server_api import api as server_api

Expand Down Expand Up @@ -108,6 +109,7 @@ def handle_request_exception(error):
api.add_namespace(authentication_api)
api.add_namespace(backup_api)
api.add_namespace(discord_api)
api.add_namespace(emby_api)
api.add_namespace(healthcheck_api)
api.add_namespace(invitations_api)
api.add_namespace(jellyfin_api)
Expand Down
41 changes: 41 additions & 0 deletions apps/wizarr-backend/wizarr_backend/api/routes/emby_api.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
from flask import request
from flask_restx import Namespace, Resource

from flask_socketio import join_room
from app.extensions import socketio
from os import urandom
from helpers.universal import global_invite_user_to_media_server

api = Namespace("Emby", description="Emby related operations", path="/emby")

@socketio.on("connect", namespace="/emby")
def connect():
print("Client connected")

@api.route("")
@api.route("/", doc=False)
class EmbyStream(Resource):
"""Listen for Emby authentication events"""

def post(self):
# Get the username, password, code, and socket ID from the request
username = request.form.get("username", None)
email = request.form.get("email", None)
password = request.form.get("password", None)
code = request.form.get("code", None)
socket_id = request.form.get("socket_id", None)

# Check for missing Socket ID
if socket_id is None:
return { "message": "Missing socket ID" }, 400

# Create a room with a random ID
random_id = urandom(16).hex()
join_room(random_id, sid=socket_id, namespace="/emby")

# Send a message to the user and start a background task
socketio.emit("message", f"Hello {username}!", namespace="/emby", to=socket_id)
socketio.start_background_task(target=global_invite_user_to_media_server, username=username, email=email, password=password, code=code, socket_id=socket_id)

# Return the room ID and the username
return { "room": random_id, "username": username }, 200
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class ScanLibrariesListAPI(Resource):
@api.response(500, "Internal server error")
def get(self):
# Import from helpers
from helpers import scan_jellyfin_libraries, scan_plex_libraries
from helpers import scan_jellyfin_libraries, scan_plex_libraries, scan_emby_libraries
from app.models.database import Settings

# Get the server settings
Expand Down Expand Up @@ -52,6 +52,17 @@ def get(self):
# Return the libraries
return {"libraries": libraries}, 200

# Check if the server type is Emby
if server_type == "emby":
# Get the libraries
libraries = scan_emby_libraries(server_api_key, server_url)

# Format the libraries as [name]: [id]
libraries = {library["Name"]: library["Guid"] for library in libraries}

# Return the libraries
return {"libraries": libraries}, 200

# Check if the server type is Plex
if server_type == "plex":
# Get the libraries
Expand Down

0 comments on commit c882992

Please sign in to comment.