Import content when a channel is saved
This commit is contained in:
parent
587d73f070
commit
7c65af8a44
@ -1,3 +1,8 @@
|
||||
from django.contrib import admin
|
||||
|
||||
from .models import OdyseeChannel, OdyseeRelease
|
||||
|
||||
admin.site.register(OdyseeChannel)
|
||||
admin.site.register(OdyseeRelease)
|
||||
|
||||
# Register your models here.
|
||||
|
@ -7,6 +7,25 @@ class OdyseeChannel(models.Model):
|
||||
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()
|
||||
a.id = release
|
||||
a.channel = self
|
||||
a.name = data["title"]
|
||||
a.description = data["description"]
|
||||
a.url = data["url"]
|
||||
a.save()
|
||||
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)
|
||||
channel = models.ForeignKey(OdyseeChannel, on_delete=models.CASCADE)
|
||||
|
@ -41,7 +41,7 @@ def odysee_get_releases(handle):
|
||||
"title": item["value"].get("title", "Untitled Release"),
|
||||
"description": item["value"].get("description", "No description provided for this release"),
|
||||
"thumbnail": item["value"].get("thumbnail", {}).get("url", ""),
|
||||
"url": f"{odysee_url}/{handle}/{item['name']}"
|
||||
"url": f"{odysee_get_channel_url(handle)}/{item['name']}"
|
||||
}
|
||||
if i == lastpage:
|
||||
break
|
||||
|
@ -2,4 +2,4 @@ from django.shortcuts import render
|
||||
from django.http import HttpResponse
|
||||
|
||||
def index(request):
|
||||
return HttpResponse("Hello, world. You're at the polls index.")
|
||||
return HttpResponse("Odysee index, content tbd")
|
||||
|
Loading…
x
Reference in New Issue
Block a user