Skip to content

Commit

Permalink
Merge pull request #658 from tcely/patch-5
Browse files Browse the repository at this point in the history
Use TextChoices for SponsorBlock_Category
  • Loading branch information
meeb authored Jan 29, 2025
2 parents ee32f23 + f60c1d7 commit e0bcd33
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 14 deletions.
19 changes: 19 additions & 0 deletions tubesync/sync/fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,25 @@
from typing import Any, Optional, Dict
from django.utils.translation import gettext_lazy as _


# as stolen from:
# - https://wiki.sponsor.ajay.app/w/Types
# - https://github.com/yt-dlp/yt-dlp/blob/master/yt_dlp/postprocessor/sponsorblock.py
#
# The spacing is a little odd, it is for easy copy/paste selection.
# Please don't change it.
# Every possible category fits in a string < 128 characters
class SponsorBlock_Category(models.TextChoices):
SPONSOR = 'sponsor', _( 'Sponsor' )
INTRO = 'intro', _( 'Intermission/Intro Animation' )
OUTRO = 'outro', _( 'Endcards/Credits' )
SELFPROMO = 'selfpromo', _( 'Unpaid/Self Promotion' )
PREVIEW = 'preview', _( 'Preview/Recap' )
FILLER = 'filler', _( 'Filler Tangent' )
INTERACTION = 'interaction', _( 'Interaction Reminder' )
MUSIC_OFFTOPIC = 'music_offtopic', _( 'Non-Music Section' )


# this is a form field!
class CustomCheckboxSelectMultiple(CheckboxSelectMultiple):
template_name = 'widgets/checkbox_select.html'
Expand Down
16 changes: 2 additions & 14 deletions tubesync/sync/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
from .matching import (get_best_combined_format, get_best_audio_format,
get_best_video_format)
from .mediaservers import PlexMediaServer
from .fields import CommaSepChoiceField
from .fields import CommaSepChoiceField, SponsorBlock_Category

media_file_storage = FileSystemStorage(location=str(settings.DOWNLOAD_ROOT), base_url='/media-data/')

Expand Down Expand Up @@ -116,21 +116,9 @@ class Source(models.Model):
EXTENSION_MKV = 'mkv'
EXTENSIONS = (EXTENSION_M4A, EXTENSION_OGG, EXTENSION_MKV)

# as stolen from: https://wiki.sponsor.ajay.app/w/Types / https://github.com/yt-dlp/yt-dlp/blob/master/yt_dlp/postprocessor/sponsorblock.py
SPONSORBLOCK_CATEGORIES_CHOICES = (
('sponsor', 'Sponsor'),
('intro', 'Intermission/Intro Animation'),
('outro', 'Endcards/Credits'),
('selfpromo', 'Unpaid/Self Promotion'),
('preview', 'Preview/Recap'),
('filler', 'Filler Tangent'),
('interaction', 'Interaction Reminder'),
('music_offtopic', 'Non-Music Section'),
)

sponsorblock_categories = CommaSepChoiceField(
_(''),
possible_choices=SPONSORBLOCK_CATEGORIES_CHOICES,
possible_choices=SponsorBlock_Category.choices,
all_choice='all',
allow_all=True,
all_label='(all options)',
Expand Down

0 comments on commit e0bcd33

Please sign in to comment.