Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Romm - Third Party Plugins Solution #1637

Open
moveweightllc opened this issue Feb 20, 2025 · 1 comment
Open

Romm - Third Party Plugins Solution #1637

moveweightllc opened this issue Feb 20, 2025 · 1 comment

Comments

@moveweightllc
Copy link

Is your feature request related to a problem? Please describe.
Many would like to customize this amazing solution with addons as to not take away from this project, and I think opening a plugin solution would be fantastic!
Describe the solution you'd like
Example: https://github.com/qbittorrent/search-plugins/wiki/Unofficial-search-plugins
Qbittorrent is an incredible Open Source Tool with legitimate purposes, these unofficial plugins allow for users to add customizations that are incredible :)
Describe alternatives you've considered
I would like to add my own addons that would improve the experience for users and am willing to fund my own projects. I'm going to pursue the API documentation with a hired hand, but I thought an official request would be appropriate.

@justinhunt1223
Copy link

I'd like to add a use case for this. I wrote a simply python script that syncs my Romm favorites to my PS3 (has retroarch on it) over FTP. I'd like this to be more automatic/integrated. I think having a way to integrate some custom scripts would be great.

import psycopg2
from psycopg2.extras import RealDictCursor
from ftplib import FTP
from pathlib import Path

PG_HOST = 'postgres-hosting-romm-db'
PG_USER = 'romm'
PG_PASSWORD = 'romm'
PG_DATABASE = 'romm'
PG_PORT = 5432

PS3_FTP_HOST = 'ps3.mydomain.com'
PS3_FTP_USERNAME = 'my-username'
PS3_FTP_PASSWORD = 'irisman-or-whatever'
PS3_ROM_DIRECTORY = '/dev_hdd0/game/RETROARCH/USRDIR/roms'

FAVORITES_COLLECTION_ID = 1 # get it from the database or url
SOURCE_ROM_DIRECTORY = '/media/roms/library'

class Romm2Ps3:

    def __init__(self) -> None:
        self.source_rom_path: Path = Path(SOURCE_ROM_DIRECTORY)
        if self.source_rom_path.is_dir() == False:
            exit('Rom path does not exist.')
        
        self.db_connection = psycopg2.connect(database=PG_DATABASE, user=PG_USER, password=PG_PASSWORD, host=PG_HOST, port=PG_PORT)
        self.db_cursor = self.db_connection.cursor(cursor_factory=RealDictCursor)
        
        self.sync_roms()

    def get_collection_rom_ids(self) -> list[int]:
        self.db_cursor.execute(f"SELECT roms from public.collections WHERE id = {FAVORITES_COLLECTION_ID};")
        record = self.db_cursor.fetchall()
        return record[0]['roms']
    
    def get_roms_to_sync(self) -> list:
        rom_ids = self.get_collection_rom_ids()

        self.db_cursor.execute(f"SELECT * from public.roms WHERE id in ({','.join(str(id) for id in rom_ids)});")
        records = self.db_cursor.fetchall()

        roms_to_sync = {}

        for record in records:
            source_rom_path: Path = self.source_rom_path.joinpath(record['file_path']).joinpath(record['file_name'])
            if source_rom_path.is_file() == False:
                continue

            platform = record['file_path'].split('/')[0]
            if not platform in roms_to_sync.keys():
                roms_to_sync[platform] = {}

            roms_to_sync[platform][record['file_name']] = source_rom_path

        return roms_to_sync
    
    def sync_roms(self) -> None:
        roms_to_sync: dict = self.get_roms_to_sync()
        
        try:
            ftp = FTP(PS3_FTP_HOST, PS3_FTP_USERNAME, PS3_FTP_PASSWORD)

            for platform, roms in roms_to_sync.items():
                ftp.cwd(PS3_ROM_DIRECTORY)
                if platform == 'ps3':
                    continue
                else:
                    if platform not in ftp.nlst():
                        ftp.mkd(platform)
                    
                    ftp.cwd(platform)
                    files_on_ps3 = ftp.nlst()

                    for destination_filename, source_rom_path in roms.items():
                        if destination_filename in files_on_ps3:
                            continue

                        ftp.storbinary(f'STOR {destination_filename}', source_rom_path.open('rb'))

                    for ps3_file in files_on_ps3:
                        if ps3_file in ['.', '..']:
                            continue

                        if not ps3_file in roms.keys():
                            ftp.delete(ps3_file)

            ftp.quit()

        except Exception as e:
            print(f"An error occurred: {e}")

Romm2Ps3()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants