Exemple #1
0
def generate_post_art(art_type):
	if art_type == "russian":
		art_info = art.get_russians()
		art_name = art.save_art(art_info, ART_FOLDER)

	if art_type == "gallery":
		art_info = art.get_gallery()
		art_name = art.save_art(art_info, ART_FOLDER)

	if art_type == "collection":
		art_info = art.get_art()
		art_name = art.save_art(art_info, ART_FOLDER)

	try: os.rename(ART_FOLDER + "\\" + art_name, ART_FOLDER + "\\" + "WORKING_FILE.jpg")
	except FileExistsError:
		os.remove(ART_FOLDER + "\\" + "WORKING_FILE.jpg")
		os.rename(ART_FOLDER + "\\" + art_name, ART_FOLDER + "\\" + "WORKING_FILE.jpg")

	while True:
		try:
			vk_photo = art.loadPhotoVk(ART_FOLDER + "\\" + "WORKING_FILE.jpg", art_name[:-4])
			break
		except requests.exceptions.ProxyError:
			print("ProxyError while loading photo, trying again")
			time.sleep(3)
	while True:
		try:
			os.rename(ART_FOLDER + "\\" + "WORKING_FILE.jpg", ART_FOLDER + "\\" + art_name)
			break
		except PermissionError:
			print("PermissionError, waiting")
			time.sleep(3)

	return vk_photo
Exemple #2
0
 def dictify(self):
     return {
         'id': self.id,
         'title': self.title,
         'artist': self.artist,
         'album': self.album,
         'length': self.length,
         'path': self.path,
         'tracknumber': self.tracknumber,
         'play_count': self.play_count(),
         'art_uri': art.get_art(self.artist, self.album),
     }
Exemple #3
0
 def dictify(self):
     return {
         "id": self.id,
         "title": self.title,
         "artist": self.artist,
         "album": self.album,
         "length": self.length,
         "path": self.path,
         "tracknumber": self.tracknumber,
         "play_count": self.play_count(),
         "art_uri": art.get_art(self.artist, self.album),
     }
Exemple #4
0
 def dictify(self):
     return {
         'id': self.id,
         'title': self.title,
         'artist': self.artist,
         'album': self.album,
         'length': self.length,
         'path': self.path,
         'tracknumber': self.tracknumber,
         'play_count': self.play_count(),
         'art_uri': art.get_art(self.artist, self.album),
     }
Exemple #5
0
def get_albums_for_artist(artist):
    songs = Song.__table__
    albums = []
    if artist:
        conn = engine.connect()
        cols = [songs.c.album, func.count(songs.c.album).label('num_songs'), songs.c.artist]
        s = (select(cols)
             .where(songs.c.artist == artist)
             .group_by(songs.c.album)
             .order_by(songs.c.album))
        res = conn.execute(s)
        albums = [{'name': row[0], 'num_songs': row[1], 'art_uri': art.get_art(row[2], row[0])} for row in res]
        conn.close()
    return {'query': artist, 'results': albums}
Exemple #6
0
def get_albums_for_artist(artist):
    songs = Song.__table__
    albums = []
    if artist:
        conn = engine.connect()
        cols = [songs.c.album, func.count(songs.c.album).label('num_songs'), songs.c.artist]
        s = (select(cols)
             .where(songs.c.artist == artist)
             .group_by(songs.c.album)
             .order_by(songs.c.album))
        res = conn.execute(s)
        albums = [{'name': row[0], 'num_songs': row[1], 'art_uri': art.get_art(row[2], row[0])} for row in res]
        conn.close()
    return {'query': artist, 'results': albums}
