68 lines
4.7 KiB
Python
68 lines
4.7 KiB
Python
import uuid
|
|
from django.db import models
|
|
from . import odysee
|
|
|
|
class Tag(models.Model):
|
|
"""
|
|
A bog-standard tag, applicable to any OdyseeRelease
|
|
"""
|
|
id = models.CharField(primary_key=True, max_length=512, default=uuid.uuid4, editable=False, db_index=True, help_text="A unique identifier for this tag")
|
|
name = models.CharField(max_length=256, unique=True, help_text="The name for this tag as it should be displayed across UIs")
|
|
description = models.TextField(help_text="A user-facing description of the tag")
|
|
|
|
def __str__(self):
|
|
return self.name
|
|
|
|
class TaggingRule(models.Model):
|
|
"""
|
|
Defines a rule run against releases to assign them with tags automatically. See `./manage.py odyseetag --help` for details on cron-ing this
|
|
"""
|
|
id = models.CharField(primary_key=True, max_length=512, default=uuid.uuid4, editable=False, db_index=True, help_text="A unique identifier for this tagging rule")
|
|
name = models.CharField(max_length=1024, help_text="A non-user-facing name for the rule")
|
|
title_regex = models.CharField(max_length=512, blank=True, help_text="A regular expression to match against the title of a release. If the release's title matches, the tag is applied. If this value is blank, it is ignored.")
|
|
description_regex = models.CharField(max_length=512, blank=True, help_text="A regular expression to match against the description of a release. If it matches, the tag is applied. If this value is blank, it is ignored.")
|
|
channel_regex = models.CharField(max_length=512, blank=True, help_text="A regular expression to match against the channel HANDLE of a release. If it matches, the tag is applied. If this value is blank, it is ignored.")
|
|
required_tag = models.ForeignKey(Tag, related_name="requiredtag", on_delete=models.CASCADE, null=True, blank=True, help_text="A tag to match against a release. If this value is blank, it is ignored.")
|
|
tag = models.ForeignKey(Tag, related_name="targettag", on_delete=models.CASCADE, db_index=True, help_text="The tag to assign a release with")
|
|
|
|
def __str__(self):
|
|
return str(self.name)
|
|
|
|
class OdyseeChannel(models.Model):
|
|
"""
|
|
An Odysee channel to monitor for releases. See `./manage.py odyseescrape --help` for details on cron-ing this
|
|
"""
|
|
id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False, db_index=True, help_text="A unique identifier for this channel")
|
|
name = models.CharField(max_length=1024, help_text="The human-readable name of the channel. Does not, and often will not, necessarily correlate with the channel's handle")
|
|
description = models.TextField(help_text="A user-facing description of the channel, its owners, and its content. May also contain links to related resources and websites.")
|
|
handle = models.CharField(max_length=1024, help_text="The @tag of the user. May be a short tag (@someuser) or qualified with claimid (@someuser:4ab8)")
|
|
|
|
tags = models.ManyToManyField(Tag, related_name="channels", help_text="A list of tags associated with this channel. When queried, any release from this channel will inherit its tags.")
|
|
|
|
def __str__(self):
|
|
return self.name
|
|
|
|
class OdyseeRelease(models.Model):
|
|
"""
|
|
An Odysee release, as (hopefully) pulled from the odyseescrape command (see above). Contains a lot of details about a release
|
|
"""
|
|
id = models.CharField(primary_key=True, max_length=512, default=uuid.uuid4, editable=False, db_index=True, help_text="A unique identifier for this release. Usually the LBRY claim ID, if available")
|
|
channel = models.ForeignKey(OdyseeChannel, on_delete=models.CASCADE, db_index=True, help_text="The channel that this release came from")
|
|
name = models.CharField(max_length=1024, help_text="The human-readable name of this release")
|
|
description = models.TextField(help_text="A user-facing description of this release. This should mirror the official post from Odysee, if available")
|
|
released = models.DateField(help_text="The date that this release was posted in UTC")
|
|
url = models.URLField(max_length=512, help_text="The URL to the Odysee page where the release can be downloaded. It is NOT a direct download link")
|
|
thumbnail = models.URLField(max_length=512, help_text="The URL to the Odysee-hosted thumbnail of the release")
|
|
filehash = models.CharField(max_length=512, help_text="The hash of the file of the claim")
|
|
|
|
tags = models.ManyToManyField(Tag, related_name="releases", blank=True, help_text="A list of tags associated with this release. This should NOT contain extraneous tags from Odysee -- it's a data structure specific to this site.")
|
|
|
|
def __str__(self):
|
|
return self.name
|
|
|
|
@property
|
|
def all_tags(self):
|
|
self_tags = self.tags.all()
|
|
channel_tags = self.channel.tags.all()
|
|
return self_tags | channel_tags
|