def sync_artist(self, artist_name): artist_by_name = Artist.objects.filter(name=artist_name); if not artist_by_name: new_artist = Artist() new_artist.name = artist_name new_artist.save() return new_artist return artist_by_name[0]
def test_track_to_string(self): """ track string presentation must be equal to artist and title """ artist = Artist(name="Artist Name") artist.save() track = Track(artist=artist, title="Track Title") self.assertEqual(str(track), artist.name + ' - ' + track.title)
def create_artist(sp_artist, client): client = client #print sp_artist sp_unique = sp_artist['id'] client_unique = sp_unique sp_uri = sp_artist['uri'] uri = sp_uri sp_name = sp_artist['name'] name = sp_name sp_href = sp_artist['href'] href = sp_href sp_popularity = sp_artist['popularity'] popularity = sp_popularity sp_followers = sp_artist['followers']['total'] followers = sp_followers if len(sp_artist['images'])==0: image_url=None image_width=None image_height=None else: for image in sp_artist['images']: image_width = image['width'] image_height = image['width'] if image_width <= 700 and image_height <= 700: image_url = image['url'] break new_artist = Artist( client=client, client_unique=client_unique, uri=uri, name=name, href=href, popularity=popularity, followers=followers, image_url=image_url, image_width=image_width, image_height=image_height ) new_artist.save() return new_artist
def setUp(self): song = Song() song.title = "Basket Case" song.file_path = "burgle/data/pandora/Basket Case.mp3" artist = Artist() artist.name = 'Green Day' artist.save() song.artist = artist album = Album() album.title = 'Dookie' album.save() song.album = album song.station_id = int('21312') song.save() genre = Genre() genre.name = 'Rock' genre.save() song.genres.add(genre)
def getOrCreateArtist(self, artist): name = artist.get_name() mbid = artist.get_mbid() similar_artist = None if mbid: try: similar_artist = Artist.objects.get(music_brainz_id=mbid) #if the artist is already in the database but names don't match #refrain from adding them if simiar_artist.name != name: return None except: print "Adding Artist: " + name similar_artist = Artist(name=name, music_brainz_id=mbid) try: similar_artist.save() except: return None return similar_artist
def setUp(self): seed = str(random.randint(1, 100000)) song = Song() song.title = 'Basket Case' pandora_url = 'http://audio-dc6-t1-1.pandora.com/access/6394738923373318898?version=4&lid=55475035&token=ltvKtTCJqaVK0%2FRsqx6FVl92LrWl3riBZtqhXMaoAQGBaZ5CflwAEnJO%2B7CSl%2FFyxIkYLmsL31krBpS3lnPj0PBX0UkSU0BFmh6BBO2wsUwUWvwFu2hyUHpWaJLcL7eJtEl08SKzQswNULEPr3V0R5JD64rB0ANyYc4YeDVSMs9m%2Fo5PITxWQlermntRbN1B2cGg4mi%2BOxQEHWnbwwoRKeQG6c0mv1qHasdMQXJrXc%2FxoUJM7az1yklTPW8LUnmaRho%2BxYBWhmJ5XBjMQtBt89moJVNfi9Cx08fUBf2GU369d63N1HACf86Nt1rcKRgS6NhaBngwjBPeJY0XBR76JesF%2BBQJHUKR' song.audio_url = pandora_url artist = Artist() artist.name = 'Green Day' artist.save() song.artist = artist album = Album() album.title = 'TestAlbum-' + str(seed) album.save() song.album = album song.station_id = int(seed) song.save() genre = Genre() genre.name = 'Rock' genre.save() song.genres.add(genre)
def setUp(self): for i in range(10): seed = str(random.randint(1, 100000)) song = Song() song.title = 'Demo' song.audio_url = 'test/music/demo.mp3' artist = Artist() artist.name = 'TestArtist-' + seed artist.save() song.artist = artist album = Album() album.title = 'TestAlbum-' + seed album.save() song.album = album song.station_id = int(seed) song.save() genre = Genre() genre.name = 'TestGenre-' + seed genre.save() song.genres.add(genre) self.test_songs.append(song)
def upload_handler(request): if request.method == "POST": f = request.FILES["upload"] filename = str(f) f_ext = os.path.splitext(str(f))[1] # If file is a compatible music file, build a filesystem structure for # it (media/artist-name/album-name), then write it to that location and # add details of the file to the database. if f_ext in [".mp3", ".MP3"]: with open(MEDIA_ROOT + str(f), "wb") as destination: for chunk in f.chunks(): destination.write(chunk) filename = eyed3.load(MEDIA_ROOT + filename) dir_struct = MEDIA_ROOT + "music" + "/" + filename.tag.artist + "/" + filename.tag.album + "/" try: if not os.path.isdir(dir_struct): os.makedirs(dir_struct) shutil.move(MEDIA_ROOT + str(f), dir_struct) except OSError as ose: if ose.errno != 17: raise # Need to pass on Errno 17, due to race conditions caused # by making directories that already exist. pass except Exception as e: # File already exists. Remove the duplicate copy. os.remove(MEDIA_ROOT + str(f)) return render_to_response( "errors/file_already_exists.html", locals(), context_instance=RequestContext(request) ) # If the artist or album doesn't exist in the database, create # table(s) for them. If they already exists, perform a query to # obtain an Artist or Album object for use as a foreign key. if not Artist.objects.filter(name=filename.tag.artist).exists(): artist = Artist(name=filename.tag.artist) artist.save() else: artist_set = Artist.objects.filter(name=filename.tag.artist) artist = [a for a in artist_set][0] if not Album.objects.filter(title=filename.tag.album).exists(): album = Album(title=filename.tag.album, artist=artist) album.save() else: album_set = Album.objects.filter(title=filename.tag.album) album = [a for a in album_set][0] if not Track.objects.filter(title=filename.tag.title).exists(): track = Track( title=filename.tag.title, album=album, artist=artist, fspath=dir_struct + str(f), media_url=MEDIA_URL + (dir_struct + str(f)).split(MEDIA_ROOT)[1], ) track.save() print "Added to DB: " + filename.tag.title return render_to_response( "errors/upload_success.html", locals(), context_instance=RequestContext(request) ) else: return render_to_response( "errors/file_already_exists.html", locals(), context_instance=RequestContext(request) ) elif f_ext in [".jpg", ".JPG"]: if not os.path.exists(MEDIA_ROOT + "pictures/" + str(f)): with open(MEDIA_ROOT + "pictures/" + str(f), "wb") as destination: for chunk in f.chunks(): destination.write(chunk) else: # File already exists. Remove the duplicate copy. return render_to_response( "errors/file_already_exists.html", locals(), context_instance=RequestContext(request) ) # If the picture doesn't exist in the database, add it. if not Picture.objects.filter(name=str(f)).exists(): picture = Picture( name=os.path.splitext(str(f))[0], filename=str(f), fspath=MEDIA_ROOT + "pictures/" + str(f), media_url=MEDIA_URL + (MEDIA_ROOT + "pictures/" + str(f)).split(MEDIA_ROOT)[1], ) picture.save() print "Added to DB: " + str(f) return render_to_response( "errors/upload_success.html", locals(), context_instance=RequestContext(request) ) else: return render_to_response( "errors/file_already_exists.html", locals(), context_instance=RequestContext(request) ) elif f_ext in [".mp4", ".MP4", ".m4v", ".M4V"]: if not os.path.exists(MEDIA_ROOT + "videos/" + str(f)): with open(MEDIA_ROOT + "videos/" + str(f), "wb") as destination: for chunk in f.chunks(): destination.write(chunk) else: # File already exists. Remove the duplicate copy. return render_to_response( "errors/file_already_exists.html", locals(), context_instance=RequestContext(request) ) # If the video doesn't exist in the database, add it. if not Video.objects.filter(title=str(f)).exists(): video = Video( title=os.path.splitext(str(f))[0], filename=str(f), fspath=MEDIA_ROOT + "videos/" + str(f), media_url=MEDIA_URL + (MEDIA_ROOT + "videos/" + str(f)).split(MEDIA_ROOT)[1], ) video.save() print "Added to DB: " + str(f) return render_to_response( "errors/upload_success.html", locals(), context_instance=RequestContext(request) ) else: return render_to_response( "errors/file_already_exists.html", locals(), context_instance=RequestContext(request) ) return render_to_response("errors/upload_failure.html", locals(), context_instance=RequestContext(request))
if tags['genre']: try: genre = Genre.objects.get(name=tags['genre']) except Genre.DoesNotExist: genre = Genre(name = tags['genre']) try: genre.save() except: genre = None artist = None if tags['artist']: try: artist = Artist.objects.get(name=tags['artist']) except Artist.DoesNotExist: artist = Artist(name = tags['artist']) try: artist.save() except: artist = None year = tags['year'] if not song == None: song.title = tags['title'] song.track = tags['track'] song.mime = tags['mime'] song.length = tags['length'] song.year = year song.genre = genre song.album = album
json_content["data"] = new_data file_content = json.dumps(json_content, separators=(',', ':')) with open("../media/peaks/" + genId + ".json", "w") as f: f.write(file_content) # Lookup if the artist exists artist_match = Artist.objects.filter(stage_name=artist) artist_obj = "" if artist_match: artist_obj = Artist.objects.get(stage_name=artist) else: artist_obj = Artist(stage_name=artist) artist_obj.save() # Lookup if the album exists album_match = Album.objects.filter(album_name=album, artist=artist_obj) album_obj = "" if album_match: album_obj = Album.objects.get(album_name=album, artist=artist_obj) else: album_obj = Album(album_name=album, artist=artist_obj, uploader_id=1) album_obj.save() # Lookup if the song exists song_match = Song.objects.filter(song_name=title, artist=artist_obj) song_obj = "" if song_match:
def setUp(self): password = '******' hashed_password = bcrypt.hashpw(password.encode('utf-8'), bcrypt.gensalt()).decode('utf-8') user = User( email = '*****@*****.**', password = hashed_password, date_of_birth = '1991-09-04', phone_number = '010-1234-1234', ) user.save() self.access_token = jwt.encode({'id' : User.objects.get(id=user.id).id}, SECRET_KEY, algorithm=ALGORITHM) self.user = user self.user_id = user.id character = Character( name = '순대', user_id = self.user_id, ) character.save() self.character = character self.character_id = character.id artist_type = ArtistType(name='그룹') artist_type.save() self.artist_type = artist_type gender = Gender(name='여성') gender.save() self.gender = gender genre = Genre( name = '발라드' ) genre.save() self.genre = genre artist = Artist( name = '다비치', profile_image_url = 'http://www.google.co.kr', artist_type_id = self.artist_type.id, gender_id = self.gender.id, genre_id = self.genre.id ) artist.save() self.artist = artist chart = Chart( name = '빌보드 차트' ) chart.save() self.chart = chart character_taste_artist = CharacterTasteArtist( artist_id = self.artist.id, character_id = self.character_id ) character_taste_artist.save() self.character_taste_artist = character_taste_artist character_taste_genre = CharacterTasteGenre( genre_id = self.genre.id, character_id = self.character_id ) character_taste_genre.save() self.character_taste_genre = character_taste_genre character_taste_chart = CharacterTasteChart( chart_id = self.chart.id, character_id = self.character_id ) character_taste_chart.save() self.character_taste_chart = character_taste_chart