Exemple #1
0
 def create(user, album, hash, file, exif_datetime):
     needs_update = False
     file_name, file_extension = os.path.splitext(file)
     if not exif_datetime:
         exif_datetime = "1930:08:25 12:00:00"
     exif_datetime = datetime.strptime(exif_datetime, "%Y:%m:%d %H:%M:%S")
     destination_album = None
     with getcursor() as cur:
         if album:
             destination_album = Album.get(user, album)
         if not destination_album:
             destination_album = Album.get_album_by_name(user, "Unsorted")
         try:
             cur.execute(
                 "INSERT INTO photos (owner, album, hash, extension, exif_datetime, created)"
                 " VALUES (%s, %s, %s, %s, %s, current_timestamp)"
                 " RETURNING id", (user.id, destination_album.id, hash,
                                   file_extension, exif_datetime))
             photo_id = cur.fetchone()[0]
         except UniqueViolation:
             needs_update = True
         if needs_update:
             with getcursor() as cur:
                 cur.execute(
                     "UPDATE photos SET album = %s, exif_datetime = %s, flag = NULL, status = 'P'"
                     " WHERE owner = %s AND hash = %s"
                     " RETURNING id",
                     (destination_album.id, exif_datetime, user.id, hash))
                 photo_id = cur.fetchone()[0]
     thumbnail_url = Photo.get_presigned_url_tn(user, hash)
     fullsize_url = Photo.get_presigned_url_fs(user, hash)
     original_url = Photo.get_presigned_url_original(
         user, hash, file_extension)
     return Photo(photo_id, user.id, album, hash, file_extension, None,
                  exif_datetime, thumbnail_url, fullsize_url, original_url)
def load():
    album = Album()
    album.name = "100 Kotlu"
    album.actors = [
            "Krishna", 
            "Baladitya", 
            "Syerabhanu", 
            "Brahmanandam"
        ]
    album.music_directors = ["Vandemataram Srinivas"]
    album.directors = ["maruthi"]
    album.imageUrl = "http://rgamedia.blob.core.windows.net/raagaimg/r_img/catalog/cd/a/a0001232.jpg"
    album.save()
    
    print album.to_json()
    
    song = Song()
    
    song.album = album
    song.title = "Chirunayyu"
    song.genre  = None
    
    song.lyricists = [
                    "Surisetty Ramarao"
                ]
    
    song.singers =  [
                    "Malathi"
                ]
    song.rating = 10
    song.save()
    
    print song.to_json()
Exemple #3
0
    def setUp(self):
        self.artist = Artist("Frightened Rabbit")

        self.label = Label("Fat Cat Records")

        self.album = Album(
            "Midnight Organ Fight", self.artist, "Indie Rock", 22.99, 13.79,
            "2008",
            "https://is2-ssl.mzstatic.com/image/thumb/Music123/v4/53/79/37/53793762-eeef-8cce-96b2-6de1c18740e2/source/600x600bb.jpg",
            6, self.label, 15)
Exemple #4
0
class TestAlbum(unittest.TestCase):
    def setUp(self):
        self.artist = Artist("Frightened Rabbit")

        self.label = Label("Fat Cat Records")

        self.album = Album(
            "Midnight Organ Fight", self.artist, "Indie Rock", 22.99, 13.79,
            "2008",
            "https://is2-ssl.mzstatic.com/image/thumb/Music123/v4/53/79/37/53793762-eeef-8cce-96b2-6de1c18740e2/source/600x600bb.jpg",
            6, self.label, 15)

    def test_album_has_title(self):
        self.assertEqual("Midnight Organ Fight", self.album.title)

    def test_album_has_artist(self):
        self.assertEqual(self.artist, self.album.artist)

    def test_album_has_genre(self):
        self.assertEqual("Indie Rock", self.album.genre)

    def test_album_has_price(self):
        self.assertEqual(22.99, self.album.price)

    def test_album_has_cost_price(self):
        self.assertEqual(13.79, self.album.cost_price)

    def test_album_has_release_year(self):
        self.assertEqual("2008", self.album.release_year)

    def test_album_has_cover_art(self):
        self.assertEqual(
            "https://is2-ssl.mzstatic.com/image/thumb/Music123/v4/53/79/37/53793762-eeef-8cce-96b2-6de1c18740e2/source/600x600bb.jpg",
            self.album.cover_art)

    def test_album_has_stock(self):
        self.assertEqual(6, self.album.stock)

    def test_album_has_label(self):
        self.assertEqual(self.label, self.album.label)

    def test_album_has_sales_count(self):
        self.assertEqual(15, self.album.sales_count)

    def test_can_order_stock(self):
        self.album.order_stock(2)
        self.assertEqual(8, self.album.stock)

    def test_can_sell_stock(self):
        self.album.sell_stock(3)
        self.assertEqual(3, self.album.stock)
