import uuid from django.db import models from . import odysee class Tag(models.Model): id = models.CharField(primary_key=True, max_length=512, default=uuid.uuid4, editable=False, db_index=True) name = models.CharField(max_length=256) description = models.TextField() class OdyseeChannel(models.Model): id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False, db_index=True) name = models.CharField(max_length=1024) handle = models.CharField(max_length=1024) def save(self, *args, **kwargs): # First, save the field super().save(*args, **kwargs) # Then we're going to do a super kludge to try and add its releases try: releases = odysee.odysee_get_releases(self.handle) for release in releases: data = releases[release] a = OdyseeRelease.objects.get_or_create( id = release, channel = self, name = data['title'], description = data['description'], url = data['url'], thumbnail = data['thumbnail'] ) except Exception as e: print(f'Failed to get releases for this channel: {e}') return class OdyseeRelease(models.Model): id = models.CharField(primary_key=True, max_length=512, default=uuid.uuid4, editable=False, db_index=True) channel = models.ForeignKey(OdyseeChannel, on_delete=models.CASCADE, db_index=True) name = models.CharField(max_length=1024) description = models.TextField() url = models.URLField(max_length=512) thumbnail = models.URLField(max_length=512) tags = models.ManyToManyField(Tag)