1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
|
import os
import uuid
from django.db import models
from django.urls import reverse
from django.template.defaultfilters import slugify
from django.conf import settings
# optional external dependencies
try:
from licenses.models import License
except:
License = None
from taggit.managers import TaggableManager
from mutagen.mp3 import MP3
from media.models import LuxAudio, LuxImage
def get_show_upload_folder(instance, pathname):
"A standardized pathname for uploaded files and images."
root, ext = os.path.splitext(pathname)
return "{0}/podcasts/{1}/{2}{3}".format(
settings.PODCASTING_IMG_PATH, instance.slug, slugify(root), ext
)
def get_episode_upload_folder(instance, pathname):
"A standardized pathname for uploaded files and images."
root, ext = os.path.splitext(pathname)
if instance.shows.count() == 1:
return "{0}/podcasts/{1}/episodes/{2}{3}".format(
settings.PODCASTING_IMG_PATH, instance.shows.all()[0].slug, slugify(root), ext
)
else:
return "{0}/podcasts/episodes/{1}/{2}{3}".format(
settings.PODCASTING_IMG_PATH, instance.slug, slugify(root), ext
)
MIME_CHOICES = (
("mp3", "audio/mpeg"),
("mp4", "audio/mp4"),
("ogg", "audio/ogg"),
)
#audio = MP3("example.mp3")
#print(audio.info.length)
class Podcast(models.Model):
uuid = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False)
title = models.CharField(max_length=255)
subtitle = models.CharField(max_length=255, blank=True, null=True)
slug = models.SlugField()
publisher = models.CharField(max_length=255)
publisher_email = models.CharField(max_length=255)
description = models.TextField()
keywords = models.CharField(max_length=255, blank=True, help_text="A comma-delimited list of words for searches, up to 12;")
license = models.TextField(blank=True, null=True)
featured_image = models.ForeignKey(LuxImage, on_delete=models.CASCADE, null=True, blank=True, help_text=("square JPEG (.jpg) or PNG (.png) image at a size of 1400x1400 pixels."))
class Meta:
verbose_name = "Podcast"
verbose_name_plural = "Podcasts"
ordering = ("title", "slug")
def __str__(self):
return self.title
def get_absolute_url(self):
return reverse("podcasts:list", kwargs={"slug": self.slug})
def ttl(self):
return "1440"
class Episode(models.Model):
"""
An individual podcast episode and it's unique attributes.
"""
id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False)
title = models.CharField(max_length=255)
subtitle = models.CharField(max_length=255, blank=True, null=True)
date_created = models.DateTimeField(auto_now_add=True, editable=False)
date_updated = models.DateTimeField(auto_now=True, editable=False)
pub_date = models.DateTimeField(null=True, blank=True)
podcast = models.ForeignKey(Podcast, on_delete=models.PROTECT)
enable_comments = models.BooleanField(default=True)
slug = models.SlugField()
PUB_STATUS = (
(0, 'Draft'),
(1, 'Published'),
)
status = models.IntegerField(choices=PUB_STATUS, default=0)
description = models.TextField()
featured_image = models.ForeignKey(LuxImage, on_delete=models.CASCADE, null=True, blank=True, help_text=("square JPEG (.jpg) or PNG (.png) image at a size of 1400x1400 pixels."))
# iTunes specific fields
keywords = models.CharField(max_length=255, blank=True, help_text="A comma-delimited list of words for searches, up to 12;")
class Meta:
verbose_name = "Episode"
verbose_name_plural = "Episodes"
ordering = ("-pub_date", "slug")
def __str__(self):
return self.title
def get_absolute_url(self):
return reverse("podcasting_episode_detail", kwargs={"show_slug": self.shows.all()[0].slug, "slug": self.slug})
def get_next(self):
next = self.__class__.objects.filter(published__gt=self.published)
try:
return next[0]
except IndexError:
return False
def get_prev(self):
prev = self.__class__.objects.filter(published__lt=self.published).order_by("-published")
try:
return prev[0]
except IndexError:
return False
def get_explicit_display(self):
return "no"
def seconds_total(self):
try:
return self.minutes * 60 + self.seconds
except:
return 0
|