Spotify
This module connects the LNLDB with LNL’s Spotify accounts via the Spotify Web API. Note that this integration is not currently available for use with personal Spotify accounts.
Models
- class spotify.models.Session(*args, **kwargs)[source]
Spotify song request session for a specific event
- Parameters:
id (AutoField) – Id (required)
event (ForeignKey to
Event2019) – Event (required)accepting_requests (BooleanField) – Accepting requests (default=True)
allow_explicit (BooleanField) – Allow explicit (default=True)
auto_approve (BooleanField) – Auto approve (default=False)
require_payment (BooleanField) – Require payment (default=False)
allow_silence (BooleanField) – Allow silence (default=False)
private (BooleanField) – Private (default=False)
user (ForeignKey to
SpotifyUser) – User (required)slug (SlugField) – Slug (required)
paypal (URLField) – PayPal.Me Link
venmo (CharField) – Venmo username
venmo_verification (CharField) – Venmo verification
- exception DoesNotExist
- exception MultipleObjectsReturned
- accepting_requests
BooleanField(default=True)
- allow_explicit
BooleanField(default=True)
- allow_silence
BooleanField(default=False)
- auto_approve
BooleanField(default=False)
- id
AutoField(verbose_name=”ID”, primary_key=True, serialize=False, auto_created=True)
- objects = <django.db.models.manager.Manager object>
- paypal
CharField(blank=True, null=True, help_text=”PayPal.Me Link”)
Paypal: PayPal.Me Link
- private
BooleanField(default=False)
- require_payment
BooleanField(default=False)
- save(*args, **kwargs)[source]
Save the current instance. Override this in a subclass if you want to control the saving process.
The ‘force_insert’ and ‘force_update’ parameters can be used to insist that the “save” must be an SQL insert or update (or equivalent for non-SQL backends), respectively. Normally, they should not be set.
- slug
SlugField(max_length=128, unique=True)
- user
ForeignKey(on_delete=CASCADE(), to=
SpotifyUser)
- venmo
CharField(max_length=16, blank=True, null=True, help_text=”Venmo username”)
Venmo: Venmo username
- venmo_verification
CharField(max_length=4, blank=True, null=True)
- class spotify.models.SongRequest(*args, **kwargs)[source]
Used in keeping track of a song request
- Parameters:
id (AutoField) – Id (required)
session (ForeignKey to
Session) – Session (required)name (CharField) – Name (required)
identifier (CharField) – Identifier (required)
duration (IntegerField) – Duration in ms (required)
approved (BooleanField) – Approved (default=False)
queued (DateTimeField) – Queued
paid (BooleanField) – Paid (default=False)
submitted_by (CharField) – Submitted by (required)
email (EmailField) – Email
phone (CharField) – Phone
- exception DoesNotExist
- exception MultipleObjectsReturned
- approved
BooleanField(default=False)
- duration
IntegerField(help_text=”Duration in ms”)
Duration: Duration in ms
- email
CharField(max_length=254, blank=True, null=True)
- id
AutoField(verbose_name=”ID”, primary_key=True, serialize=False, auto_created=True)
- identifier
CharField(max_length=32)
- name
CharField(max_length=150)
- objects = <django.db.models.manager.Manager object>
- paid
BooleanField(default=False)
- phone
CharField(max_length=24, blank=True, null=True)
- queued
DateTimeField(blank=True, null=True)
- submitted_by
CharField(max_length=150)
- class spotify.models.SpotifyUser(*args, **kwargs)[source]
Represents a user’s Spotify Account. Authentication tokens will be saved here.
- Parameters:
id (AutoField) – Id (required)
user (ForeignKey to
User) – User (required)display_name (CharField) – Display name
spotify_id (CharField) – Spotify id
token_info (TextField) – Token info
personal (BooleanField) – Uncheck this for shared club accounts (default=True)
- exception DoesNotExist
- exception MultipleObjectsReturned
- display_name
CharField(max_length=150, blank=True, null=True)
- id
AutoField(verbose_name=”ID”, primary_key=True, serialize=False, auto_created=True)
- objects = <django.db.models.manager.Manager object>
- personal
BooleanField(default=True, help_text=”Uncheck this for shared club accounts”)
Personal: Uncheck this for shared club accounts
- spotify_id
CharField(max_length=150, blank=True, null=True)
- token_info
TextField(blank=True, null=True)
API Methods
- class spotify.api.DjangoCacheHandler(user, account_id=None)[source]
Custom Spotipy cache handler. Saves authentication information to the database.
- exception spotify.api.SpotifySessionError(message, error=None, error_description=None, *args, **kwargs)[source]
- spotify.api.add_to_queue(song_request, request_user)[source]
Attempt to add a track to the Spotify queue
- Parameters:
song_request – Song request object
request_user – The user currently logged in (User object)
- Returns:
None on success; SpotifyException otherwise
- spotify.api.get_available_devices(account)[source]
Retrieves information about a Spotify user’s available devices
- Parameters:
account – The corresponding SpotifyUser object
- Returns:
Device info (List of Dictionaries)
- spotify.api.get_currently_playing(session)[source]
Attempts to get details about what is currently playing in Spotify
- Parameters:
session – The corresponding Session object
- Returns:
Item metadata, if available (Dictionary)
- spotify.api.get_playback_state(session)[source]
Retrieves information about the session’s current playback state
- Parameters:
session – The corresponding Session object
- Returns:
Playback state information (Dictionary)
- spotify.api.get_spotify_session(account, request_user)[source]
Call this method to get a Spotify session for a specific Spotify account.
- Parameters:
account – SpotifyUser object
request_user – The user currently logged in (User object)
- Returns:
A Spotify object (manages the session and API calls)
- spotify.api.get_track(session, identifier)[source]
Retrieves the metadata for a given item in Spotify
- Parameters:
session – A Session object (used for authenticating the request)
identifier – The unique Spotify ID for the item
- Returns:
Item metadata, if available (Dictionary)
- spotify.api.pause(session)[source]
Pause playback for a given session.
- Parameters:
session – The corresponding Session object
- Returns:
None (if successful); Error message otherwise (string)
- spotify.api.play(session, device=None)[source]
Starts or resumes playback for a given session.
- Parameters:
session – The corresponding Session object
device – The unique id of the device to start playback on
- Returns:
None (if successful); Error message otherwise (string)
- spotify.api.previous(session)[source]
Skip to the previous track.
- Parameters:
session – The corresponding Session object
- Returns:
None (if successful); Error message otherwise (string)
Views
- spotify.views.configure_session(request, event_id)[source]
Set up a Spotify shared listening session and begin accepting song requests for an event
- Parameters:
event_id – The primary key value of the event the session is attached to
- spotify.views.generate_qr_code(request, session_id)[source]
Generate a QR Code
- Parameters:
session_id – The primary key value of the shared listening session
- spotify.views.pay_fee(request, session_id)[source]
If payment is required when making a song request, this page should be displayed.
- Parameters:
session_id – The primary key value of the session object
- spotify.views.queue_manager(request, session)[source]
Manage or view song requests
- Parameters:
session – The primary key value of the session object
Forms
- class spotify.forms.SongRequestForm(session, *args, **kwargs)[source]
- class Meta[source]
- fields = ('email', 'phone')
- model
alias of
SongRequest
- base_fields = {'email': <django.forms.fields.EmailField object>, 'first_name': <django.forms.fields.CharField object>, 'last_name': <django.forms.fields.CharField object>, 'phone': <django.forms.fields.CharField object>, 'request_type': <django.forms.fields.ChoiceField object>}
- clean()[source]
Hook for doing any extra form-wide cleaning after Field.clean() has been called on every field. Any ValidationError raised by this method will not be associated with a particular field; it will have a special-case association with the field named ‘__all__’.
- declared_fields = {'first_name': <django.forms.fields.CharField object>, 'last_name': <django.forms.fields.CharField object>, 'request_type': <django.forms.fields.ChoiceField object>}
- property media
Return all media required to render the widgets on this form.
- class spotify.forms.SpotifySessionForm(request_user, *args, **kwargs)[source]
- class Meta[source]
- fields = ('user', 'accepting_requests', 'allow_explicit', 'require_payment', 'auto_approve', 'private', 'allow_silence', 'paypal', 'venmo', 'venmo_verification')
- base_fields = {'accepting_requests': <django.forms.fields.BooleanField object>, 'allow_explicit': <django.forms.fields.BooleanField object>, 'allow_silence': <django.forms.fields.BooleanField object>, 'auto_approve': <django.forms.fields.BooleanField object>, 'paypal': <django.forms.fields.URLField object>, 'private': <django.forms.fields.BooleanField object>, 'require_payment': <django.forms.fields.BooleanField object>, 'user': <django.forms.models.ModelChoiceField object>, 'venmo': <django.forms.fields.CharField object>, 'venmo_verification': <django.forms.fields.CharField object>}
- declared_fields = {'auto_approve': <django.forms.fields.BooleanField object>, 'paypal': <django.forms.fields.URLField object>, 'private': <django.forms.fields.BooleanField object>, 'user': <django.forms.models.ModelChoiceField object>, 'venmo_verification': <django.forms.fields.CharField object>}
- property media
Return all media required to render the widgets on this form.