# CustomMedia A fork of [Plan9's CustomMedia project](https://gitea.plan9.rocks/cat/CustomMedia) that adds whitelist and blacklist versions for choosing specific homeservers to pull media from directly. Conserve your matrix homeserver's precious storage space and bandwidth with this one simple webserver. # Requirements - Python 3 - gunicorn - `pip3 install gunicorn` # Nginx configuration Add this inside of the block that matches for requests to /_matrix, replacing `server\.org` with your own homeserver ``` location ~ ^/_matrix/media/(?[^/]+)/((download|thumbnail)/(?!(server\.org)/))(?.*)$ { proxy_pass http://localhost:9999; proxy_set_header X-Forwarded-For $remote_addr; proxy_read_timeout 3600s; add_header 'Access-Control-Allow-Origin' '*'; add_header 'Access-Control-Allow-Credentials' 'true'; add_header 'Access-Control-Allow-Methods' 'GET, POST, PUT, DELETE, OPTIONS'; add_header 'Access-Control-Allow-Headers' 'DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range'; } ``` # systemd Service Clone this repository into /opt, check that custommedia.py has permission to execute, then use this systemd service (replacing custommedia.py with one of the other ones if desired): ``` [Unit] Description=Custom media After=network.target StartLimitIntervalSec=0 [Service] Type=simple Restart=always RestartSec=5 User=root WorkingDirectory=/opt/CustomMedia ExecStart=/opt/CustomMedia/custommedia.py [Install] WantedBy=multi-user.target ``` # Mappings CustomMedia uses a mapping.json file to cache which domain a homeserver's media is on (unless using the -morg.py version). This file will automatically be created in the working directory if one does not exist, but one has been provided here with some common homeservers.