mirror of
https://github.com/meeb/tubesync.git
synced 2025-06-23 21:46:44 +00:00
Use V
for models.py
This commit is contained in:
parent
7638500188
commit
58b98739ee
@ -26,9 +26,11 @@ from .matching import (get_best_combined_format, get_best_audio_format,
|
|||||||
get_best_video_format)
|
get_best_video_format)
|
||||||
from .mediaservers import PlexMediaServer
|
from .mediaservers import PlexMediaServer
|
||||||
from .fields import CommaSepChoiceField
|
from .fields import CommaSepChoiceField
|
||||||
from .choices import (CapChoices, Fallback, IndexSchedule, MediaServerType,
|
from .choices import (V, CapChoices, Fallback, FileExtension,
|
||||||
|
IndexSchedule, MediaServerType,
|
||||||
SourceResolution, SourceResolutionInteger,
|
SourceResolution, SourceResolutionInteger,
|
||||||
SponsorBlock_Category, YouTube_SourceType)
|
SponsorBlock_Category, YouTube_AudioCodec,
|
||||||
|
YouTube_SourceType, YouTube_VideoCodec)
|
||||||
|
|
||||||
media_file_storage = FileSystemStorage(location=str(settings.DOWNLOAD_ROOT), base_url='/media-data/')
|
media_file_storage = FileSystemStorage(location=str(settings.DOWNLOAD_ROOT), base_url='/media-data/')
|
||||||
|
|
||||||
@ -38,46 +40,31 @@ class Source(models.Model):
|
|||||||
or a YouTube playlist.
|
or a YouTube playlist.
|
||||||
'''
|
'''
|
||||||
|
|
||||||
SOURCE_TYPE_YOUTUBE_CHANNEL = YouTube_SourceType.CHANNEL.value
|
EXTENSIONS = FileExtension.values
|
||||||
SOURCE_TYPE_YOUTUBE_CHANNEL_ID = YouTube_SourceType.CHANNEL_ID.value
|
|
||||||
SOURCE_TYPE_YOUTUBE_PLAYLIST = YouTube_SourceType.PLAYLIST.value
|
|
||||||
|
|
||||||
SOURCE_RESOLUTION_1080P = SourceResolution.VIDEO_1080P.value
|
SOURCE_TYPE_YOUTUBE_CHANNEL = V(YouTube_SourceType.CHANNEL)
|
||||||
SOURCE_RESOLUTION_AUDIO = SourceResolution.AUDIO.value
|
SOURCE_TYPE_YOUTUBE_CHANNEL_ID = V(YouTube_SourceType.CHANNEL_ID)
|
||||||
|
SOURCE_TYPE_YOUTUBE_PLAYLIST = V(YouTube_SourceType.PLAYLIST)
|
||||||
|
|
||||||
|
SOURCE_RESOLUTION_1080P = V(SourceResolution.VIDEO_1080P)
|
||||||
|
SOURCE_RESOLUTION_AUDIO = V(SourceResolution.AUDIO)
|
||||||
SOURCE_RESOLUTIONS = SourceResolution.values
|
SOURCE_RESOLUTIONS = SourceResolution.values
|
||||||
|
|
||||||
SOURCE_VCODEC_AVC1 = 'AVC1'
|
SOURCE_VCODEC_VP9 = V(YouTube_VideoCodec.VP9)
|
||||||
SOURCE_VCODEC_VP9 = 'VP9'
|
SOURCE_VCODEC_CHOICES = list(reversed(YouTube_VideoCodec.choices[1:]))
|
||||||
SOURCE_VCODECS = (SOURCE_VCODEC_AVC1, SOURCE_VCODEC_VP9)
|
|
||||||
SOURCE_VCODECS_PRIORITY = (SOURCE_VCODEC_VP9, SOURCE_VCODEC_AVC1)
|
|
||||||
SOURCE_VCODEC_CHOICES = (
|
|
||||||
(SOURCE_VCODEC_AVC1, _('AVC1 (H.264)')),
|
|
||||||
(SOURCE_VCODEC_VP9, _('VP9')),
|
|
||||||
)
|
|
||||||
|
|
||||||
SOURCE_ACODEC_MP4A = 'MP4A'
|
SOURCE_ACODEC_OPUS = V(YouTube_AudioCodec.OPUS)
|
||||||
SOURCE_ACODEC_OPUS = 'OPUS'
|
SOURCE_ACODEC_CHOICES = list(reversed(YouTube_AudioCodec.choices))
|
||||||
SOURCE_ACODECS = (SOURCE_ACODEC_MP4A, SOURCE_ACODEC_OPUS)
|
|
||||||
SOURCE_ACODEC_PRIORITY = (SOURCE_ACODEC_OPUS, SOURCE_ACODEC_MP4A)
|
|
||||||
SOURCE_ACODEC_CHOICES = (
|
|
||||||
(SOURCE_ACODEC_MP4A, _('MP4A')),
|
|
||||||
(SOURCE_ACODEC_OPUS, _('OPUS')),
|
|
||||||
)
|
|
||||||
|
|
||||||
FALLBACK_FAIL = Fallback.FAIL.value
|
FALLBACK_FAIL = V(Fallback.FAIL)
|
||||||
FALLBACK_NEXT_BEST = Fallback.NEXT_BEST.value
|
FALLBACK_NEXT_BEST = V(Fallback.NEXT_BEST)
|
||||||
FALLBACK_NEXT_BEST_HD = Fallback.NEXT_BEST_HD.value
|
FALLBACK_NEXT_BEST_HD = V(Fallback.NEXT_BEST_HD)
|
||||||
|
|
||||||
FILTER_SECONDS_CHOICES = (
|
FILTER_SECONDS_CHOICES = (
|
||||||
(True, _('Minimum Length')),
|
(True, _('Minimum Length')),
|
||||||
(False, _('Maximum Length')),
|
(False, _('Maximum Length')),
|
||||||
)
|
)
|
||||||
|
|
||||||
EXTENSION_M4A = 'm4a'
|
|
||||||
EXTENSION_OGG = 'ogg'
|
|
||||||
EXTENSION_MKV = 'mkv'
|
|
||||||
EXTENSIONS = (EXTENSION_M4A, EXTENSION_OGG, EXTENSION_MKV)
|
|
||||||
|
|
||||||
sponsorblock_categories = CommaSepChoiceField(
|
sponsorblock_categories = CommaSepChoiceField(
|
||||||
_(''),
|
_(''),
|
||||||
max_length=128,
|
max_length=128,
|
||||||
@ -277,7 +264,7 @@ class Source(models.Model):
|
|||||||
max_length=8,
|
max_length=8,
|
||||||
db_index=True,
|
db_index=True,
|
||||||
choices=SOURCE_VCODEC_CHOICES,
|
choices=SOURCE_VCODEC_CHOICES,
|
||||||
default=SOURCE_VCODEC_VP9,
|
default=YouTube_VideoCodec.VP9,
|
||||||
help_text=_('Source video codec, desired video encoding format to download (ignored if "resolution" is audio only)')
|
help_text=_('Source video codec, desired video encoding format to download (ignored if "resolution" is audio only)')
|
||||||
)
|
)
|
||||||
source_acodec = models.CharField(
|
source_acodec = models.CharField(
|
||||||
@ -285,7 +272,7 @@ class Source(models.Model):
|
|||||||
max_length=8,
|
max_length=8,
|
||||||
db_index=True,
|
db_index=True,
|
||||||
choices=SOURCE_ACODEC_CHOICES,
|
choices=SOURCE_ACODEC_CHOICES,
|
||||||
default=SOURCE_ACODEC_OPUS,
|
default=YouTube_AudioCodec.OPUS,
|
||||||
help_text=_('Source audio codec, desired audio encoding format to download')
|
help_text=_('Source audio codec, desired audio encoding format to download')
|
||||||
)
|
)
|
||||||
prefer_60fps = models.BooleanField(
|
prefer_60fps = models.BooleanField(
|
||||||
@ -374,7 +361,7 @@ class Source(models.Model):
|
|||||||
|
|
||||||
@property
|
@property
|
||||||
def is_audio(self):
|
def is_audio(self):
|
||||||
return self.source_resolution == SourceResolution.AUDIO.value
|
return self.source_resolution == V(SourceResolution.AUDIO)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def is_video(self):
|
def is_video(self):
|
||||||
@ -406,14 +393,14 @@ class Source(models.Model):
|
|||||||
depending on audio codec.
|
depending on audio codec.
|
||||||
'''
|
'''
|
||||||
if self.is_audio:
|
if self.is_audio:
|
||||||
if self.source_acodec == self.SOURCE_ACODEC_MP4A:
|
if self.source_acodec == V(YouTube_AudioCodec.MP4A):
|
||||||
return self.EXTENSION_M4A
|
return V(FileExtension.M4A)
|
||||||
elif self.source_acodec == self.SOURCE_ACODEC_OPUS:
|
elif self.source_acodec == V(YouTube_AudioCodec.OPUS):
|
||||||
return self.EXTENSION_OGG
|
return V(FileExtension.OGG)
|
||||||
else:
|
else:
|
||||||
raise ValueError('Unable to choose audio extension, uknown acodec')
|
raise ValueError('Unable to choose audio extension, uknown acodec')
|
||||||
else:
|
else:
|
||||||
return self.EXTENSION_MKV
|
return V(FileExtension.MKV)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def create_url(obj, source_type, key):
|
def create_url(obj, source_type, key):
|
||||||
@ -434,7 +421,7 @@ class Source(models.Model):
|
|||||||
|
|
||||||
@property
|
@property
|
||||||
def format_summary(self):
|
def format_summary(self):
|
||||||
if self.source_resolution == SourceResolution.AUDIO.value:
|
if self.is_audio:
|
||||||
vc = 'none'
|
vc = 'none'
|
||||||
else:
|
else:
|
||||||
vc = self.source_vcodec
|
vc = self.source_vcodec
|
||||||
@ -451,7 +438,7 @@ class Source(models.Model):
|
|||||||
@property
|
@property
|
||||||
def type_directory_path(self):
|
def type_directory_path(self):
|
||||||
if settings.SOURCE_DOWNLOAD_DIRECTORY_PREFIX:
|
if settings.SOURCE_DOWNLOAD_DIRECTORY_PREFIX:
|
||||||
if self.source_resolution == SourceResolution.AUDIO.value:
|
if self.is_audio:
|
||||||
return Path(settings.DOWNLOAD_AUDIO_DIR) / self.directory
|
return Path(settings.DOWNLOAD_AUDIO_DIR) / self.directory
|
||||||
else:
|
else:
|
||||||
return Path(settings.DOWNLOAD_VIDEO_DIR) / self.directory
|
return Path(settings.DOWNLOAD_VIDEO_DIR) / self.directory
|
||||||
@ -965,12 +952,12 @@ class Media(models.Model):
|
|||||||
resolution = self.downloaded_format.lower()
|
resolution = self.downloaded_format.lower()
|
||||||
elif self.downloaded_height:
|
elif self.downloaded_height:
|
||||||
resolution = f'{self.downloaded_height}p'
|
resolution = f'{self.downloaded_height}p'
|
||||||
if self.downloaded_format != 'audio':
|
if self.downloaded_format != V(SourceResolution.AUDIO):
|
||||||
vcodec = self.downloaded_video_codec.lower()
|
vcodec = self.downloaded_video_codec.lower()
|
||||||
fmt.append(vcodec)
|
fmt.append(vcodec)
|
||||||
acodec = self.downloaded_audio_codec.lower()
|
acodec = self.downloaded_audio_codec.lower()
|
||||||
fmt.append(acodec)
|
fmt.append(acodec)
|
||||||
if self.downloaded_format != 'audio':
|
if self.downloaded_format != V(SourceResolution.AUDIO):
|
||||||
fps = str(self.downloaded_fps)
|
fps = str(self.downloaded_fps)
|
||||||
fmt.append(f'{fps}fps')
|
fmt.append(f'{fps}fps')
|
||||||
if self.downloaded_hdr:
|
if self.downloaded_hdr:
|
||||||
@ -1294,19 +1281,19 @@ class Media(models.Model):
|
|||||||
acodec = self.downloaded_audio_codec
|
acodec = self.downloaded_audio_codec
|
||||||
if acodec is None:
|
if acodec is None:
|
||||||
raise TypeError() # nothing here.
|
raise TypeError() # nothing here.
|
||||||
acodec = acodec.lower()
|
acodec = acodec.upper()
|
||||||
if acodec == "mp4a":
|
if acodec == V(YouTube_AudioCodec.MP4A):
|
||||||
return "audio/mp4"
|
return "audio/mp4"
|
||||||
elif acodec == "opus":
|
elif acodec == V(YouTube_AudioCodec.OPUS):
|
||||||
return "audio/opus"
|
return "audio/opus"
|
||||||
else:
|
else:
|
||||||
# fall-fall-back.
|
# fall-fall-back.
|
||||||
return 'audio/ogg'
|
return 'audio/ogg'
|
||||||
vcodec = vcodec.lower()
|
vcodec = vcodec.upper()
|
||||||
if vcodec == 'vp9':
|
if vcodec == V(YouTube_VideoCodec.AVC1):
|
||||||
return 'video/webm'
|
|
||||||
else:
|
|
||||||
return 'video/mp4'
|
return 'video/mp4'
|
||||||
|
else:
|
||||||
|
return 'video/matroska'
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def nfoxml(self):
|
def nfoxml(self):
|
||||||
@ -1580,12 +1567,12 @@ class MediaServer(models.Model):
|
|||||||
A remote media server, such as a Plex server.
|
A remote media server, such as a Plex server.
|
||||||
'''
|
'''
|
||||||
|
|
||||||
SERVER_TYPE_PLEX = MediaServerType.PLEX.value
|
SERVER_TYPE_PLEX = V(MediaServerType.PLEX)
|
||||||
ICONS = {
|
ICONS = {
|
||||||
SERVER_TYPE_PLEX: '<i class="fas fa-server"></i>',
|
V(MediaServerType.PLEX): '<i class="fas fa-server"></i>',
|
||||||
}
|
}
|
||||||
HANDLERS = {
|
HANDLERS = {
|
||||||
SERVER_TYPE_PLEX: PlexMediaServer,
|
V(MediaServerType.PLEX): PlexMediaServer,
|
||||||
}
|
}
|
||||||
|
|
||||||
server_type = models.CharField(
|
server_type = models.CharField(
|
||||||
|
Loading…
Reference in New Issue
Block a user