Exemple #5
0
def put_api_albums_share(id):
    try:
        album = Album.get(current_user, id)
        album.share(current_user, request.json['shared'])
    except ValueError as error:
        return error.args[0], 400
    return json.dumps(album.__dict__)
Exemple #6
0
def delete_api_albums(id):
    try:
        album = Album.get(current_user, id)
        album.delete(current_user)
    except ValueError as error:
        return error.args[0], 400
    return json.dumps(True)
Exemple #7
0
        def matched(widget, model, iter):
            item = model[iter]
            data_a = item[4]
            data_b = item[5]

            self.aview.matched = [data_a, data_b]
            self.albumfilter.refilter()

            if data_b == 'blm.!ARTIST!':
                # Matched an artist: show albums
                return False
            elif exists(data_b):
                # Matched a song: queue to playlist
                sng = Song(filename=item[5])
                self.aview.queue(sng)

                # Go back to empty search
                self.aview.matched = False
                searchentry = widget.get_entry()
                searchentry.set_text('')
                return True
            #elif len(self.albumfilter) == 1:
            else:
                # Matched an album: load it in a panel
                album = Album(data_b, data_a, self.songs_tree)
                if hasattr(album, 'name'):
                    self.aview.on_album_matched(album)

                    # Go back to empty search
                    self.aview.matched = False
                    searchentry = widget.get_entry()
                    searchentry.set_text('')
                    return True
Exemple #8
0
 def post(self, pessoa_id: int):
     args = self.req.parse_args()
     descricao = args['descricao']
     titulo = args['titulo']
     pessoa_id = args['pessoa_id']
     album = Album(descricao, titulo, pessoa_id)
     return self.dao.create(album), 201
Exemple #9
0
def put_api_albums():
    try:
        album = Album.get(current_user, request.json['id'])
        album = album.update(current_user, request.json['name'])
    except ValueError as error:
        return error.args[0], 400
    return json.dumps(album.__dict__)
Exemple #10
0
    def get (self, albumId):
        albums = []

        if self.current_user:
            user = User.get_user_by_id (self.current_user["id"])

            graph = facebook.GraphAPI (user.access_token)
            userInfo = graph.get_object ("%s" % user.id)

            if albumId:
                result = Album.query (albumId, ancestor = user.key).fetch ()
            else:
                result = [
                    {"id": album.key.id(), "name": album.name, "cover":
                        base64.b64encode (album.cover if album.cover else '')} 
                    for album in user.albums
                ]
            """
            all_albums = self.graph ('me/albums')
            
            if all_albums:
                print albums
                albums = [
                    dict (
                        name = album["name"],
                        icon = self.graph (album["cover_photo"]),
                        dikt = album
                    ) for album in all_albums["data"]
                ]
            """
        else:
            pass

        self.response.out.write (json.dumps (result))
def list_albums():
    albums = []
    sql = "SELECT * FROM albums"
    results = run_sql(sql)
    for row in results:
        album = Album(row['title'], row['genre'], row['id'], row['artist_id'])
        albums.append(album)
    return albums
def update_album(id):
    artist_id = request.form["artist_id"]
    artist = artist_repository.select(artist_id)
    title = request.form["title"]
    quantity = request.form["quantity"]
    album = Album(title, artist, quantity, id)
    album_repository.update(album)
    return redirect("/albums")
Exemple #13
0
 def select(self, id):
     album = None
     sql = "SELECT * FROM albums WHERE id = %s"
     results = SqlRunner.run(sql,(id,))
     row = results[0]
     artist = artist_repository.select(row['artist_id'])
     album = Album(row['title'], artist, row['quantity'], row['id'])
     return album
Exemple #14
0
def select(id):
    album = None
    sql = "SELECT * FROM albums WHERE id = %s"
    values = [id]
    result = run_sql(sql, values)[0]
    if result is not None:
        album = Album(result['name'], result['genre'], result['id'])
    return album 
Exemple #15
0
def update_album(id):
    title = request.form['title']
    artist_id = request.form['artist_id']
    quantity = request.form['quantity']
    artist = artist_repository.select(artist_id)
    album = Album(title, artist, quantity, id)
    album_repository.update(album)
    return redirect('/albums')
