chore: rename libretimeapi dir to libretime_api
This commit is contained in:
parent
02efadc3d0
commit
6de242db65
36 changed files with 0 additions and 0 deletions
14
api/libretime_api/models/__init__.py
Normal file
14
api/libretime_api/models/__init__.py
Normal file
|
@ -0,0 +1,14 @@
|
|||
from .authentication import *
|
||||
from .celery import *
|
||||
from .countries import *
|
||||
from .files import *
|
||||
from .playlists import *
|
||||
from .playout import *
|
||||
from .podcasts import *
|
||||
from .preferences import *
|
||||
from .schedule import *
|
||||
from .services import *
|
||||
from .shows import *
|
||||
from .smart_blocks import *
|
||||
from .tracks import *
|
||||
from .webstreams import *
|
148
api/libretime_api/models/authentication.py
Normal file
148
api/libretime_api/models/authentication.py
Normal file
|
@ -0,0 +1,148 @@
|
|||
import hashlib
|
||||
|
||||
from django.contrib import auth
|
||||
from django.contrib.auth.models import AbstractBaseUser, Permission
|
||||
from django.core.exceptions import PermissionDenied
|
||||
from django.db import models
|
||||
|
||||
from libretimeapi.managers import UserManager
|
||||
from libretimeapi.permission_constants import GROUPS
|
||||
|
||||
from .user_constants import ADMIN, USER_TYPES
|
||||
|
||||
|
||||
class LoginAttempt(models.Model):
|
||||
ip = models.CharField(primary_key=True, max_length=32)
|
||||
attempts = models.IntegerField(blank=True, null=True)
|
||||
|
||||
class Meta:
|
||||
managed = False
|
||||
db_table = "cc_login_attempts"
|
||||
|
||||
|
||||
class Session(models.Model):
|
||||
sessid = models.CharField(primary_key=True, max_length=32)
|
||||
userid = models.ForeignKey(
|
||||
"User", models.DO_NOTHING, db_column="userid", blank=True, null=True
|
||||
)
|
||||
login = models.CharField(max_length=255, blank=True, null=True)
|
||||
ts = models.DateTimeField(blank=True, null=True)
|
||||
|
||||
class Meta:
|
||||
managed = False
|
||||
db_table = "cc_sess"
|
||||
|
||||
|
||||
USER_TYPE_CHOICES = ()
|
||||
for item in USER_TYPES.items():
|
||||
USER_TYPE_CHOICES = USER_TYPE_CHOICES + (item,)
|
||||
|
||||
|
||||
class User(AbstractBaseUser):
|
||||
username = models.CharField(db_column="login", unique=True, max_length=255)
|
||||
password = models.CharField(
|
||||
db_column="pass", max_length=255
|
||||
) # Field renamed because it was a Python reserved word.
|
||||
type = models.CharField(max_length=1, choices=USER_TYPE_CHOICES)
|
||||
first_name = models.CharField(max_length=255)
|
||||
last_name = models.CharField(max_length=255)
|
||||
last_login = models.DateTimeField(db_column="lastlogin", blank=True, null=True)
|
||||
lastfail = models.DateTimeField(blank=True, null=True)
|
||||
skype_contact = models.CharField(max_length=1024, blank=True, null=True)
|
||||
jabber_contact = models.CharField(max_length=1024, blank=True, null=True)
|
||||
email = models.CharField(max_length=1024, blank=True, null=True)
|
||||
cell_phone = models.CharField(max_length=1024, blank=True, null=True)
|
||||
login_attempts = models.IntegerField(blank=True, null=True)
|
||||
|
||||
USERNAME_FIELD = "username"
|
||||
EMAIL_FIELD = "email"
|
||||
REQUIRED_FIELDS = ["type", "email", "first_name", "last_name"]
|
||||
objects = UserManager()
|
||||
|
||||
def get_full_name(self):
|
||||
return "{} {}".format(self.first_name, self.last_name)
|
||||
|
||||
def get_short_name(self):
|
||||
return self.first_name
|
||||
|
||||
def set_password(self, password):
|
||||
if not password:
|
||||
self.set_unusable_password()
|
||||
else:
|
||||
self.password = hashlib.md5(password.encode()).hexdigest()
|
||||
|
||||
def is_staff(self):
|
||||
return self.type == ADMIN
|
||||
|
||||
def check_password(self, password):
|
||||
if self.has_usable_password():
|
||||
test_password = hashlib.md5(password.encode()).hexdigest()
|
||||
return test_password == self.password
|
||||
return False
|
||||
|
||||
"""
|
||||
The following methods have to be re-implemented here, as PermissionsMixin
|
||||
assumes that the User class has a 'group' attribute, which LibreTime does
|
||||
not currently provide. Once Django starts managing the Database
|
||||
(managed = True), then this can be replaced with
|
||||
django.contrib.auth.models.PermissionMixin.
|
||||
"""
|
||||
|
||||
def is_superuser(self):
|
||||
return self.type == ADMIN
|
||||
|
||||
def get_user_permissions(self, obj=None):
|
||||
"""
|
||||
Users do not have permissions directly, only through groups
|
||||
"""
|
||||
return []
|
||||
|
||||
def get_group_permissions(self, obj=None):
|
||||
permissions = GROUPS[self.type]
|
||||
if obj:
|
||||
obj_name = obj.__class__.__name__.lower()
|
||||
permissions = [perm for perm in permissions if obj_name in perm]
|
||||
# get permissions objects
|
||||
q = models.Q()
|
||||
for perm in permissions:
|
||||
q = q | models.Q(codename=perm)
|
||||
return list(Permission.objects.filter(q))
|
||||
|
||||
def get_all_permissions(self, obj=None):
|
||||
return self.get_user_permissions(obj) + self.get_group_permissions(obj)
|
||||
|
||||
def has_perm(self, perm, obj=None):
|
||||
if self.is_superuser():
|
||||
return True
|
||||
if not perm:
|
||||
return False
|
||||
permissions = self.get_all_permissions(obj)
|
||||
try:
|
||||
permission = Permission.objects.get(codename=perm)
|
||||
return permission in permissions
|
||||
except Permission.DoesNotExist:
|
||||
return False
|
||||
|
||||
def has_perms(self, perm_list, obj=None):
|
||||
result = True
|
||||
for permission in perm_list:
|
||||
result = result and self.has_perm(permission, obj)
|
||||
return result
|
||||
|
||||
class Meta:
|
||||
managed = False
|
||||
db_table = "cc_subjs"
|
||||
|
||||
|
||||
class UserToken(models.Model):
|
||||
user = models.ForeignKey(User, models.DO_NOTHING)
|
||||
action = models.CharField(max_length=255)
|
||||
token = models.CharField(unique=True, max_length=40)
|
||||
created = models.DateTimeField()
|
||||
|
||||
def get_owner(self):
|
||||
return self.user
|
||||
|
||||
class Meta:
|
||||
managed = False
|
||||
db_table = "cc_subjs_token"
|
15
api/libretime_api/models/celery.py
Normal file
15
api/libretime_api/models/celery.py
Normal file
|
@ -0,0 +1,15 @@
|
|||
from django.db import models
|
||||
|
||||
|
||||
class CeleryTask(models.Model):
|
||||
task_id = models.CharField(max_length=256)
|
||||
track_reference = models.ForeignKey(
|
||||
"ThirdPartyTrackReference", models.DO_NOTHING, db_column="track_reference"
|
||||
)
|
||||
name = models.CharField(max_length=256, blank=True, null=True)
|
||||
dispatch_time = models.DateTimeField(blank=True, null=True)
|
||||
status = models.CharField(max_length=256)
|
||||
|
||||
class Meta:
|
||||
managed = False
|
||||
db_table = "celery_tasks"
|
10
api/libretime_api/models/countries.py
Normal file
10
api/libretime_api/models/countries.py
Normal file
|
@ -0,0 +1,10 @@
|
|||
from django.db import models
|
||||
|
||||
|
||||
class Country(models.Model):
|
||||
isocode = models.CharField(primary_key=True, max_length=3)
|
||||
name = models.CharField(max_length=255)
|
||||
|
||||
class Meta:
|
||||
managed = False
|
||||
db_table = "cc_country"
|
117
api/libretime_api/models/files.py
Normal file
117
api/libretime_api/models/files.py
Normal file
|
@ -0,0 +1,117 @@
|
|||
from django.db import models
|
||||
|
||||
|
||||
class File(models.Model):
|
||||
name = models.CharField(max_length=255)
|
||||
mime = models.CharField(max_length=255)
|
||||
ftype = models.CharField(max_length=128)
|
||||
directory = models.ForeignKey(
|
||||
"MusicDir", models.DO_NOTHING, db_column="directory", blank=True, null=True
|
||||
)
|
||||
filepath = models.TextField(blank=True, null=True)
|
||||
import_status = models.IntegerField()
|
||||
currently_accessing = models.IntegerField(db_column="currentlyaccessing")
|
||||
edited_by = models.ForeignKey(
|
||||
"User",
|
||||
models.DO_NOTHING,
|
||||
db_column="editedby",
|
||||
blank=True,
|
||||
null=True,
|
||||
related_name="edited_files",
|
||||
)
|
||||
mtime = models.DateTimeField(blank=True, null=True)
|
||||
utime = models.DateTimeField(blank=True, null=True)
|
||||
lptime = models.DateTimeField(blank=True, null=True)
|
||||
md5 = models.CharField(max_length=32, blank=True, null=True)
|
||||
track_title = models.CharField(max_length=512, blank=True, null=True)
|
||||
artist_name = models.CharField(max_length=512, blank=True, null=True)
|
||||
bit_rate = models.IntegerField(blank=True, null=True)
|
||||
sample_rate = models.IntegerField(blank=True, null=True)
|
||||
format = models.CharField(max_length=128, blank=True, null=True)
|
||||
length = models.DurationField(blank=True, null=True)
|
||||
album_title = models.CharField(max_length=512, blank=True, null=True)
|
||||
genre = models.CharField(max_length=64, blank=True, null=True)
|
||||
comments = models.TextField(blank=True, null=True)
|
||||
year = models.CharField(max_length=16, blank=True, null=True)
|
||||
track_number = models.IntegerField(blank=True, null=True)
|
||||
channels = models.IntegerField(blank=True, null=True)
|
||||
url = models.CharField(max_length=1024, blank=True, null=True)
|
||||
bpm = models.IntegerField(blank=True, null=True)
|
||||
rating = models.CharField(max_length=8, blank=True, null=True)
|
||||
encoded_by = models.CharField(max_length=255, blank=True, null=True)
|
||||
disc_number = models.CharField(max_length=8, blank=True, null=True)
|
||||
mood = models.CharField(max_length=64, blank=True, null=True)
|
||||
label = models.CharField(max_length=512, blank=True, null=True)
|
||||
composer = models.CharField(max_length=512, blank=True, null=True)
|
||||
encoder = models.CharField(max_length=64, blank=True, null=True)
|
||||
checksum = models.CharField(max_length=256, blank=True, null=True)
|
||||
lyrics = models.TextField(blank=True, null=True)
|
||||
orchestra = models.CharField(max_length=512, blank=True, null=True)
|
||||
conductor = models.CharField(max_length=512, blank=True, null=True)
|
||||
lyricist = models.CharField(max_length=512, blank=True, null=True)
|
||||
original_lyricist = models.CharField(max_length=512, blank=True, null=True)
|
||||
radio_station_name = models.CharField(max_length=512, blank=True, null=True)
|
||||
info_url = models.CharField(max_length=512, blank=True, null=True)
|
||||
artist_url = models.CharField(max_length=512, blank=True, null=True)
|
||||
audio_source_url = models.CharField(max_length=512, blank=True, null=True)
|
||||
radio_station_url = models.CharField(max_length=512, blank=True, null=True)
|
||||
buy_this_url = models.CharField(max_length=512, blank=True, null=True)
|
||||
isrc_number = models.CharField(max_length=512, blank=True, null=True)
|
||||
catalog_number = models.CharField(max_length=512, blank=True, null=True)
|
||||
original_artist = models.CharField(max_length=512, blank=True, null=True)
|
||||
copyright = models.CharField(max_length=512, blank=True, null=True)
|
||||
report_datetime = models.CharField(max_length=32, blank=True, null=True)
|
||||
report_location = models.CharField(max_length=512, blank=True, null=True)
|
||||
report_organization = models.CharField(max_length=512, blank=True, null=True)
|
||||
subject = models.CharField(max_length=512, blank=True, null=True)
|
||||
contributor = models.CharField(max_length=512, blank=True, null=True)
|
||||
language = models.CharField(max_length=512, blank=True, null=True)
|
||||
file_exists = models.BooleanField(blank=True, null=True)
|
||||
replay_gain = models.DecimalField(
|
||||
max_digits=8, decimal_places=2, blank=True, null=True
|
||||
)
|
||||
owner = models.ForeignKey("User", models.DO_NOTHING, blank=True, null=True)
|
||||
cuein = models.DurationField(blank=True, null=True)
|
||||
cueout = models.DurationField(blank=True, null=True)
|
||||
silan_check = models.BooleanField(blank=True, null=True)
|
||||
hidden = models.BooleanField(blank=True, null=True)
|
||||
is_scheduled = models.BooleanField(blank=True, null=True)
|
||||
is_playlist = models.BooleanField(blank=True, null=True)
|
||||
filesize = models.IntegerField()
|
||||
description = models.CharField(max_length=512, blank=True, null=True)
|
||||
artwork = models.CharField(max_length=512, blank=True, null=True)
|
||||
track_type = models.CharField(max_length=16, blank=True, null=True)
|
||||
|
||||
def get_owner(self):
|
||||
return self.owner
|
||||
|
||||
class Meta:
|
||||
managed = False
|
||||
db_table = "cc_files"
|
||||
permissions = [
|
||||
("change_own_file", "Change the files where they are the owner"),
|
||||
("delete_own_file", "Delete the files where they are the owner"),
|
||||
]
|
||||
|
||||
|
||||
class MusicDir(models.Model):
|
||||
directory = models.TextField(unique=True, blank=True, null=True)
|
||||
type = models.CharField(max_length=255, blank=True, null=True)
|
||||
exists = models.BooleanField(blank=True, null=True)
|
||||
watched = models.BooleanField(blank=True, null=True)
|
||||
|
||||
class Meta:
|
||||
managed = False
|
||||
db_table = "cc_music_dirs"
|
||||
|
||||
|
||||
class CloudFile(models.Model):
|
||||
storage_backend = models.CharField(max_length=512)
|
||||
resource_id = models.TextField()
|
||||
filename = models.ForeignKey(
|
||||
File, models.DO_NOTHING, blank=True, null=True, db_column="cc_file_id"
|
||||
)
|
||||
|
||||
class Meta:
|
||||
managed = False
|
||||
db_table = "cloud_file"
|
42
api/libretime_api/models/playlists.py
Normal file
42
api/libretime_api/models/playlists.py
Normal file
|
@ -0,0 +1,42 @@
|
|||
from django.db import models
|
||||
|
||||
from .files import File
|
||||
from .smart_blocks import SmartBlock
|
||||
|
||||
|
||||
class Playlist(models.Model):
|
||||
name = models.CharField(max_length=255)
|
||||
mtime = models.DateTimeField(blank=True, null=True)
|
||||
utime = models.DateTimeField(blank=True, null=True)
|
||||
creator = models.ForeignKey("User", models.DO_NOTHING, blank=True, null=True)
|
||||
description = models.CharField(max_length=512, blank=True, null=True)
|
||||
length = models.DurationField(blank=True, null=True)
|
||||
|
||||
def get_owner(self):
|
||||
return self.creator
|
||||
|
||||
class Meta:
|
||||
managed = False
|
||||
db_table = "cc_playlist"
|
||||
|
||||
|
||||
class PlaylistContent(models.Model):
|
||||
playlist = models.ForeignKey(Playlist, models.DO_NOTHING, blank=True, null=True)
|
||||
file = models.ForeignKey(File, models.DO_NOTHING, blank=True, null=True)
|
||||
block = models.ForeignKey(SmartBlock, models.DO_NOTHING, blank=True, null=True)
|
||||
stream_id = models.IntegerField(blank=True, null=True)
|
||||
type = models.SmallIntegerField()
|
||||
position = models.IntegerField(blank=True, null=True)
|
||||
trackoffset = models.FloatField()
|
||||
cliplength = models.DurationField(blank=True, null=True)
|
||||
cuein = models.DurationField(blank=True, null=True)
|
||||
cueout = models.DurationField(blank=True, null=True)
|
||||
fadein = models.TimeField(blank=True, null=True)
|
||||
fadeout = models.TimeField(blank=True, null=True)
|
||||
|
||||
def get_owner(self):
|
||||
return self.playlist.owner
|
||||
|
||||
class Meta:
|
||||
managed = False
|
||||
db_table = "cc_playlistcontents"
|
76
api/libretime_api/models/playout.py
Normal file
76
api/libretime_api/models/playout.py
Normal file
|
@ -0,0 +1,76 @@
|
|||
from django.db import models
|
||||
|
||||
from .files import File
|
||||
|
||||
|
||||
class ListenerCount(models.Model):
|
||||
timestamp = models.ForeignKey("Timestamp", models.DO_NOTHING)
|
||||
mount_name = models.ForeignKey("MountName", models.DO_NOTHING)
|
||||
listener_count = models.IntegerField()
|
||||
|
||||
class Meta:
|
||||
managed = False
|
||||
db_table = "cc_listener_count"
|
||||
|
||||
|
||||
class LiveLog(models.Model):
|
||||
state = models.CharField(max_length=32)
|
||||
start_time = models.DateTimeField()
|
||||
end_time = models.DateTimeField(blank=True, null=True)
|
||||
|
||||
class Meta:
|
||||
managed = False
|
||||
db_table = "cc_live_log"
|
||||
|
||||
|
||||
class PlayoutHistory(models.Model):
|
||||
file = models.ForeignKey(File, models.DO_NOTHING, blank=True, null=True)
|
||||
starts = models.DateTimeField()
|
||||
ends = models.DateTimeField(blank=True, null=True)
|
||||
instance = models.ForeignKey(
|
||||
"ShowInstance", models.DO_NOTHING, blank=True, null=True
|
||||
)
|
||||
|
||||
class Meta:
|
||||
managed = False
|
||||
db_table = "cc_playout_history"
|
||||
|
||||
|
||||
class PlayoutHistoryMetadata(models.Model):
|
||||
history = models.ForeignKey(PlayoutHistory, models.DO_NOTHING)
|
||||
key = models.CharField(max_length=128)
|
||||
value = models.CharField(max_length=128)
|
||||
|
||||
class Meta:
|
||||
managed = False
|
||||
db_table = "cc_playout_history_metadata"
|
||||
|
||||
|
||||
class PlayoutHistoryTemplate(models.Model):
|
||||
name = models.CharField(max_length=128)
|
||||
type = models.CharField(max_length=35)
|
||||
|
||||
class Meta:
|
||||
managed = False
|
||||
db_table = "cc_playout_history_template"
|
||||
|
||||
|
||||
class PlayoutHistoryTemplateField(models.Model):
|
||||
template = models.ForeignKey(PlayoutHistoryTemplate, models.DO_NOTHING)
|
||||
name = models.CharField(max_length=128)
|
||||
label = models.CharField(max_length=128)
|
||||
type = models.CharField(max_length=128)
|
||||
is_file_md = models.BooleanField()
|
||||
position = models.IntegerField()
|
||||
|
||||
class Meta:
|
||||
managed = False
|
||||
db_table = "cc_playout_history_template_field"
|
||||
|
||||
|
||||
class Timestamp(models.Model):
|
||||
timestamp = models.DateTimeField()
|
||||
|
||||
class Meta:
|
||||
managed = False
|
||||
db_table = "cc_timestamp"
|
86
api/libretime_api/models/podcasts.py
Normal file
86
api/libretime_api/models/podcasts.py
Normal file
|
@ -0,0 +1,86 @@
|
|||
from django.db import models
|
||||
|
||||
from .authentication import User
|
||||
from .files import File
|
||||
|
||||
|
||||
class ImportedPodcast(models.Model):
|
||||
auto_ingest = models.BooleanField()
|
||||
auto_ingest_timestamp = models.DateTimeField(blank=True, null=True)
|
||||
album_override = models.BooleanField()
|
||||
podcast = models.ForeignKey("Podcast", models.DO_NOTHING)
|
||||
|
||||
def get_owner(self):
|
||||
return self.podcast.owner
|
||||
|
||||
class Meta:
|
||||
managed = False
|
||||
db_table = "imported_podcast"
|
||||
|
||||
|
||||
class Podcast(models.Model):
|
||||
url = models.CharField(max_length=4096)
|
||||
title = models.CharField(max_length=4096)
|
||||
creator = models.CharField(max_length=4096, blank=True, null=True)
|
||||
description = models.CharField(max_length=4096, blank=True, null=True)
|
||||
language = models.CharField(max_length=4096, blank=True, null=True)
|
||||
copyright = models.CharField(max_length=4096, blank=True, null=True)
|
||||
link = models.CharField(max_length=4096, blank=True, null=True)
|
||||
itunes_author = models.CharField(max_length=4096, blank=True, null=True)
|
||||
itunes_keywords = models.CharField(max_length=4096, blank=True, null=True)
|
||||
itunes_summary = models.CharField(max_length=4096, blank=True, null=True)
|
||||
itunes_subtitle = models.CharField(max_length=4096, blank=True, null=True)
|
||||
itunes_category = models.CharField(max_length=4096, blank=True, null=True)
|
||||
itunes_explicit = models.CharField(max_length=4096, blank=True, null=True)
|
||||
owner = models.ForeignKey(
|
||||
User, models.DO_NOTHING, db_column="owner", blank=True, null=True
|
||||
)
|
||||
|
||||
def get_owner(self):
|
||||
return self.owner
|
||||
|
||||
class Meta:
|
||||
managed = False
|
||||
db_table = "podcast"
|
||||
permissions = [
|
||||
("change_own_podcast", "Change the podcasts where they are the owner"),
|
||||
("delete_own_podcast", "Delete the podcasts where they are the owner"),
|
||||
]
|
||||
|
||||
|
||||
class PodcastEpisode(models.Model):
|
||||
file = models.ForeignKey(File, models.DO_NOTHING, blank=True, null=True)
|
||||
podcast = models.ForeignKey(Podcast, models.DO_NOTHING)
|
||||
publication_date = models.DateTimeField()
|
||||
download_url = models.CharField(max_length=4096)
|
||||
episode_guid = models.CharField(max_length=4096)
|
||||
episode_title = models.CharField(max_length=4096)
|
||||
episode_description = models.TextField()
|
||||
|
||||
def get_owner(self):
|
||||
return self.podcast.owner
|
||||
|
||||
class Meta:
|
||||
managed = False
|
||||
db_table = "podcast_episodes"
|
||||
permissions = [
|
||||
(
|
||||
"change_own_podcastepisode",
|
||||
"Change the episodes of podcasts where they are the owner",
|
||||
),
|
||||
(
|
||||
"delete_own_podcastepisode",
|
||||
"Delete the episodes of podcasts where they are the owner",
|
||||
),
|
||||
]
|
||||
|
||||
|
||||
class StationPodcast(models.Model):
|
||||
podcast = models.ForeignKey(Podcast, models.DO_NOTHING)
|
||||
|
||||
def get_owner(self):
|
||||
return self.podcast.owner
|
||||
|
||||
class Meta:
|
||||
managed = False
|
||||
db_table = "station_podcast"
|
32
api/libretime_api/models/preferences.py
Normal file
32
api/libretime_api/models/preferences.py
Normal file
|
@ -0,0 +1,32 @@
|
|||
from django.db import models
|
||||
|
||||
|
||||
class Preference(models.Model):
|
||||
subjid = models.ForeignKey(
|
||||
"User", models.DO_NOTHING, db_column="subjid", blank=True, null=True
|
||||
)
|
||||
keystr = models.CharField(unique=True, max_length=255, blank=True, null=True)
|
||||
valstr = models.TextField(blank=True, null=True)
|
||||
|
||||
class Meta:
|
||||
managed = False
|
||||
db_table = "cc_pref"
|
||||
unique_together = (("subjid", "keystr"),)
|
||||
|
||||
|
||||
class MountName(models.Model):
|
||||
mount_name = models.CharField(max_length=1024)
|
||||
|
||||
class Meta:
|
||||
managed = False
|
||||
db_table = "cc_mount_name"
|
||||
|
||||
|
||||
class StreamSetting(models.Model):
|
||||
keyname = models.CharField(primary_key=True, max_length=64)
|
||||
value = models.CharField(max_length=255, blank=True, null=True)
|
||||
type = models.CharField(max_length=16)
|
||||
|
||||
class Meta:
|
||||
managed = False
|
||||
db_table = "cc_stream_setting"
|
85
api/libretime_api/models/schedule.py
Normal file
85
api/libretime_api/models/schedule.py
Normal file
|
@ -0,0 +1,85 @@
|
|||
from django.db import models
|
||||
|
||||
from .files import File
|
||||
|
||||
|
||||
class Schedule(models.Model):
|
||||
starts = models.DateTimeField()
|
||||
ends = models.DateTimeField()
|
||||
file = models.ForeignKey(File, models.DO_NOTHING, blank=True, null=True)
|
||||
stream = models.ForeignKey("Webstream", models.DO_NOTHING, blank=True, null=True)
|
||||
clip_length = models.DurationField(blank=True, null=True)
|
||||
fade_in = models.TimeField(blank=True, null=True)
|
||||
fade_out = models.TimeField(blank=True, null=True)
|
||||
cue_in = models.DurationField()
|
||||
cue_out = models.DurationField()
|
||||
media_item_played = models.BooleanField(blank=True, null=True)
|
||||
instance = models.ForeignKey("ShowInstance", models.DO_NOTHING)
|
||||
playout_status = models.SmallIntegerField()
|
||||
broadcasted = models.SmallIntegerField()
|
||||
position = models.IntegerField()
|
||||
|
||||
def get_owner(self):
|
||||
return self.instance.get_owner()
|
||||
|
||||
def get_cueout(self):
|
||||
"""
|
||||
Returns a scheduled item cueout that is based on the current show instance.
|
||||
|
||||
Cueout of a specific item can potentially overrun the show that it is
|
||||
scheduled in. In that case, the cueout should be the end of the show.
|
||||
This prevents the next show having overlapping items playing.
|
||||
|
||||
Cases:
|
||||
- When the schedule ends before the end of the show instance,
|
||||
return the stored cueout.
|
||||
|
||||
- When the schedule starts before the end of the show instance
|
||||
and ends after the show instance ends,
|
||||
return timedelta between schedule starts and show instance ends.
|
||||
|
||||
- When the schedule starts after the end of the show instance,
|
||||
return the stored cue_out even if the schedule WILL NOT BE PLAYED.
|
||||
"""
|
||||
if self.starts < self.instance.ends and self.instance.ends < self.ends:
|
||||
return self.instance.ends - self.starts
|
||||
return self.cue_out
|
||||
|
||||
def get_ends(self):
|
||||
"""
|
||||
Returns a scheduled item ends that is based on the current show instance.
|
||||
|
||||
End of a specific item can potentially overrun the show that it is
|
||||
scheduled in. In that case, the end should be the end of the show.
|
||||
This prevents the next show having overlapping items playing.
|
||||
|
||||
Cases:
|
||||
- When the schedule ends before the end of the show instance,
|
||||
return the scheduled item ends.
|
||||
|
||||
- When the schedule starts before the end of the show instance
|
||||
and ends after the show instance ends,
|
||||
return the show instance ends.
|
||||
|
||||
- When the schedule starts after the end of the show instance,
|
||||
return the show instance ends.
|
||||
"""
|
||||
if self.instance.ends < self.ends:
|
||||
return self.instance.ends
|
||||
return self.ends
|
||||
|
||||
@property
|
||||
def is_valid(self):
|
||||
"""
|
||||
A schedule item is valid if it starts before the end of the show instance
|
||||
it is in
|
||||
"""
|
||||
return self.starts < self.instance.ends
|
||||
|
||||
class Meta:
|
||||
managed = False
|
||||
db_table = "cc_schedule"
|
||||
permissions = [
|
||||
("change_own_schedule", "Change the content on their shows"),
|
||||
("delete_own_schedule", "Delete the content on their shows"),
|
||||
]
|
10
api/libretime_api/models/services.py
Normal file
10
api/libretime_api/models/services.py
Normal file
|
@ -0,0 +1,10 @@
|
|||
from django.db import models
|
||||
|
||||
|
||||
class ServiceRegister(models.Model):
|
||||
name = models.CharField(primary_key=True, max_length=32)
|
||||
ip = models.CharField(max_length=45)
|
||||
|
||||
class Meta:
|
||||
managed = False
|
||||
db_table = "cc_service_register"
|
95
api/libretime_api/models/shows.py
Normal file
95
api/libretime_api/models/shows.py
Normal file
|
@ -0,0 +1,95 @@
|
|||
from django.db import models
|
||||
|
||||
from .files import File
|
||||
from .playlists import Playlist
|
||||
|
||||
|
||||
class Show(models.Model):
|
||||
name = models.CharField(max_length=255)
|
||||
url = models.CharField(max_length=255, blank=True, null=True)
|
||||
genre = models.CharField(max_length=255, blank=True, null=True)
|
||||
description = models.CharField(max_length=8192, blank=True, null=True)
|
||||
color = models.CharField(max_length=6, blank=True, null=True)
|
||||
background_color = models.CharField(max_length=6, blank=True, null=True)
|
||||
live_stream_using_airtime_auth = models.BooleanField(blank=True, null=True)
|
||||
live_stream_using_custom_auth = models.BooleanField(blank=True, null=True)
|
||||
live_stream_user = models.CharField(max_length=255, blank=True, null=True)
|
||||
live_stream_pass = models.CharField(max_length=255, blank=True, null=True)
|
||||
linked = models.BooleanField()
|
||||
is_linkable = models.BooleanField()
|
||||
image_path = models.CharField(max_length=255, blank=True, null=True)
|
||||
has_autoplaylist = models.BooleanField()
|
||||
autoplaylist = models.ForeignKey(Playlist, models.DO_NOTHING, blank=True, null=True)
|
||||
autoplaylist_repeat = models.BooleanField()
|
||||
|
||||
def get_owner(self):
|
||||
return self.showhost_set.all()
|
||||
|
||||
class Meta:
|
||||
managed = False
|
||||
db_table = "cc_show"
|
||||
|
||||
|
||||
class ShowDays(models.Model):
|
||||
first_show = models.DateField()
|
||||
last_show = models.DateField(blank=True, null=True)
|
||||
start_time = models.TimeField()
|
||||
timezone = models.CharField(max_length=1024)
|
||||
duration = models.CharField(max_length=1024)
|
||||
day = models.SmallIntegerField(blank=True, null=True)
|
||||
repeat_type = models.SmallIntegerField()
|
||||
next_pop_date = models.DateField(blank=True, null=True)
|
||||
show = models.ForeignKey(Show, models.DO_NOTHING)
|
||||
record = models.SmallIntegerField(blank=True, null=True)
|
||||
|
||||
def get_owner(self):
|
||||
return self.show.get_owner()
|
||||
|
||||
class Meta:
|
||||
managed = False
|
||||
db_table = "cc_show_days"
|
||||
|
||||
|
||||
class ShowHost(models.Model):
|
||||
show = models.ForeignKey(Show, models.DO_NOTHING)
|
||||
subjs = models.ForeignKey("User", models.DO_NOTHING)
|
||||
|
||||
class Meta:
|
||||
managed = False
|
||||
db_table = "cc_show_hosts"
|
||||
|
||||
|
||||
class ShowInstance(models.Model):
|
||||
description = models.CharField(max_length=8192, blank=True, null=True)
|
||||
starts = models.DateTimeField()
|
||||
ends = models.DateTimeField()
|
||||
show = models.ForeignKey(Show, models.DO_NOTHING)
|
||||
record = models.SmallIntegerField(blank=True, null=True)
|
||||
rebroadcast = models.SmallIntegerField(blank=True, null=True)
|
||||
instance = models.ForeignKey("self", models.DO_NOTHING, blank=True, null=True)
|
||||
file = models.ForeignKey(File, models.DO_NOTHING, blank=True, null=True)
|
||||
time_filled = models.DurationField(blank=True, null=True)
|
||||
created = models.DateTimeField()
|
||||
last_scheduled = models.DateTimeField(blank=True, null=True)
|
||||
modified_instance = models.BooleanField()
|
||||
autoplaylist_built = models.BooleanField()
|
||||
|
||||
def get_owner(self):
|
||||
return show.get_owner()
|
||||
|
||||
class Meta:
|
||||
managed = False
|
||||
db_table = "cc_show_instances"
|
||||
|
||||
|
||||
class ShowRebroadcast(models.Model):
|
||||
day_offset = models.CharField(max_length=1024)
|
||||
start_time = models.TimeField()
|
||||
show = models.ForeignKey(Show, models.DO_NOTHING)
|
||||
|
||||
def get_owner(self):
|
||||
return show.get_owner()
|
||||
|
||||
class Meta:
|
||||
managed = False
|
||||
db_table = "cc_show_rebroadcast"
|
83
api/libretime_api/models/smart_blocks.py
Normal file
83
api/libretime_api/models/smart_blocks.py
Normal file
|
@ -0,0 +1,83 @@
|
|||
from django.db import models
|
||||
|
||||
|
||||
class SmartBlock(models.Model):
|
||||
name = models.CharField(max_length=255)
|
||||
mtime = models.DateTimeField(blank=True, null=True)
|
||||
utime = models.DateTimeField(blank=True, null=True)
|
||||
creator = models.ForeignKey("User", models.DO_NOTHING, blank=True, null=True)
|
||||
description = models.CharField(max_length=512, blank=True, null=True)
|
||||
length = models.DurationField(blank=True, null=True)
|
||||
type = models.CharField(max_length=7, blank=True, null=True)
|
||||
|
||||
def get_owner(self):
|
||||
return self.creator
|
||||
|
||||
class Meta:
|
||||
managed = False
|
||||
db_table = "cc_block"
|
||||
permissions = [
|
||||
(
|
||||
"change_own_smartblock",
|
||||
"Change the smartblocks where they are the owner",
|
||||
),
|
||||
(
|
||||
"delete_own_smartblock",
|
||||
"Delete the smartblocks where they are the owner",
|
||||
),
|
||||
]
|
||||
|
||||
|
||||
class SmartBlockContent(models.Model):
|
||||
block = models.ForeignKey(SmartBlock, models.DO_NOTHING, blank=True, null=True)
|
||||
file = models.ForeignKey("File", models.DO_NOTHING, blank=True, null=True)
|
||||
position = models.IntegerField(blank=True, null=True)
|
||||
trackoffset = models.FloatField()
|
||||
cliplength = models.DurationField(blank=True, null=True)
|
||||
cuein = models.DurationField(blank=True, null=True)
|
||||
cueout = models.DurationField(blank=True, null=True)
|
||||
fadein = models.TimeField(blank=True, null=True)
|
||||
fadeout = models.TimeField(blank=True, null=True)
|
||||
|
||||
def get_owner(self):
|
||||
return self.block.get_owner()
|
||||
|
||||
class Meta:
|
||||
managed = False
|
||||
db_table = "cc_blockcontents"
|
||||
permissions = [
|
||||
(
|
||||
"change_own_smartblockcontent",
|
||||
"Change the content of smartblocks where they are the owner",
|
||||
),
|
||||
(
|
||||
"delete_own_smartblockcontent",
|
||||
"Delete the content of smartblocks where they are the owner",
|
||||
),
|
||||
]
|
||||
|
||||
|
||||
class SmartBlockCriteria(models.Model):
|
||||
criteria = models.CharField(max_length=32)
|
||||
modifier = models.CharField(max_length=16)
|
||||
value = models.CharField(max_length=512)
|
||||
extra = models.CharField(max_length=512, blank=True, null=True)
|
||||
criteriagroup = models.IntegerField(blank=True, null=True)
|
||||
block = models.ForeignKey(SmartBlock, models.DO_NOTHING)
|
||||
|
||||
def get_owner(self):
|
||||
return self.block.get_owner()
|
||||
|
||||
class Meta:
|
||||
managed = False
|
||||
db_table = "cc_blockcriteria"
|
||||
permissions = [
|
||||
(
|
||||
"change_own_smartblockcriteria",
|
||||
"Change the criteria of smartblocks where they are the owner",
|
||||
),
|
||||
(
|
||||
"delete_own_smartblockcriteria",
|
||||
"Delete the criteria of smartblocks where they are the owner",
|
||||
),
|
||||
]
|
26
api/libretime_api/models/tracks.py
Normal file
26
api/libretime_api/models/tracks.py
Normal file
|
@ -0,0 +1,26 @@
|
|||
from django.db import models
|
||||
|
||||
from .files import File
|
||||
|
||||
|
||||
class ThirdPartyTrackReference(models.Model):
|
||||
service = models.CharField(max_length=256)
|
||||
foreign_id = models.CharField(unique=True, max_length=256, blank=True, null=True)
|
||||
file = models.ForeignKey(File, models.DO_NOTHING, blank=True, null=True)
|
||||
upload_time = models.DateTimeField(blank=True, null=True)
|
||||
status = models.CharField(max_length=256, blank=True, null=True)
|
||||
|
||||
class Meta:
|
||||
managed = False
|
||||
db_table = "third_party_track_references"
|
||||
|
||||
|
||||
class TrackType(models.Model):
|
||||
code = models.CharField(max_length=16, unique=True)
|
||||
type_name = models.CharField(max_length=255, blank=True, null=True)
|
||||
description = models.CharField(max_length=255, blank=True, null=True)
|
||||
visibility = models.BooleanField(blank=True, default=True)
|
||||
|
||||
class Meta:
|
||||
managed = False
|
||||
db_table = "cc_track_types"
|
11
api/libretime_api/models/user_constants.py
Normal file
11
api/libretime_api/models/user_constants.py
Normal file
|
@ -0,0 +1,11 @@
|
|||
GUEST = "G"
|
||||
DJ = "H"
|
||||
PROGRAM_MANAGER = "P"
|
||||
ADMIN = "A"
|
||||
|
||||
USER_TYPES = {
|
||||
GUEST: "Guest",
|
||||
DJ: "DJ",
|
||||
PROGRAM_MANAGER: "Program Manager",
|
||||
ADMIN: "Admin",
|
||||
}
|
41
api/libretime_api/models/webstreams.py
Normal file
41
api/libretime_api/models/webstreams.py
Normal file
|
@ -0,0 +1,41 @@
|
|||
from django.contrib.auth import get_user_model
|
||||
from django.db import models
|
||||
|
||||
from .schedule import Schedule
|
||||
|
||||
|
||||
class Webstream(models.Model):
|
||||
name = models.CharField(max_length=255)
|
||||
description = models.CharField(max_length=255)
|
||||
url = models.CharField(max_length=512)
|
||||
length = models.DurationField()
|
||||
creator_id = models.IntegerField()
|
||||
mtime = models.DateTimeField()
|
||||
utime = models.DateTimeField()
|
||||
lptime = models.DateTimeField(blank=True, null=True)
|
||||
mime = models.CharField(max_length=1024, blank=True, null=True)
|
||||
|
||||
def get_owner(self):
|
||||
User = get_user_model()
|
||||
return User.objects.get(pk=self.creator_id)
|
||||
|
||||
class Meta:
|
||||
managed = False
|
||||
db_table = "cc_webstream"
|
||||
permissions = [
|
||||
("change_own_webstream", "Change the webstreams where they are the owner"),
|
||||
("delete_own_webstream", "Delete the webstreams where they are the owner"),
|
||||
]
|
||||
|
||||
|
||||
class WebstreamMetadata(models.Model):
|
||||
instance = models.ForeignKey(Schedule, models.DO_NOTHING)
|
||||
start_time = models.DateTimeField()
|
||||
liquidsoap_data = models.CharField(max_length=1024)
|
||||
|
||||
def get_owner(self):
|
||||
return self.instance.get_owner()
|
||||
|
||||
class Meta:
|
||||
managed = False
|
||||
db_table = "cc_webstream_metadata"
|
Loading…
Add table
Add a link
Reference in a new issue