Пример #1
0
def add_to_library(request, album_id):

    profile = get_object_or_404(User, id=request.user.id)

    album = Album.objects.get(pk=album_id)
    albumsongs = album.song_set.all()

    print ('--------',album.artist)
    
    album_copy = Album()
    album_copy = copy.deepcopy(album)
    album_copy.users.add(profile)
    # 
    # album_copy.song.add(album_songs)

    # print ('dddddddd',album_copy.song_set.all())
    # album_copy

    # album_copy.albums.add(album_copy)
    # profile.album
    print ('#####',type(album_copy))

    # print ("#########",album_copy.users.all())

    # album_copy.users = None

    # print ('@@@@@@@@@@',album_copy.user)

    album_copy.save()

    return render(request, 'music/my_library.html', {'profile': profile })
Пример #2
0
def read_data_from_excel(excel_file):
    # reads data from an excel_file
    file_path = str(excel_file)

    # create a workbook using the excel file received
    w_book = xlrd.open_workbook(file_path)

    # open the excel_sheet with the data
    sheet = w_book.sheet_by_index(0)

    # import the database model Albums
    from music.models import Album

    # instantiate a state
    state = StateService().get(name='Active')
    # loop through the data printing all the data

    for row in range(1, sheet.nrows):
        # print (str(sheet.cell_value(row, col))),
        obj = Album(artist=sheet.cell_value(row, 0),
                    album_title=sheet.cell_value(row, 1),
                    genre=sheet.cell_value(row, 2),
                    state=state)
        print('album added')
        obj.save()

    return 'Success'
Пример #3
0
def CreateAlbum():
    a = Album(
        artist="Taylor swift",
        album_title="red",
        genre="Country",
        album_logo="/Users/fanjialiang2401/Desktop/Imag/1_12.jpg",
    )
    a.save()
Пример #4
0
 def create(self, validated_date):
     tracks_data = validated_date.get("tracks")
     a = Album()
     a.title = validated_date.pop("title")
     a.year = validated_date.pop("year")
     a.publisher = validated_date.pop("publisher")
     a.description = validated_date.pop("description")
     a.save()
     if tracks_data != None:
         for track_id in tracks_data:
             m = Music.objects.get(pk=track_id)
             m.album = a
             m.save()
     return a
Пример #5
0
def make_album(request):
    error_msg = []
    context = {
        'title': 'Create Album',
        'error_msg': error_msg,
    }
    if request.method == 'GET':
        #print(request.method)
        return render(request, 'music/album/create_album.html', context)

    else:
        is_form_valid = True
        #print(request.POST)
        album_title = request.POST['album_title']
        artist = request.POST['artist']
        img = None
        file_path = None
        if request.FILES and (not request.FILES['album_cover'].content_type.
                              __contains__('image/')):  #check valid file
            context['error_msg'].append('Upload an image file')
            is_form_valid = False
        elif request.FILES and request.FILES[
                'album_cover'].content_type.__contains__('image/'):
            img = request.FILES['album_cover']

        if not (album_title and artist):  #check all fields filled
            context['error_msg'].append('Fill up all fields')
            is_form_valid = False

        if is_form_valid:
            if img:
                img_folder = save_file_to_firebase(file=img,
                                                   type='image',
                                                   path='album_covers/' +
                                                   album_title)
                img = img_folder[0]
                file_path = img_folder[1]

            album = Album(album_title=album_title,
                          artist=artist,
                          image=img,
                          file_path=file_path)
            album.save()
            return get_album_details(request, album.id)
        return render(request, 'music/album/create_album.html', context)
    def setUp(self):
        album = Album(album_name='Anti', artist='Rihanna')
        album.save()

        self.album_id = album.id

        track1 = Track(title='Desperado', order=1, album=album, duration=4)
        track1.save()

        self.track1_id = track1.id

        track2 = Track(title='Love on the brain',
                       order=2,
                       album=album,
                       duration=3)
        track2.save()

        self.track2_id = track2.id
Пример #7
0
COMMIT;

#save the changes
kendavar@uecb1d74a93b158e48e11:~/kendavar/Django/website$ python manage.py migrate
Operations to perform:
  Apply all migrations: admin, auth, contenttypes, music, sessions
Running migrations:
  Rendering model states... DONE
  Applying music.0001_initial... OK

#operation on the python manage.py shell.insert/update db.
$python manage.py shell
from music.models import Album, Song