Exemple #7
0
def add_songs_in_dir(path, store_checksum=False):
    """Update database to reflect the contents of the given directory.

    store_checksum: Whether or not to store an MD5 file checksum in order to
    update the song metadata in the database if the file is modified. Disabled
    by default because it makes scanning a lot slower.
    """
    already_added = _prune_dir(path, prune_modified=store_checksum)
    table = Song.__table__
    conn = engine.connect()
    num_songs = 0
    for root, _, files in walk(path):
        for f in files:
            ext = splitext(f)[1]
            filepath = join(root, f).decode('utf-8')
            if ext in {'.mp3', '.flac', '.ogg', '.m4a', '.mp4'}:
                if filepath in already_added:
                    print 'Already added: ' + filepath
                    continue

                try:
                    if ext == '.mp3':
                        song = EasyMP3(filepath)
                    elif ext == '.flac':
                        song = FLAC(filepath)
                    elif ext == '.ogg':
                        song = OggVorbis(filepath)
                    elif ext in {'.m4a', '.mp4'}:
                        song = MP4(filepath)
                except IOError, e:
                    print e
                    continue

                # Required tags
                try:
                    if ext in {'.m4a', '.mp4'}:
                        title = song.tags['\xa9nam'][0]
                        artist = song.tags['\xa9ART'][0]
                    else:
                        title = song.tags['title'][0]
                        artist = song.tags['artist'][0]
                except Exception:
                    print 'Missing tags: ' + filepath
                    continue

                song_obj = {
                    'title': title,
                    'artist': artist,
                    'length': song.info.length,
                    'path': filepath,
                }

                # Calculate and store file checksum
                if store_checksum:
                    with open(filepath, 'rb') as song_file:
                        song_obj['checksum'] = md5_for_file(song_file)

                try: # Album optional for singles
                    if ext in {'.m4a', '.mp4'}:
                        song_obj['album'] = song.tags['\xa9alb'][0]
                    else:
                        song_obj['album'] = song.tags['album'][0]
                except Exception:
                    song_obj['album'] = None

                try: # Track number optional
                    if ext in {'.m4a', '.mp4'}:
                        song_obj['tracknumber'] = song.tags['trkn'][0][0]
                    else:
                        song_obj['tracknumber'] = (
                            int(song.tags['tracknumber'][0]))
                except Exception:
                    song_obj['tracknumber'] = None

                # Album art added on indexing
                if not art.get_art(song_obj['artist'], song_obj['album']):
                    art.index_art(song_obj)

                print 'Added: ' + filepath
                conn.execute(table.insert().values(song_obj))
                num_songs += 1
Exemple #8
0
def add_songs_in_dir(path, store_checksum=False):
    """Update database to reflect the contents of the given directory.

    store_checksum: Whether or not to store an MD5 file checksum in order to
    update the song metadata in the database if the file is modified. Disabled
    by default because it makes scanning a lot slower.
    """
    already_added = _prune_dir(path, prune_modified=store_checksum)
    table = Song.__table__
    conn = engine.connect()
    num_songs = 0
    for root, _, files in walk(path):
        for f in files:
            ext = splitext(f)[1]
            filepath = join(root, f).decode('utf-8')
            if ext in {'.mp3', '.flac', '.ogg', '.m4a', '.mp4'}:
                if filepath in already_added:
                    print 'Already added: ' + filepath
                    continue

                try:
                    if ext == '.mp3':
                        song = EasyMP3(filepath)
                    elif ext == '.flac':
                        song = FLAC(filepath)
                    elif ext == '.ogg':
                        song = OggVorbis(filepath)
                    elif ext in {'.m4a', '.mp4'}:
                        song = MP4(filepath)
                except IOError, e:
                    print e
                    continue

                # Required tags
                try:
                    if ext in {'.m4a', '.mp4'}:
                        title = song.tags['\xa9nam'][0]
                        artist = song.tags['\xa9ART'][0]
                    else:
                        title = song.tags['title'][0]
                        artist = song.tags['artist'][0]
                except Exception:
                    print 'Missing tags: ' + filepath
                    continue

                song_obj = {
                    'title': title,
                    'artist': artist,
                    'length': song.info.length,
                    'path': filepath,
                }

                # Calculate and store file checksum
                if store_checksum:
                    with open(filepath, 'rb') as song_file:
                        song_obj['checksum'] = md5_for_file(song_file)

                try: # Album optional for singles
                    if ext in {'.m4a', '.mp4'}:
                        song_obj['album'] = song.tags['\xa9alb'][0]
                    else:
                        song_obj['album'] = song.tags['album'][0]
                except Exception:
                    song_obj['album'] = None

                try: # Track number optional
                    if ext in {'.m4a', '.mp4'}:
                        song_obj['tracknumber'] = song.tags['trkn'][0][0]
                    else:
                        song_obj['tracknumber'] = (
                            int(song.tags['tracknumber'][0]))
                except Exception:
                    song_obj['tracknumber'] = None

                # Album art added on indexing
                if not art.get_art(song_obj['artist'], song_obj['album']):
                    art.index_art(song_obj)

                print 'Added: ' + filepath
                conn.execute(table.insert().values(song_obj))
                num_songs += 1
