def init_db(): file = read_file("./Albums.txt") if not file: print("File Does Not Exist. Make Sure 'Albums.txt' is in the same folder") album = None for line in file: if line.strip() == '': continue elif line.__contains__('/') or line.strip() == '': tokens = line.split('/') artist = tokens[0].strip() title = tokens[1].strip() year = tokens[2].strip() album = Album(artist, title, year) album_list.append(album) elif album: tokens = line.split('-') title = tokens[0].strip() duration = get_duration_seconds(tokens[1].strip()) track = Track(title, duration) album.track_list.append(track)
def file2Dict(filePath): d = dict() dbFile = open(filePath, 'r') dbText = dbFile.read() dbtext = dbText.strip() dbList = dbText.split("\n\n") for album in dbList: albumLines = album.split("\n") i = 0 for albumLine in albumLines: if (i == 0): artist = albumLine.strip() elif (i == 1): words = albumLine.split() year = words[0].strip() name = albumLine.strip(year) name = name.strip() year = int(year) newAlbum = Album(name, artist, year) else: song = albumLine.strip('-') song = song.strip() if (song == ''): continue #splitting on last line will create blank song, ignore this else: newAlbum.appendSong(song) i += 1 if (newAlbum.getArtist() in d): d[newAlbum.getArtist()].append(newAlbum) else: d[newAlbum.getArtist()] = [] d[newAlbum.getArtist()].append(newAlbum) return d
def addAlbum(inDict, dbFilePath): name = input('Please enter the name of the album: ') while True: try: year = int(input('Please enter release year: ')) except: print('Year must be an integer!') continue break artist = input('Please enter the artist: ') newAlbum = Album(name, artist, year) while True: newSong = input('Please add a song or type "q" to stop: ') if (newSong == 'q'): break else: newAlbum.appendSong(newSong) if (newAlbum.getArtist() not in inDict): inDict[newAlbum.getArtist()] = [] inDict[newAlbum.getArtist()].append(newAlbum) else: albumFound = False for album in inDict[newAlbum.getArtist()]: if (album.getName() == newAlbum.getName()): albumFound = True if (albumFound): print('Album already exists! Aborting.') else: inDict[newAlbum.getArtist()].append(newAlbum) dict2File(inDict, dbFilePath)
def saveAlbum(self, album): name = album['albumName'].replace('/', '__') path = config.PATH + '/' + self.ownerID + '/' + config.ALBUMLISTPATH + '/' + album[ 'albumId'] + ' ' + name Common.checkPath(path) album = Album(self.userID, self.spider, self.ownerID, album['albumId'], name, album['photoCount'], path) album.work()
def add(self): newAlbum = [] for field in self.fieldList: msg = f'\tEnter album {field}:\n\t' # newAlbum.append("test") newAlbum.append(input(msg)) # print(Album(newAlbum).__dict__) self.database.add(Album(newAlbum))
def saveAlbum(self, album): name = album['albumName'].replace('/', '_') #替换不满足路径规则的字符 path = Config.DATAPATH + '/' + self.ownerID + '/' + Config.ALBUMLISTPATH + '/' + album[ 'albumId'] + '_' + name CommonFunction.CreatePath(path) album = Album(self.spider, self.userID, self.ownerID, album['albumId'], name, album['photoCount'], path) album.work()
def retrieveAlbums(self): sql = "SELECT * from album" cur.execute(sql) self.myAlbums = [] for row in cur: a = Album() a.album_id = row[0] a.title = row[1] a.band_name = row[2] a.band_id = row[3] self.myAlbums.append(a)
def retrieveBandAlbums(self): albums = [] sql = "SELECT * from album where band_id = '" + str(self.band_id) + "'" cur.execute(sql) for row in cur: a = Album() a.album_id = row[0] a.title = row[1] a.band_name = row[2] a.band_id = row[3] albums.append(a) return albums
def createAlbum(self, user, albumName, albumUrl): album = Album(user, albumName, albumUrl) print(album) print(user) userAlbums = user.albums if not userAlbums: print("No albums yet") userAlbums = UserAlbums(user, [album]) print(userAlbums) return userAlbums print("already found albums") userAlbums.addAlbum(album) print(userAlbums) return userAlbums
def _retrieve_albums(self, limit=20, offset=0, session=None): user_id = self._get_safe('user_id') if user_id: albums = api.request('/user/' + user_id + '/albums', session, method='GET', params=dict( limit=limit, offset=offset, )) if albums: for album in albums['albums']: yield (Album(meta={'album': album}), albums['page']['total'])
def getAlbumInfo(token_info, songList): name = token_info['name'] artistList = [] for x in token_info['artists']: artistList.append(x['name']) imageList = [] for x in token_info['images']: imageList.append(x['url']) album = Album() if (len(imageList) >= 1): album.setImageLarge(imageList[0]) if (len(imageList) >= 2): album.setImageSmall(imageList[1]) album.setName(name) album.setArtists(artistList) album.setTracks(songList) return album
def get_album_information(self, album_id): cursor = self.con.cursor() query = '''SELECT albumTitle, bandName FROM Album WHERE albumID = ?''' cursor.execute(query, (album_id, )) self.con.commit() album_info = cursor.fetchall() album = Album(*album_info[0]) query = '''SELECT songURL, songName, songLength FROM Song WHERE albumID = ?''' cursor.execute(query, (album_id)) self.con.commit() songs_list = cursor.fetchall() for item in songs_list: song = Song(url=item[0], name=item[1], length=item[2]) album.add_song(song) return album
def getAblumInfo(self, url): try: response = requests.get(url).json() albumObj = Album() albumObj.setAlbumName(response["album"]["name"]) albumObj.setArtistName(response["album"]["artist"]) if "wiki" in response["album"]: albumObj.setPublishDate(response["album"]["wiki"]["published"]) elif "tags" in response["album"]: albumObj.setPublishDate( response["album"]["tags"]["tag"][0]["name"]) for x in response["album"]["image"]: if (x["size"] == "large"): albumObj.setImageUrl(x["#text"]) break return albumObj except requests.exceptions.RequestException as e: print("Error.") print(e)
def createAlbum(self, song, id, dirpath): """Crea un objeto album""" album = Album(song, id, dirpath) return album
def insertar(self, nombre, listaCanciones): if self.raiz == None: self.raiz = Album(nombre, listaCanciones) else: self.raiz.insertar(nombre, listaCanciones)
""" author : Jagepard <*****@*****.**> license https://mit-license.org/ MIT """ from Album import Album from Interpreter import Interpreter interpreter = Interpreter() interpreter.addAlbumToRegistry(Album("Untouchables", "Korn")) interpreter.addAlbumToRegistry(Album("Adrenaline", "Deftones")) interpreter.interpret("album 2") interpreter.interpret("album author 2") interpreter.interpret("album author 1") interpreter.interpret("author 1")
p = Artista('NULL','NULL','NULL') z = p.LeerArt() for a in z: print(a.idArtista, " - ", a.Nombre, " - ", a.Conciertos) elif a =='3': p = Artista('NULL','NULL','NULL') id_borrar = input ("Ingrese ID a Borrar: ") p.BorrarArt(id_borrar) elif a =='4': p = Artista('NULL','NULL','NULL') id_update = input("Ingrese ID a Actualizar: ") nombre_nuevo = input("Ingrese Nombre a Actualizar: ") concierto_nuevo = input("Ingrese Concierto a Actualizar: ") p.ActualizarArt(nombre_nuevo,concierto_nuevo,id_update) elif a =='5': p = Album('NULL','NULL','NULL') nom_al = input("Ingrese Nombre Album: ") fech_lan = input("Ingresar Fecha de Lanazamiento: ") p.InsertAl(nom_al,fech_lan) elif a == '6': p = Album('NULL','NULL','NULL') z = p.LeerAl() for a in z: print(a.idAlbum, ' - ',a.Nombre_Album, " - ", a.Fecha_Lanzamiento) elif a =='7': p = Album('NULL','NULL','NULL') id_borrar = input ("Ingrese ID a Borrar: ") p.BorrarAl(id_borrar) elif a =='8': p = Album('NULL','NULL','NULL') id_update = input("Ingrese ID a Actualizar: ")
else: artistSongs[songNum].playSong() if choice2 == "4": MP.retrieveArtists() MP.viewArtists() if choice2 == "5": break if choice == "3": while True: choice2 = input("1. add new Album 2. Delete Album 3. Play Songs to a certain Album" + " 4. View all Albums 5. back:\n") if choice2 == "1": album = Album() album.title = input("Enter album title:") MP.retrieveBands() MP.viewBands() bandNum = int(input("Enter band #:"))-1 album.band_name = MP.myBands[bandNum].name album.band_id = MP.myBands[bandNum].band_id album.addAlbum() if choice2 == "2": aID = int(input("Enter # of album:")) MP.retrieveAlbums() MP.myAlbums[aID-1].deleteAlbum() if choice2 == "3": MP.retrieveAlbums()
with open("albumid.txt", encoding="utf-8") as file: l_artistid = [] # (obj) List kus on kõik "Artist" objektid l_albumid = [] # (obj) List kus on kõik "Album" objektid l_laulud = [] # (obj) List kus on kõik "Laul" objektid l_art_nimed = [] # (str) List kus on kõikide "Artist" objektide nimed sees for line in file: artist, albumi_pealkiri, ilmumis_aasta, laulu_pealkiri = line.strip( "\n").split("\t") if artist not in l_art_nimed: l_artistid.append(Artist(artist)) l_art_nimed.append(artist) l_albumid.append( Album(albumi_pealkiri, ilmumis_aasta, l_artistid[-1])) l_artistid[-1].lisa_album(l_albumid[-1]) elif l_artistid[l_art_nimed.index( artist)].albumid[-1].nimi != albumi_pealkiri: l_albumid.append( Album(albumi_pealkiri, ilmumis_aasta, l_artistid[-1])) l_artistid[l_art_nimed.index(artist)].lisa_album(l_albumid[-1]) else: pass l_laulud.append(Laul(laulu_pealkiri, l_artistid[-1], l_albumid[-1])) l_artistid[-1].albumid[-1].lisa_laul(l_laulud[-1]) # Üldine otsing #while True:
import os import sys sys.path.append(os.path.join(os.path.dirname(__file__), '../src/')) from Photo import Photo from Album import Album BLINK_PHOTO_PATH = os.path.join(os.path.dirname(__file__), './static/johnny_blink6.jpg') NOBLINK_PHOTO_PATH = os.path.join(os.path.dirname(__file__), './static/johnny_noblink1.jpg') # BLINK_PHOTO_PATH = os.path.join(os.path.dirname(__file__), './static/jeff_test/Jeff_blink.PNG') # NOBLINK_PHOTO_PATH = os.path.join(os.path.dirname(__file__), './static/jeff_test/jeff_noblink.PNG') my_album = Album() blink_photo = Photo(BLINK_PHOTO_PATH) noblink_photo = Photo(NOBLINK_PHOTO_PATH) my_album.insert_photo(blink_photo) my_album.insert_photo(noblink_photo) my_album.facial_classification() # blink_photo.blink_detect() # noblink_photo.blink_detect() my_album.update_base_photo_index(0) my_album.blink_detection() # person_id and photo_id of new face # my_album.face_swap(swap_person_id = 0, newFace_photo_id = 1)
def insertar(self, nombre): if self.raiz == None: self.raiz = Album(nombre) else: self.raiz.insertar(nombre)
def upload_file(): # check for numFiles entry if 'numFiles' not in request.form or request.form['numFiles'] == "": content = {"Error": "Missing 'numFiles' in POST request"} return content, 400 numFiles = int(request.form['numFiles']) if numFiles == 0: content = {"Error": "No files added in POST request"} return content, 400 if 'basePhotoIndex' not in request.form or request.form[ 'basePhotoIndex'] == "": content = {"Error": "Missing 'basePhotoIndex' in POST request"} return content, 400 basePhotoIndex = int(request.form['basePhotoIndex']) # Error check for i in range(numFiles): entry = 'file[' + str(i) + ']' if entry not in request.files: content = {"Error": "Missing " + entry + " in POST request"} return content, 400 file = request.files[entry] if file.filename == '': content = {"Error": "File field is empty in POST request"} return content, 400 if not (file and allowed_file(file.filename)): content = { "Error": "File is wrong format (only accepts png, jpg, jpeg)" } return content, 400 # Create a new session scale_percent = 0 newAlbum = Album(scale_percent) new_session_id = appSessions.new_session(newAlbum) session_path = os.path.join(uploadFolder, new_session_id) os.mkdir(session_path) output_photo_path = "" # Save file in path for i in range(numFiles): entry = 'file[' + str(i) + ']' file = request.files[entry] filename = secure_filename(file.filename) if (i == basePhotoIndex): output_photo_path = os.path.join(session_path, "retouched_" + filename) file.save(os.path.join(session_path, filename)) newAlbum.insert_photo(Photo(os.path.join(session_path, filename))) newAlbum.facial_classification() newAlbum.update_base_photo_index(basePhotoIndex) newAlbum.blink_detection() newAlbum.remove_blinking_faces() newAlbum.write_output_photo(output_photo_path) newAlbum.status = "READY" content = {"session_id": new_session_id} return content, 200