-# Generated by Django 4.1.5 on 2023-01-22 11:53
+# Generated by Django 4.1.5 on 2023-01-22 12:47
from django.db import migrations, models
+import django.db.models.deletion
class Migration(migrations.Migration):
initial = True
- dependencies = []
+ dependencies = [
+ ("socialaccount", "0003_extra_data_default_dict"),
+ ]
operations = [
migrations.CreateModel(
name="Clip",
fields=[
- ("id", models.TextField(primary_key=True, serialize=False)),
- ("url", models.URLField()),
- ("embed_url", models.URLField()),
- ("broadcaster_id", models.TextField()),
- ("broadcaster_name", models.TextField()),
- ("creator_id", models.TextField()),
- ("creator_name", models.TextField()),
- ("video_id", models.TextField()),
- ("game_id", models.TextField()),
- ("title", models.TextField()),
- ("view_count", models.IntegerField()),
- ("created_at", models.DateTimeField()),
- ("thumbnail_url", models.TextField()),
- ("duration", models.FloatField()),
- ("vod_offset", models.IntegerField()),
+ (
+ "id",
+ models.CharField(max_length=100, primary_key=True, serialize=False),
+ ),
+ ("url", models.URLField(null=True)),
+ ("embed_url", models.URLField(null=True)),
+ ("broadcaster_id", models.CharField(max_length=100, null=True)),
+ ("broadcaster_name", models.CharField(max_length=100, null=True)),
+ ("creator_id", models.CharField(max_length=100, null=True)),
+ ("creator_name", models.CharField(max_length=100, null=True)),
+ ("video_id", models.CharField(max_length=100, null=True)),
+ ("game_id", models.CharField(max_length=100, null=True)),
+ ("title", models.CharField(max_length=200, null=True)),
+ ("view_count", models.IntegerField(null=True)),
+ ("created_at", models.DateTimeField(null=True)),
+ ("thumbnail_url", models.URLField(null=True)),
+ ("duration", models.FloatField(null=True)),
+ ("vod_offset", models.IntegerField(null=True)),
+ (
+ "user",
+ models.ForeignKey(
+ on_delete=django.db.models.deletion.CASCADE,
+ to="socialaccount.socialaccount",
+ ),
+ ),
],
),
]
+++ /dev/null
-# Generated by Django 4.1.5 on 2023-01-22 11:54
-
-from django.db import migrations, models
-
-
-class Migration(migrations.Migration):
-
- dependencies = [
- ("manager", "0001_initial"),
- ]
-
- operations = [
- migrations.AlterField(
- model_name="clip",
- name="broadcaster_id",
- field=models.TextField(null=True),
- ),
- migrations.AlterField(
- model_name="clip",
- name="broadcaster_name",
- field=models.TextField(null=True),
- ),
- migrations.AlterField(
- model_name="clip",
- name="created_at",
- field=models.DateTimeField(null=True),
- ),
- migrations.AlterField(
- model_name="clip",
- name="creator_id",
- field=models.TextField(null=True),
- ),
- migrations.AlterField(
- model_name="clip",
- name="creator_name",
- field=models.TextField(null=True),
- ),
- migrations.AlterField(
- model_name="clip",
- name="duration",
- field=models.FloatField(null=True),
- ),
- migrations.AlterField(
- model_name="clip",
- name="embed_url",
- field=models.URLField(null=True),
- ),
- migrations.AlterField(
- model_name="clip",
- name="game_id",
- field=models.TextField(null=True),
- ),
- migrations.AlterField(
- model_name="clip",
- name="thumbnail_url",
- field=models.TextField(null=True),
- ),
- migrations.AlterField(
- model_name="clip",
- name="title",
- field=models.TextField(null=True),
- ),
- migrations.AlterField(
- model_name="clip",
- name="url",
- field=models.URLField(null=True),
- ),
- migrations.AlterField(
- model_name="clip",
- name="video_id",
- field=models.TextField(null=True),
- ),
- migrations.AlterField(
- model_name="clip",
- name="view_count",
- field=models.IntegerField(null=True),
- ),
- migrations.AlterField(
- model_name="clip",
- name="vod_offset",
- field=models.IntegerField(null=True),
- ),
- ]
--- /dev/null
+# Generated by Django 4.1.5 on 2023-01-22 12:48
+
+from django.db import migrations
+
+
+class Migration(migrations.Migration):
+
+ dependencies = [
+ ("manager", "0001_initial"),
+ ]
+
+ operations = [
+ migrations.RenameField(
+ model_name="clip",
+ old_name="user",
+ new_name="account",
+ ),
+ ]
--- /dev/null
+# Generated by Django 4.1.5 on 2023-01-22 12:52
+
+from django.conf import settings
+from django.db import migrations, models
+import django.db.models.deletion
+
+
+class Migration(migrations.Migration):
+
+ dependencies = [
+ migrations.swappable_dependency(settings.AUTH_USER_MODEL),
+ ("manager", "0002_rename_user_clip_account"),
+ ]
+
+ operations = [
+ migrations.AlterField(
+ model_name="clip",
+ name="account",
+ field=models.ForeignKey(
+ on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL
+ ),
+ ),
+ ]
from django.db import models
+from django.contrib.auth.models import User
# Create your models here.
class Clip(models.Model):
- id = models.TextField(primary_key=True)
+ id = models.CharField(primary_key=True, max_length=100)
url = models.URLField(null=True)
embed_url = models.URLField(null=True)
- broadcaster_id = models.TextField(null=True)
- broadcaster_name = models.TextField(null=True)
- creator_id = models.TextField(null=True)
- creator_name = models.TextField(null=True)
- video_id = models.TextField(null=True)
- game_id = models.TextField(null=True)
- title = models.TextField(null=True)
+ broadcaster_id = models.CharField(null=True, max_length=100)
+ broadcaster_name = models.CharField(null=True, max_length=100)
+ creator_id = models.CharField(null=True, max_length=100)
+ creator_name = models.CharField(null=True, max_length=100)
+ video_id = models.CharField(null=True, max_length=100)
+ game_id = models.CharField(null=True, max_length=100)
+ title = models.CharField(null=True, max_length=200)
view_count = models.IntegerField(null=True)
created_at = models.DateTimeField(null=True)
- thumbnail_url = models.TextField(null=True)
+ thumbnail_url = models.URLField(null=True)
duration = models.FloatField(null=True)
vod_offset = models.IntegerField(null=True)
+ account = models.ForeignKey(User, on_delete=models.CASCADE)
from .models import Clip
from urllib.parse import urlparse
from allauth.socialaccount.models import SocialApp, SocialToken
+from django.contrib.auth.models import User
-def request_clip(url: str):
- id = urlparse(url).path.split("/")[-1]
+def request_clip(user, clip: str):
+ id = urlparse(clip).path.split("/")[-1]
social_app: SocialApp = SocialApp.objects.first()
oauth = SocialToken.objects.first().token
thumbnail_url=data["thumbnail_url"],
duration=data["duration"],
vod_offset=data["vod_offset"],
+ account=User.objects.get(id=user.id),
).save()
return
import requests
-from django.http import HttpResponse, HttpResponseRedirect
+from django.http import HttpResponse
from django.shortcuts import render
from .request_clip import request_clip
# check whether it's valid:
if form.is_valid():
try:
- request_clip(form.cleaned_data.get("clip"))
+ request_clip(user=request.user, clip=form.cleaned_data["clip"])
except Exception as e:
print(e)
return HttpResponse(b"<h1>NOPE</h1>")
# redirect to a new URL:
return HttpResponse(b"<h1>THANKS</h1>")
# return HttpResponseRedirect("/thanks/")
+ else:
+ print("invalid")
# if a GET (or any other method) we'll create a blank form
else:
form = ClipForm()
- return render(request, "name.html", {"form": form})
+ return render(request, "manager/index.html", {"form": form})