def list_albums_by_artist(artist):
    list_a_b_a = []
    sql = "SELECT * FROM albums WHERE artist_id = %s"
    values = [artist.id]
    results = run_sql(sql, values)
    for row in results:
        album = Album(row['title'], row['genre'], row['id'], artist)
        list_a_b_a.append(album)
    return list_a_b_a
def find_album(id):
    album = None
    sql = "SELECT * FROM albums WHERE id = %s"
    values = [id]
    result = run_sql(sql, values)[0]
    if result is not None:
        album = Album(result['title'], result['genre'], result['artist'],
                      result['id'])
    return album
Exemple #18
0
def select(id):
    album = None
    sql = "SELECT * FROM album where id = %s"
    values = [id]
    result = run_sql(sql, values)[0]
    if result is not None:
        artist = artist_repository.select(result['artist_id'])
        album = Album(result['title'], artist, result['genre'], result['id'])
        return album
Exemple #19
0
def albums(artist):
    albums = []
    sql = "SELECT * FROM albums WHERE artist_id=%s"
    values = [artist.id]
    results = run_sql(sql, values)
    for row in results:
        album = Album(row["name"], row["genre"], artist, row["id"])
        albums.append(album)
    return albums
def find_artist_by_album(album):
    artist = None
    sql = "SELECT * FROM album WHERE album_title = %s"
    values = [album.title]
    results = run_sql(sql, values)
    if results != None:
        artist = artist_repository.select(result['artist_id'])
        album = Album(result['title'], result['genre'], result['id'], artist)
    return artist
def select_all(artist):
    albums = []
    sql = "SELECT * FROM artists WHEN artist = artist"
    results = run_sql(sql)
    for row in results:
        album = Album(result['title'], result['genre'], result['artist'],
                      result['id'])
        albums.append(album)
    return albums
Exemple #22
0
def select_all():
    albums = []
    sql = "SELECT * FROM albums"
    results = run_sql(sql)
    for row in results:
        artist = artist_repo.select(row['artist_id'])
        album = Album(row['name'], row['genre'], row['id'], artist)
        albums.append(album)
    return albums
Exemple #23
0
 def select_for_artist(self, id):
     artist = artist_repository.select(id)
     albums = []
     sql = "SELECT * FROM albums where artist_id = %s"
     results = SqlRunner.run(sql,(id,))
     for row in results:
         album = Album(row['title'], artist, row['quantity'], row['id'])
         albums.append(album)
     return albums
Exemple #24
0
 def select_all(self):
     albums = []
     sql = "SELECT * FROM albums"
     results = SqlRunner.run(sql)
     for row in results:
         artist = artist_repository.select(row['artist_id'])
         album = Album(row['title'], artist, row['quantity'], row['id'])
         albums.append(album)
     return albums
Exemple #25
0
def select(id):
    album = None
    sql = "SELECT * FROM albums WHERE id = %s"
    values = [id]
    result = run_sql(sql, values)[0]
    if result is not None:
        artist = artist_repo.select(result['artist_id'])
        album = Album(result["name"], result["genre"], artist, result["id"])
    return album
Exemple #26
0
def select_by_artist_id(artist_id):
    albums = []
    sql = "SELECT * FROM albums WHERE artist_id = %s"
    values = [artist_id]
    results = run_sql(sql, values)
    for row in results:
        artist = artist_repository.select(row['artist_id'])
        album = Album(row['title'], row['genre'], artist, row['id'])
        albums.append(album)
    return albums
Exemple #27
0
def get_albums(artist):
    albums = []
    sql = "SELECT * FROM albums WHERE artist_id = %s"
    values = [artist.id]
    result = run_sql(sql, values)

    for row in result:
        album = Album(row['name'], row['artist'], row['genre'], row['id'])
        albums.append(album)
    return albums
