Beispiel #1
0
    def truncate_artists():
        while True:
            song_artist = song.get('ALBUMARTIST')
            artist = song.get('ARTIST')
            if song_artist:
                if ',' in song_artist:
                    sing_it()
                    report('TRUNCATING ALBUMARTIST', end='')
                    song.set('ALBUMARTIST',
                             song.get('ALBUMARTIST').split(',')[0])

                if song.get('ALBUMARTIST') not in song.get('ARTIST'):
                    song.set(
                        'ARTIST',
                        song.get('ARTIST') + ', ' + song.get('ALBUMARTIST'))
                break

            elif artist:
                sing_it()
                report('FIXING ALBUMARTIST ', end='')
                if ',' in artist:
                    song.set('ALBUMARTIST', song.get('ARTIST').split(',')[0])
                else:
                    song.set('ALBUMARTIST', song.get('ARTIST'))

            else:
                error('No ARTIST and no ALBUMARTIST?')
                error(project, '/', artist_d, '/', album_d, '/', song_f, '\n')
                break
Beispiel #2
0
    def load(self, exit_on_exc=True, debug=False):
        try:
            if self.is_json:
                self.tags = read_json(self.full_path())
            else:
                self.tags = music_tag.load_file(self.full_path())

            return self.tags

        except Exception as e:
            error('Couldn\'t load',
                  self.full_path,
                  fatal=exit_on_exc,
                  exc=e,
                  debug=debug)
            return None
Beispiel #3
0
def get_filtered_songs(path, song_fs,
                       artist_filter=None, album_filter=None,
                       title_filter=None,
                       sort_per_track=False, post_process_songs=False,
                       print_header=True,
                       no_warn=False, deep_warn=False,
                       mark_missing_songs=False, dryrun=True,
                       verbose=False, silent=False, debug=False):
    printed_header = False
    filtered_songs = {}
    missed_songs = []
    warnings = 0
    max_track_len = 0
    total_album_tracks = None  # unknown or inconsistent
    track_info_per_song = {}

    for song in song_fs:
        if is_song_file(song):
            s = Song(path=path, song_f=song, debug=debug)
            if ((not artist_filter or
                 artist_filter.lower() in s.get('ALBUMARTIST').lower()) and
                    ((not album_filter or
                      album_filter.lower() in s.get('ALBUM').lower()) and
                     (not title_filter or
                      title_filter.lower() in s.get('TITLE').lower()))):
                if print_header and not printed_header:
                    green()
                    green('Listing', path)
                    printed_header = True
                if sort_per_track:
                    track_tag = s.get_track_nbr_as_string(verbose=verbose)
                    track_nbr, total = s.parse_track_nbr(track_tag)
                    track_info_per_song[s.name()] = (track_nbr, total)

                    # build up a list, in case of mixes directory, there would
                    # be track number overlaps
                    f_songs = filtered_songs.get(track_nbr)
                    if f_songs:
                        f_songs.append(s)
                    else:
                        filtered_songs[track_nbr] = [s]

                else:
                    track_tag = s.get_track_nbr_as_string(verbose=verbose)
                    filtered_songs[len(filtered_songs)] = [s]

                max_track_len = max(max_track_len, len(track_tag))

    if filtered_songs and sort_per_track and post_process_songs:
        prev_track_nbr = 0
        song_that_gave_total_tracks = None
        total_tracks_is_inconsistent = False
        for track_nbr in sorted(filtered_songs):
            first_song = True
            for song in filtered_songs[track_nbr]:
                song_f = song.name()
                song_base = song_f[:-len(SONG_FILE_EXT)]
                track_nbr, total = track_info_per_song[song_f]
                if missing_file_exists(path, track_nbr):
                    error('.missing file exists for', song_f, end='\n')
                    error('You must delete it:',
                          get_missing_file_full_path(path, track_nbr),
                          end='\n')
                if first_song:
                    if track_nbr != prev_track_nbr + 1:
                        # TODO(if last song is missing, we don't report)
                        for i in range(prev_track_nbr + 1, track_nbr):
                            if not missing_file_exists(path, i):
                                if mark_missing_songs:
                                    add_missing_file(path, i, dryrun)
                                else:
                                    missed_songs.append((path, i))

                    prev_track_nbr = track_nbr
                    first_song = False

                if total and not total_tracks_is_inconsistent:
                    if total_album_tracks is None:
                        total_album_tracks = total
                        song_that_gave_total_tracks = song_base
                    elif total_album_tracks != total:
                        total_tracks_is_inconsistent = True
                        total_album_tracks = None

                        if not no_warn:
                            warn('Within', path, 'album,')
                            yellow('     ', song_base,
                                   'has inconsistent total tracks with',
                                   song_that_gave_total_tracks)
                            if deep_warn:
                                print_songs(path, song_fs,
                                            artist_filter, album_filter,
                                            title_filter, sort_per_track=True,
                                            verbose=verbose, silent=silent,
                                            debug=debug)
                            warnings += 1

        if not silent:
            for song in missed_songs:
                warn(song[0], '[Track', song[1], '\b] is missing')
                warnings += 1

    return (filtered_songs, missed_songs, total_album_tracks, warnings,
            max_track_len)
Beispiel #4
0
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import time, os, sys

BATCHPATH = os.path.dirname(os.path.dirname(os.path.abspath(os.path.realpath(__file__))))
sys.path.insert(0, BATCHPATH)

from lib.base import gettime, info, warn, error

from types import MappingProxyType


if __name__ =='__main__':
    d = {1:'A'}
    d_proxy = MappingProxyType(d)
    info("d_proxy: %s" %(d_proxy))
    info("d_proxy[1]: %s" %(d_proxy[1]))

    try:
        d_proxy[2] = 'x'
    except Exception as err:
        error("exception: %s" %(err))

    d[2] = 'B'
    info("d_proxy: %s" %(d_proxy))
    info("d_proxy[2]: %s" %(d_proxy[2]))

Beispiel #5
0
def test_error():
    error('wooo...bad (just kidding)')
    error('wooo...bad', end=' (just kidding!)\n')
    cyan('test_error OK')
Beispiel #6
0
        dryrun=dryrun,
        verbose=verbose,
        silent=silent)
    remove_file('.',
                'test3.txt',
                safe_remove=safe_remove,
                dryrun=dryrun,
                verbose=verbose,
                silent=silent)
    remove_file('.',
                'test3 (1).txt',
                safe_remove=safe_remove,
                dryrun=dryrun,
                verbose=verbose,
                silent=silent)
    cyan('test_file_manipulation_2 OK')


if __name__ == "__main__":
    test_colours()
    test_windows()
    test_error()
    test_to_camel_case()
    test_file_extension()
    test_file_manipulation_1()
    test_file_manipulation_2()
    green('ALL TESTS PASS. Happy day :)')
    cyan('Final test is a fatal error:')
    fatal_error('The world exploded')
    error('SHOULD NOT HAVE COME HERE!')