Exemple #9
0
def recover_art(path):
    """Recovers missing artwork for songs already in database.

    Useful for disaster recovery.
    """
    table = Song.__table__
    conn = engine.connect()
    num_songs = 0
    for root, _, files in walk(path):
        for f in files:
            ext = splitext(f)[1]
            filepath = join(root, f).decode('utf-8')
            if ext in {'.mp3', '.flac', '.ogg', '.m4a', '.mp4'}:
                try:
                    if ext == '.mp3':
                        song = EasyMP3(filepath)
                    elif ext == '.flac':
                        song = FLAC(filepath)
                    elif ext == '.ogg':
                        song = OggVorbis(filepath)
                    elif ext in {'.m4a', '.mp4'}:
                        song = MP4(filepath)
                except IOError, e:
                    print e
                    continue

                # Required tags
                try:
                    if ext in {'.m4a', '.mp4'}:
                        title = song.tags['\xa9nam'][0]
                        artist = song.tags['\xa9ART'][0]
                    else:
                        title = song.tags['title'][0]
                        artist = song.tags['artist'][0]
                except Exception:
                    print 'Missing tags: ' + filepath
                    continue

                song_obj = {
                    'title': title,
                    'artist': artist,
                    'length': song.info.length,
                    'path': filepath,
                }

                try:  # Album optional for singles
                    if ext in {'.m4a', '.mp4'}:
                        song_obj['album'] = song.tags['\xa9alb'][0]
                    else:
                        song_obj['album'] = song.tags['album'][0]
                except Exception:
                    song_obj['album'] = None

                try:  # Track number optional
                    if ext in {'.m4a', '.mp4'}:
                        song_obj['tracknumber'] = song.tags['trkn'][0][0]
                    else:
                        song_obj['tracknumber'] = (int(
                            song.tags['tracknumber'][0]))
                except Exception:
                    song_obj['tracknumber'] = None

                # Album art added on indexing
                if not art.get_art(song_obj['artist'], song_obj['album']):
                    art.index_art(song_obj)
                    print 'Recovered artwork for: ' + filepath
                    num_songs += 1
Exemple #10
0
def recover_art(path):
    """Recovers missing artwork for songs already in database.

    Useful for disaster recovery.
    """
    table = Song.__table__
    conn = engine.connect()
    num_songs = 0
    for root, _, files in walk(path):
        for f in files:
            ext = splitext(f)[1]
            filepath = join(root, f).decode('utf-8')
            if ext in {'.mp3', '.flac', '.ogg', '.m4a', '.mp4'}:
                try:
                    if ext == '.mp3':
                        song = EasyMP3(filepath)
                    elif ext == '.flac':
                        song = FLAC(filepath)
                    elif ext == '.ogg':
                        song = OggVorbis(filepath)
                    elif ext in {'.m4a', '.mp4'}:
                        song = MP4(filepath)
                except IOError, e:
                    print e
                    continue

                # Required tags
                try:
                    if ext in {'.m4a', '.mp4'}:
                        title = song.tags['\xa9nam'][0]
                        artist = song.tags['\xa9ART'][0]
                    else:
                        title = song.tags['title'][0]
                        artist = song.tags['artist'][0]
                except Exception:
                    print 'Missing tags: ' + filepath
                    continue

                song_obj = {
                    'title': title,
                    'artist': artist,
                    'length': song.info.length,
                    'path': filepath,
                }

                try: # Album optional for singles
                    if ext in {'.m4a', '.mp4'}:
                        song_obj['album'] = song.tags['\xa9alb'][0]
                    else:
                        song_obj['album'] = song.tags['album'][0]
                except Exception:
                    song_obj['album'] = None

                try: # Track number optional
                    if ext in {'.m4a', '.mp4'}:
                        song_obj['tracknumber'] = song.tags['trkn'][0][0]
                    else:
                        song_obj['tracknumber'] = (
                            int(song.tags['tracknumber'][0]))
                except Exception:
                    song_obj['tracknumber'] = None

                # Album art added on indexing
                if not art.get_art(song_obj['artist'], song_obj['album']):
                    art.index_art(song_obj)
                    print 'Recovered artwork for: ' + filepath
                    num_songs += 1