Exemple #28
0
def select_all():
    albums = []
    sql = "SELECT * FROM albums"
    results = run_sql(sql)

    for row in results:
        artist = artist_repository.select(row["artist_id"])
        album = Album(row["title"], row["genre"], artist, row["id"])
        albums.append(album)
    return albums
    def song_started(self, song):
        # First, try to download a few similar artists names
        if self.config['shuffle_mode'] == 'similar':
            def download_similars():
                threads_enter()
                art = self.lastfm.get_similar_artists(song.artist)

                self.similar_artists = []
                mdb = MusicDatabase(None)

                for artist in art:
                    if mdb.artist_exists(artist):
                        self.similar_artists.append(artist)

                self.is_in_similar_thread = False
                threads_leave()

            if not self.is_in_similar_thread:
                self.is_in_similar_thread = True
                thread = Thread(group=None, target=download_similars,
                                name='similars', args=())
                thread.start()

        # Second, update statistics for this song
        song.increment_statistics()
        alb = Album(song.artist, song.album, self.songs_tree)
        alb.increment_statistics()

        # Then, highlight currently playing song/album if it's in playlist
        if self.playlist_current is not None:
            # Currently playing item is in the playlist
            item_iter, item_path, item_in_album = self.playlist_current

            # Remove marker of all items
            for item in self.liststore:
                current_label = item[1]
                if current_label[:2] == '◎ ':
                    item[1] = current_label[2:]

            # Add marker on one item
            current_label = self.liststore[item_iter][1]
            if current_label[:2] != '◎ ':
                self.liststore[item_iter][1] = '◎ ' + current_label
Exemple #30
0
def select_all():
    albums = []
    sql = 'SELECT * FROM albums'
    results = run_sql(sql)

    for row in results:
        artist = artist_repository.select(row['artist_id'])
        album = Album(row['title'], artist, row['genre'], row['id'])
        albums.append(album)
    return albums
Exemple #31
0
 def create(identity_provider, external_id, name, email, profile_pic,
            country):
     with getcursor() as cur:
         cur.execute(
             "INSERT INTO users (identity_provider, external_id, name, email, profile_pic, country, last_login, created)"
             " VALUES (%s, %s, %s, %s, %s, %s, current_timestamp, current_timestamp)"
             " RETURNING id", (
                 identity_provider,
                 external_id,
                 name,
                 email,
                 profile_pic,
                 country,
             ))
         user_id = cur.fetchone()[0]
     user = User(user_id, identity_provider, external_id, name, email,
                 profile_pic, country, generate_csrf())
     Album.create(user, "Unsorted")
     return user
Exemple #32
0
def albums(artist):
    albums = []

    sql = "SELECT * FROM albums WHERE artist_id = %s"
    values = [artist.id]
    results = run_sql(sql, values)

    for row in results:
        album = Album(row['album_title'], row['genre'], artist)
        albums.append(album)
    return albums
def insert_init_data():
    
    Album.drop_collection()
    Song.drop_collection()
    
    
    data = json.loads(open("mapped_songs.json","r").read())
    count = 0
    for movie_name in data:
        movie = data[movie_name]
        a = Album()
        a.name = movie_name
        a.directors = movie.get("directors",None)
        a.music_directors = movie.get("music_directors",None)
        a.image_url = movie.get("img",None)
        a.actors = movie.get("actors",None)
        a.save()
        
        
        print "saved :: ", a.name
        for song_title_path  in  movie.get("song_entries",[]):
            if(not song_title_path): continue
            song_title , path  = song_title_path
            s = Song()
            s.title = song_title
#             s.lyricists = song.get("lyricists",None)
#             s.singers = song.get("singers",None)
            s.path = path
            s.album = a
            s.track_n = count
            count +=1
            s.save()
            print "    ", "saved song : " , s.title , s.album 
            
    
    poll = Poll.create_next_poll("telugu")
    print poll.to_json()
    print Poll.get_current_poll("telugu").to_json()        
    
    
    set_max_track()
def add_album(movie_name , image_url , directors=None , music_directors=None , actors = None):
    if(not movie_name or not image_url or not "http" in image_url):
        print "need movie name and imageurl"
        return
        
    a = Album()
    a.name = movie_name
    a.directors = directors
    a.music_directors = music_directors
    a.image_url = image_url
    a.actors = actors
    print a.save()
    


#get_max_track()
Exemple #35
0
    def get (self, albumId):
        result = []

        if self.current_user:
            user = User.get_user_by_id (self.current_user["id"])

            graph = facebook.GraphAPI (user.access_token)
            userInfo = graph.get_object ("%s" % user.id)

            if albumId:
                result = Album.query (albumId, ancestor = user.key).fetch ()
            else:
                result = [
                    {"id": album.key.id(), "name": album.name, "cover": "/image/%s" % album.cover}
                    for album in user.albums
                ]
        else:
            pass

        self.response.out.write (json.dumps (result))
Exemple #36
0
 def get_albums(self):
   for e in sorted(os.walk(self.month_dir).next()[1]):
     album = Album(self.year, self.month, e)
     if album.first_image_url() != '':
       yield album
Exemple #37
0
def photo_metadata(album_path):
  album = Album(path=album_path)
  response.content_type = 'application/json'
  return album.get_exif_data()