Commit 0a2ae1d3 authored by Brian Guadalupe's avatar Brian Guadalupe

Merge branch 'fix-songs-local' into 'master'

Populate songs table in database (and more)

Closes #4

See merge request brian/mymusiclist!7
parents eacd23d2 92469da4
# run in Django shell ONLY!!!
# python manage.py shell
# >>> exec(open('./SQL/populate_songs.py').read())
from core.models import *
def extract_song_title(s):
clean = []
i = 1
for t in s.split(' ÷'):
if t == '': continue
u = t.strip('\n').split()
if u[0] == '.flac' or u[0] == '.mp3' or u[0] == '.dts':
clean.append(' '.join(t.strip('\n').split()[2:])[:-len(u[0])])
i += 1
return clean
def prettify_genre(g):
return ', '.join([h.replace('_',' ') for h in g.split()])
for song in Song.objects.filter(song_name__startswith="."):
songlst = extract_song_title(song.song_name)
for e in songlst:
Song.objects.create(song_name=e, genre=prettify_genre(song.genre), artist=song.artist, album=song.album)
# uncomment the next line if you want to delete the original entry after parsing
# song.delete()
# if something messed up above, uncomment these lines
# for song in Song.objects.exclude(song_name__startswith="."):
# song.delete()
\ No newline at end of file
...@@ -3,7 +3,7 @@ PRAGMA journal_mode = MEMORY; ...@@ -3,7 +3,7 @@ PRAGMA journal_mode = MEMORY;
BEGIN TRANSACTION; BEGIN TRANSACTION;
INSERT INTO `core_artist` VALUES (409,'Akon','No description available'),(2822,'Maroon 5','No description available'),(3457,'Calvin Harris','No description available'),(14571,'Taylor Swift','No description available'),(42820,'The Script','No description available'),(137257,'Avicii','No description available'),(204743,'Jason Derulo','No description available'),(209178,'Khalid','No description available'),(348773,'Imagine Dragons','No description available'),(383287,'Kendrick Lamar','No description available'),(463487,'ClariS','No description available'),(464253,'Ed Sheeran','No description available'),(475312,'Charlie Puth','No description available'),(613412,'One Direction','No description available'),(986658,'Kygo','No description available'),(1033658,'Zayn','No description available'),(1117531,'Halsey','No description available'),(1189739,'BTS','No description available'),(1243225,'LANY','No description available'),(1427741,'Niall Horan','No description available'); INSERT INTO `core_artist` VALUES (409,'Akon','No description available'),(2822,'Maroon 5','No description available'),(3457,'Calvin Harris','No description available'),(14571,'Taylor Swift','No description available'),(42820,'The Script','No description available'),(137257,'Avicii','No description available'),(204743,'Jason Derulo','No description available'),(209178,'Khalid','No description available'),(348773,'Imagine Dragons','No description available'),(383287,'Kendrick Lamar','No description available'),(463487,'ClariS','No description available'),(464253,'Ed Sheeran','No description available'),(475312,'Charlie Puth','No description available'),(613412,'One Direction','No description available'),(986658,'Kygo','No description available'),(1033658,'Zayn','No description available'),(1117531,'Halsey','No description available'),(1189739,'BTS','No description available'),(1243225,'LANY','No description available'),(1427741,'Niall Horan','No description available');
INSERT INTO `core_album` VALUES (5855,'Trouble',2003,409),(13544,'Konvicted',2006,409),(19129,'Songs About Jane',2002,2822),(19602,'I Created Disco',2007,3457),(30519,'Taylor Swift',2006,14571),(37318,'It Won''t Be Soon Before Long',2007,2822),(203718,'The Script',2008,42820),(295240,'Fearless',2008,14571),(311226,'Freedom',2008,409),(538314,'Ready for the Weekend',2009,3457),(710818,'Jason Derülo',2010,204743),(857392,'Hands All Over',2010,2822),(857450,'Science & Faith',2010,42820),(71829076,'Speak Now',2010,14571),(72002104,'Section.80',2011,383287),(72045386,'+',2011,464253),(72048111,'Future History',2011,204743),(72087084,'Up All Night',2011,613412),(72184080,'BIRTHDAY',2012,463487),(72237573,'Overexposed',2012,2822),(72285595,'Night Visions',2012,348773),(72286759,'#3',2012,42820),(72318070,'good kid, m.A.A.d city',2012,383287),(72318105,'Red',2012,14571),(72324214,'18 Months',2012,3457),(72335503,'Take Me Home',2012,613412),(72519340,'SECOND STORY',2013,463487),(72572571,'TRUE',2013,137257),(72577095,'Tattoos',2013,204743),(72619052,'Midnight Memories',2013,613412),(72701191,'Talk Dirty',2014,204743),(72731395,'PARTY TIME',2014,463487),(72740625,'×',2014,464253),(72783778,'V',2014,2822),(72792151,'No Sound Without Silence',2014,42820),(72817155,'1989',2014,14571),(72819437,'Motion',2014,3457),(72829519,'Four',2014,613412),(72902118,'Smoke + Mirrors',2015,348773),(72926857,'To Pimp a Butterfly',2015,383287),(72981909,'Everything Is 4',2015,204743),(73045308,'Badlands',2015,1117531),(73068131,'Stories',2015,137257),(73098814,'Made In the A.M.',2015,613412),(73155604,'Nine Track Mind',2016,475312),(73184511,'untitled unmastered.',2016,383287),(73198864,'Mind of Mine',2016,1033658),(73233717,'Cloud Nine',2016,986658); INSERT INTO `core_album` VALUES (5855,'Trouble',2003,409),(13544,'Konvicted',2006,409),(19129,'Songs About Jane',2002,2822),(19602,'I Created Disco',2007,3457),(30519,'Taylor Swift',2006,14571),(37318,'It Won''t Be Soon Before Long',2007,2822),(203718,'The Script',2008,42820),(295240,'Fearless',2008,14571),(311226,'Freedom',2008,409),(538314,'Ready for the Weekend',2009,3457),(710818,'Jason Derülo',2010,204743),(857392,'Hands All Over',2010,2822),(857450,'Science & Faith',2010,42820),(71829076,'Speak Now',2010,14571),(72002104,'Section.80',2011,383287),(72045386,'+',2011,464253),(72048111,'Future History',2011,204743),(72087084,'Up All Night',2011,613412),(72184080,'BIRTHDAY',2012,463487),(72237573,'Overexposed',2012,2822),(72285595,'Night Visions',2012,348773),(72286759,'#3',2012,42820),(72318070,'good kid, m.A.A.d city',2012,383287),(72318105,'Red',2012,14571),(72324214,'18 Months',2012,3457),(72335503,'Take Me Home',2012,613412),(72519340,'SECOND STORY',2013,463487),(72572571,'TRUE',2013,137257),(72577095,'Tattoos',2013,204743),(72619052,'Midnight Memories',2013,613412),(72701191,'Talk Dirty',2014,204743),(72731395,'PARTY TIME',2014,463487),(72740625,'×',2014,464253),(72783778,'V',2014,2822),(72792151,'No Sound Without Silence',2014,42820),(72817155,'1989',2014,14571),(72819437,'Motion',2014,3457),(72829519,'Four',2014,613412),(72902118,'Smoke + Mirrors',2015,348773),(72926857,'To Pimp a Butterfly',2015,383287),(72981909,'Everything Is 4',2015,204743),(73045308,'Badlands',2015,1117531),(73068131,'Stories',2015,137257),(73098814,'Made In the A.M.',2015,613412),(73155604,'Nine Track Mind',2016,475312),(73184511,'untitled unmastered.',2016,383287),(73198864,'Mind of Mine',2016,1033658),(73233717,'Cloud Nine',2016,986658);
INSERT INTO `core_song` VALUES (1,'.flac s28257036s Disc 1/01 - Locked Up.flac ÷ INSERT INTO `core_song`(`id`, `song_name`, `genre`, `song_length`, `lyrics`, `artist_id`, `album_id`) VALUES (1,'.flac s28257036s Disc 1/01 - Locked Up.flac ÷
.flac s23390085s Disc 1/02 - Trouble Nobody.flac ÷ .flac s23390085s Disc 1/02 - Trouble Nobody.flac ÷
.flac s30832094s Disc 1/03 - Bananza (Belly Dancer).flac ÷ .flac s30832094s Disc 1/03 - Bananza (Belly Dancer).flac ÷
.flac s31885803s Disc 1/04 - Gangsta (feat. Daddy T, Devyne & Picklehead).flac ÷ .flac s31885803s Disc 1/04 - Gangsta (feat. Daddy T, Devyne & Picklehead).flac ÷
......
from django.contrib import admin from django.contrib import admin
from core.models import *
# Register your models here. # Register your models here.
class AlbumAdmin(admin.ModelAdmin):
list_display = ('album_name', 'artist', 'year')
class ArtistAdmin(admin.ModelAdmin):
list_display = ('name',)
class SongAdmin(admin.ModelAdmin):
list_display = ('song_name', 'artist', 'album')
list_filter = ('artist', 'album',)
admin.site.register(Album, AlbumAdmin)
admin.site.register(Artist, ArtistAdmin)
admin.site.register(Song, SongAdmin)
\ No newline at end of file
from django.db import models from django.db import models
class user_account(models.Model): class UserAccount(models.Model):
id = models.AutoField(primary_key=True) id = models.AutoField(primary_key=True)
first_name = models.CharField(max_length=64) first_name = models.CharField(max_length=64)
last_name = models.CharField(max_length=64) last_name = models.CharField(max_length=64)
email = models.CharField(max_length=64) email = models.CharField(max_length=64)
class artist(models.Model): class Artist(models.Model):
id = models.AutoField(primary_key=True) id = models.AutoField(primary_key=True)
name = models.CharField(max_length=64) name = models.CharField(max_length=64)
description = models.TextField() description = models.TextField()
def __str__(self):
return self.name
class album(models.Model): class Album(models.Model):
id = models.AutoField(primary_key=True) id = models.AutoField(primary_key=True)
album_name = models.CharField(max_length=64) album_name = models.CharField(max_length=64)
year = models.DecimalField(max_digits=4, decimal_places=0) year = models.DecimalField(max_digits=4, decimal_places=0)
artist = models.ForeignKey(artist) artist = models.ForeignKey(Artist)
def __str__(self):
return self.album_name
class song(models.Model): class Song(models.Model):
id = models.AutoField(primary_key=True) id = models.AutoField(primary_key=True)
song_name = models.TextField() song_name = models.TextField()
genre = models.CharField(max_length=128) genre = models.CharField(max_length=128)
song_length = models.PositiveIntegerField(default=0, null=True) song_length = models.PositiveIntegerField(default=0, null=True)
lyrics = models.TextField(null=True) lyrics = models.TextField(null=True)
artist = models.ForeignKey(artist) artist = models.ForeignKey(Artist)
album = models.ForeignKey(album) album = models.ForeignKey(Album)
def __str__(self):
return self.song_name
class music_playlist(models.Model): class MusicPlaylist(models.Model):
id = models.AutoField(primary_key=True) id = models.AutoField(primary_key=True)
playlist_name = models.CharField(max_length=32) playlist_name = models.CharField(max_length=32)
is_public = models.BooleanField(default=False) is_public = models.BooleanField(default=False)
user = models.ForeignKey(user_account) user = models.ForeignKey(UserAccount)
def __str__(self):
return self.playlist_name
class music_entry(models.Model): class MusicEntry(models.Model):
RATING_CHOICES = ( RATING_CHOICES = (
(0,'1'), (0,'1'),
(1,'2'), (1,'2'),
...@@ -48,10 +56,12 @@ class music_entry(models.Model): ...@@ -48,10 +56,12 @@ class music_entry(models.Model):
id = models.AutoField(primary_key=True) id = models.AutoField(primary_key=True)
order_in_playlist = models.PositiveSmallIntegerField() order_in_playlist = models.PositiveSmallIntegerField()
rating = models.DecimalField(max_digits=1, decimal_places=0, choices=RATING_CHOICES) rating = models.DecimalField(max_digits=1, decimal_places=0, choices=RATING_CHOICES)
playlist = models.ForeignKey(music_playlist) playlist = models.ForeignKey(MusicPlaylist)
song = models.ForeignKey(song) song = models.ForeignKey(Song)
class tag(models.Model): class Tag(models.Model):
id = models.AutoField(primary_key=True) id = models.AutoField(primary_key=True)
name = models.CharField(max_length=32) name = models.CharField(max_length=32)
tag = models.ManyToManyField(music_entry) tag = models.ManyToManyField(MusicEntry)
def __str__(self):
return self.name
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment