diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..f0176bb --- /dev/null +++ b/Dockerfile @@ -0,0 +1,29 @@ +# Use an official Python runtime as a parent image +FROM python:3.7-slim-buster + +# Set the working directory in the container to /app +WORKDIR /app + +# Add the current directory contents into the container at /app +ADD . /app + +# Update and install build dependencies +RUN apt-get update && apt-get install -y \ + build-essential \ + libssl-dev \ + libffi-dev \ + python3-dev \ + python3-pip + +# Install any needed packages specified in requirements.txt +RUN pip install --no-cache-dir -r requirements.txt + +# Make port 80 available to the world outside this container +EXPOSE 5000 + +# Define environment variable +ENV NAME World + +# Run app.py when the container launches +CMD ["uwsgi", "--ini", "app.ini"] + diff --git a/GAPS 2.py b/GAPS 2.py index e9618ba..c679ac2 100644 --- a/GAPS 2.py +++ b/GAPS 2.py @@ -78,40 +78,39 @@ def save_tmdb_key(): # If the API key is not valid, return an error message return {'message': app.config['RESPONSE_MESSAGES']['api_key_failure'] + str(response.status_code)}, response.status_code -@app.route('/link_plex_account', methods=['POST']) -def link_plex_account(): - try: - headers = {'X-Plex-Client-Identifier': app.config['PLEX_CLIENT_IDENTIFIER']} - pinlogin = MyPlexPinLogin(headers=headers, oauth=True) - oauth_url = pinlogin.oauthUrl() - webbrowser.open(oauth_url) - pinlogin.run(timeout=120) - pinlogin.waitForLogin() - if pinlogin.token: - plex_data = PlexAccountData() # Create a new PlexAccountData object - plex_account = MyPlexAccount(token=pinlogin.token) - username = plex_account.username # Get the username - resources = [resource for resource in plex_account.resources() if resource.owned and resource.connections] - servers = [f"{resource.name} ({resource.connections[0].address})" for resource in resources if resource.connections] - - # Store tokens in the dictionary - for resource in resources: - if resource.connections: - server_name = f"{resource.name} ({resource.connections[0].address})" - tokens[server_name] = pinlogin.token - plex_data.add_token(server_name, pinlogin.token) - - plex_data.set_servers(servers) - - # Store the PlexAccountData object in the array - plex_data_array.append(plex_data) - - # Return the JSON response with servers and token - return jsonify(servers=servers, token=pinlogin.token) - else: - return jsonify({'message': app.config['RESPONSE_MESSAGES']['plex_account_error'], 'servers': [], 'token': None}) - except Exception as e: - return jsonify({'message': app.config['RESPONSE_MESSAGES']['plex_account_error'], 'servers': [], 'token': None}) +@app.route('/fetch_servers', methods=['POST']) +def fetch_servers(): + if globalPin.checkLogin(): # Assumes that checkLogin() returns True if the user is authenticated + plex_data = PlexAccountData() # Create a new PlexAccountData object + plex_account = MyPlexAccount(token=globalPin.token) + username = plex_account.username # Get the username + resources = [resource for resource in plex_account.resources() if resource.owned and resource.connections] + servers = [f"{resource.name} ({resource.connections[0].address})" for resource in resources if resource.connections] + + # Store tokens in the dictionary + for resource in resources: + if resource.connections: + server_name = f"{resource.name} ({resource.connections[0].address})" + tokens[server_name] = globalPin.token + plex_data.add_token(server_name, globalPin.token) + + plex_data.set_servers(servers) + + # Store the PlexAccountData object in the array + plex_data_array.append(plex_data) + + # Return the JSON response with servers and token + return jsonify(servers=servers, token=globalPin.token) + else: + return jsonify({'message': 'User is not authenticated', 'servers': [], 'token': None}) + +globalPin = None +@app.route('/authenticate_plex_acc', methods=['POST']) +def authenticate_plex_acc(): + global globalPin + globalPin = MyPlexPinLogin(oauth=True) + oauth_url = globalPin.oauthUrl() + return jsonify({'oauth_url': oauth_url}) @app.route('/fetch_libraries/') def fetch_libraries(serverName): @@ -324,4 +323,4 @@ def get_recommendated_movies(): moviesFromSelectedLibrary = {} if __name__ == '__main__': - app.run(debug=False) \ No newline at end of file + app.run(host='0.0.0.0', port=5000, debug=False) \ No newline at end of file diff --git a/app.ini b/app.ini new file mode 100644 index 0000000..a312fa7 --- /dev/null +++ b/app.ini @@ -0,0 +1,11 @@ +[uwsgi] +module = wsgi:app +http = :5000 +master = true +processes = 5 + +socket = app.sock +chmod-socket = 660 +vacuum = true + +die-on-term = true diff --git a/config.py b/config.py index 0a58746..4e2b50c 100644 --- a/config.py +++ b/config.py @@ -12,7 +12,6 @@ # Define the base URLs TMDB_BASE_URL = "https://api.themoviedb.org/3" TMDB_IMAGE_BASE_URL = "https://image.tmdb.org/t/p/w500" -PLEX_CLIENT_IDENTIFIER = "your_unique_client_identifier" # Define the response messages RESPONSE_MESSAGES = { diff --git a/requirements.txt b/requirements.txt index dbcdd71..34964b6 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,3 +1,4 @@ Flask requests -plexapi \ No newline at end of file +plexapi +uwsgi \ No newline at end of file diff --git a/templates/about.html b/templates/about.html index 845168d..5da3052 100644 --- a/templates/about.html +++ b/templates/about.html @@ -2,7 +2,7 @@ - Gaps + Gaps 2 @@ -22,10 +22,10 @@

About

- GAPS 2 is a rewrite of the original GAPS project, now written in Python instead of Java. GAPS (Gaps A Plex Server) finds movies you're missing in your Plex Server. It's a great way to find additional movies that you might be interested in based on collections from movies in your Plex Server. + GAPS 2 is a rewrite of the original GAPS project, now written in Python instead of Java. GAPS (Gaps A Plex Server) finds movies you're missing in your Plex Server. It's a great way to find additional movies that you might be interested in based on collections from movies in your Plex Server.

- The GAPS 2 project aims to bring the same functionality with the simplicity and versatility of Python. + The GAPS 2 project aims to bring the same functionality with the simplicity and versatility of Python.

Gaps searches through your Plex Server. It then queries diff --git a/templates/configuration.html b/templates/configuration.html index 72b0e1e..7dc70d4 100644 --- a/templates/configuration.html +++ b/templates/configuration.html @@ -28,8 +28,15 @@

Settings

+ +
+

To use Gaps, you'll need a MovieDB api key. Navigate over to The @@ -148,13 +155,18 @@

Settings

+
- -
- +
+ +
+
+ +
+
@@ -191,6 +203,41 @@

Servers

+ +
+
+
+ + +
+ Please enter your Jellyfin server address. +
+
+
+ + +
+ Please enter your Jellyfin username. +
+
+
+ +
+ +
+ +
+
+
+ Please enter your Jellyfin password. +
+
+ +
+
+ +
+
@@ -222,37 +269,19 @@

Error!

+ + + + + + + + +