Album.objects.all()
a = Album(artist="Taylor Swift", album_title="Red",genre="country",album_logo="asdfsdsfa")
a.save()
a.artist
a.id
a.pk #a.id or a.pk -primary key
#second way to input values to db
b=Album()
b.artist= "Myth"
b.album_title="High school"
b.album_logo="/home/local/ANT/kendavar/kendavar/"
b.save()
Album.objects.all()

#dunter/string representaion of the object.It gives a name to the object
class Album(models.Model):
    artist = models.CharField(max_length=250)
a = Album(artist="The Nelsonions",
          album_title="Bluish-blue",
          genre="Rock",
          album_logo="http://schmoesknow.com/wonder-woman-movie-review/50254/")
## above code is all on one line
a.save()  # writes into the database
a.id  # show the ID (primary key)

a = Album(
    artist="The Bill-Browns",
    album_title="Ready or not",
    genre="Rock",
    album_logo=
    "http://schmoesknow.com/wp-content/uploads/2017/05/Wonder-Woman-Movie-Artwork.jpg"
)
# above code is all on one line
##
a.save()  # writes into the database
##
a.id  # show the ID (primary key)

a = Album(
    artist="DJ Cool-cumber",
    album_title="Ignite the night",
    genre="Rock",
    album_logo=
    "http://schmoesknow.com/wp-content/uploads/2017/05/Wonder-Woman-Movie-Artwork.jpg"
)
# above code is all on one line
##
a.save()  # writes into the database
Пример #9
0
from music.models import Ablum, Song
from music.models import Album, Song
Album.objects.all()
a = Album(artist='Taylor Swift',album_title='Red',genre='Country',album_logo="https://imgchr.com/i/Kb9vFO")
a.save()
a.artist
a.album_title
a.id
a.pk
b = Album()
b.artist = "Myth"
b.album_title = "High School"
b.genre = "Punk"
b.album_logo = ""
b.album_logo = ""
b.album_logo = "https://imgchr.com/i/KbC100"
b.saz
b.save()
a.artist
b.artist
b.album_title = "Middle School"
b.album_title
Album.objects.all()
%hist -f Create_Albums.py
Пример #10
0
    # 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:
        song_obj = Song.objects.get(song_name=title, artist=artist_obj)
        song_obj.save()
    else:
        # save the peaks file
        song_obj = Song(peaks_file="../media/peaks/" + genId + ".json", song_duration_seconds=file.info.length,song_file=song_file, track_art=art_file,track_art_dominant_color=dominant_color_hex, uploader_id=1, song_name=title, artist=artist_obj, album=album_obj)
        song_obj.save()

    index = index + 1
Пример #11
0
#different ways of adding rows in the table
from music.models import Album ,Song
Album.objects.all()

a = Album(artist = "Taylor Swift", album_title = "Red",genre = "Country" ,album_logo = "https://upload.wikimedia.org/wikipedia
a.save()

b=Album()
b.artist = "One direction"
b.album_title = "once a day"
b.genre = "punk"
b.album_logo = "http://cdn01.cdn.justjared.com/wp-content/uploads/2014/02/stewart-whoa/kristen-stewart-if-i-do-a-good-scene-i-say-whoa-thats-dope-01.jpg"
b.save()

Album.objects.all()
Album.objects.filter(id =1)
#prints the first one
Album.objects.filter(artist__startswith='Taylor')


#adding songs to database

In [1]: from music.models import Album,Song

In [2]: album1 = Album.objects.get(pk = 1)

In [3]: album1.artist
Out[3]: 'Taylor Swift'

In [4]: song = Song()
Пример #12
0
import os
import django

sys.path.append(".")  # here store is root folder(means parent).
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "mosaic_api.settings")
django.setup()
import spotipy
import spotipy.util as util
from music.models import Album

if len(sys.argv) > 1:
    username = sys.argv[1]
else:
    print("Usage: %s username" % (sys.argv[0],))
    sys.exit()

scope = 'user-library-read'
token = util.prompt_for_user_token(username, scope)

if token:
    sp = spotipy.Spotify(auth=token)
    results = sp.current_user_saved_albums(limit=50)
    for item in results['items']:
        album_record = item['album']
        album = Album(released=2017, title=album_record['name'], artist=album_record['artists'][0]
                      ['name'], spotify_URL=album_record['id'], cover_art=album_record['images'][0]['url'])
        print(album)
        album.save()
else:
    print("Can't get token for", username)