August 11, 2023

Selfhosted Youtube Alternative on Unraid - Part 3 (Updating to V3.0)

Selfhosted Youtube Alternative on  Unraid - Part 3 (Updating to V3.0)

Mostly for my own use but in case anyone's following along...


Update

MediaCMS 3.0 has been released, but if you're coming from v2.x like me there are a few issues to work out. I also have the developer's hack in place to prevent encoding of videos on upload to save my poor CPU, and that will have to be reapplied as well.

Database

The first issue is PostgreSQL has been updated from version 13.x to version 15... but older databases are not compatible with PostgreSQL 15. The easiest way I found to do this is to make a new container, copy your data, then swap the containers in your docker-compose. I loosely followed this guide by Elke van den Bos on Medium if you need hand holding. But the short version is:

New database compose section
  1. Add a second database to your docker-compose with the same settings as the first but named something different
  2. Set the image for that new database to a current version
  3. Change the storage volume on your database to point to a new directory
  4. Add one shared external storage volume to both database containers
  5. Run both containers, then enter the old db container and do a pg_dump from to the shared location, enter the new db container and do an import of the dump .sql file as follows:

docker compose exec -it db  /bin/bash -c 'pg_dumpall -U mediacms > /backup/<todays date>.sql'

docker compose exec -it db15/bin/bash -c 'psql -d mediacms  -U mediacms < /backup/<todays date>.sql'

Note if you're on Unraid like me you will have to run those from the docker-compose file's directory which will be something like

/boot/config/plugins/compose.manager/projects/MediaCMS/

Now you can stop the MediaCMS stack entirely, (optionally backup and then) replace your old database storage volume with your new one, then remove the new database definition from your docker-compose and update the normal database definition to use the latest version of the postgres container. Don't forget to delete the new shared backup volume you added as well.


Website

The easiest way to update the website is to backup and delete the entire MediaCMS directory. So the first step is naturally, make a backup of your MediaCMS root directory (this is important because you need some config files in there, and maybe all your media if you store it there like the default configuration does), then delete the existing copy.

Next, you want to clone the current version git repo into a new MediaCMS directory.

The files I modified were /MediaCMS/deploy/docker/local_settings.py and /MediaCMS/static/css/_comons.css/ but you may have more depending on how customized your instance is. So those files need to be copied in from the backup. If your media files were stored in here as well, copy those back too.


Disable Transcoding Again

(if you did before)

If you're like me and you have transcoding disabled on your MediaCMS, don't forget that was a hacky workaround proposed by the dev until he or someone has time to do it properly. I swear someday I will contribute, maybe this or maybe GPU-based encoding hardware acceleration. But I'm too busy for now. Anyway...

You will have to reapply those changes to the python code. If you copied your local_settings.py file from backup then you already have the setting in there again. To update the code, open your /MediaCMS/files/models.py file. You can diff this file against your backed up copy if needed.

You want to look for the media_init function and make some changes:

    def media_init(self):
        """Normally this is called when a media is uploaded
        Performs all related tasks, as check for media type,
        video duration, encode
        """
        self.set_media_type()
        if self.media_type == "video":
            self.set_thumbnail(force=True)
            # removed code - Justin
            # self.produce_sprite_from_video()
            # self.encode()

            # begin added code
            if settings.DO_NOT_TRANSCODE_VIDEO:
                self.encoding_status = "success"
                if self.state == "public" and self.encoding_status == "success" and self.is_reviewed is True:
                    self.listable = True
                self.save(update_fields=['encoding_status', 'listable'])
            else:
                self.produce_sprite_from_video()
                self.encode()
            # end added code
        elif self.media_type == "image":
            self.set_thumbnail(force=True)
        return True

Then in the encodings_info function around line 673

    def encodings_info(self, full=False):
        """Property used on serializers"""

        ret = {}

        if self.media_type not in ["video"]:
            return ret
        for key in ENCODE_RESOLUTIONS_KEYS:
            ret[key] = {}

        # begin added code
            if settings.DO_NOT_TRANSCODE_VIDEO:
                ret['720'] = {"h264": {"url": helpers.url_from_path(self.media_file.path), "status": "success", "progress": 100}}
                return ret
        # end added code

...

Save those changes and restart your stack.

That ... should be it. If you have any questions, feel free to contact me or, of course, the MediaCMS dev through the github issues page or discussions page.