add media table
parent
e77a117339
commit
42344cb76f
|
@ -27,3 +27,4 @@ from .marsey import *
|
|||
from .transactions import *
|
||||
from .streamers import *
|
||||
from .sub_logs import *
|
||||
from .media import *
|
||||
|
|
|
@ -0,0 +1,19 @@
|
|||
from sqlalchemy import *
|
||||
from files.__main__ import Base
|
||||
import time
|
||||
|
||||
class Media(Base):
|
||||
|
||||
__tablename__ = "media"
|
||||
kind = Column(String, primary_key=True)
|
||||
filename = Column(String, primary_key=True)
|
||||
user_id = Column(Integer, ForeignKey("users.id"))
|
||||
created_utc = Column(Integer)
|
||||
size = Column(Integer)
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
if "created_utc" not in kwargs: kwargs["created_utc"] = int(time.time())
|
||||
super().__init__(*args, **kwargs)
|
||||
|
||||
def __repr__(self):
|
||||
return f"<Streamer(id={self.id})>"
|
|
@ -10,6 +10,7 @@ from .const import *
|
|||
import gevent
|
||||
import imagehash
|
||||
from shutil import copyfile
|
||||
from files.classes.media import *
|
||||
|
||||
def process_files():
|
||||
body = ''
|
||||
|
@ -45,6 +46,14 @@ def process_audio(file):
|
|||
os.remove(name)
|
||||
abort(413)
|
||||
|
||||
media = Media(
|
||||
kind='audio',
|
||||
filename=name.split('/')[-1],
|
||||
user_id=g.v.id,
|
||||
size=size
|
||||
)
|
||||
g.db.add(media)
|
||||
|
||||
return f'{SITE_FULL}{name}'
|
||||
|
||||
|
||||
|
@ -78,6 +87,14 @@ def process_video(file):
|
|||
subprocess.run(["ffmpeg", "-y", "-loglevel", "warning", "-i", old, "-map_metadata", "-1", "-c:v", "copy", "-c:a", "copy", new], check=True)
|
||||
os.remove(old)
|
||||
|
||||
media = Media(
|
||||
kind='video',
|
||||
filename=new.split('/')[-1],
|
||||
user_id=g.v.id,
|
||||
size=os.stat(new).st_size
|
||||
)
|
||||
g.db.add(media)
|
||||
|
||||
return f'{SITE_FULL}{new}'
|
||||
|
||||
|
||||
|
@ -144,4 +161,12 @@ def process_image(filename=None, resize=0, trim=False):
|
|||
os.remove(filename)
|
||||
abort(417)
|
||||
|
||||
media = Media(
|
||||
kind='image',
|
||||
filename=filename.split('/')[-1],
|
||||
user_id=g.v.id,
|
||||
size=os.stat(filename).st_size
|
||||
)
|
||||
g.db.add(media)
|
||||
|
||||
return filename
|
||||
|
|
|
@ -0,0 +1,13 @@
|
|||
CREATE TABLE public.media (
|
||||
kind character varying(5) NOT NULL,
|
||||
filename character varying(23) NOT NULL,
|
||||
user_id Integer NOT NULL,
|
||||
created_utc integer NOT NULL,
|
||||
size integer NOT NULL
|
||||
);
|
||||
|
||||
ALTER TABLE ONLY public.media
|
||||
ADD CONSTRAINT media_pkey PRIMARY KEY (kind, filename);
|
||||
|
||||
ALTER TABLE ONLY public.media
|
||||
ADD CONSTRAINT media_user_fkey FOREIGN KEY (user_id) REFERENCES public.users(id);
|
Loading…
Reference in New Issue