Esempio n. 1
0
 def post(self, p):
     if not files.exists(p):
         abort(404, message=('File not found: %s' % p))
     o = json.load(request.stream)
     if not (isinstance(o, dict) and 'command' in o):
         abort(400)
     cmd = o['command']
     try:
         if cmd == 'move':
             if not 'to' in o:
                 abort(400)
             files.move_file(p, o['to'])
         elif cmd == 'copy':
             if not 'to' in o:
                 abort(400)
             files.copy_file(p, o['to'])
         elif cmd == 'mkdir':
             name = o['name']
             if '/' in name:
                 abort(400, message='Invalid filename.')
             if not files.is_directory(p):
                 abort(400, message='Not a directory.')
             if not 'name' in o:
                 abort(400)
             return files.mkdir(p, name)
         else:
             abort(400, message=('Invalid command: %s' % cmd))
     except OSError as e:
         abort(500, message=('File system error: ' + e.strerror))
     except IOError as e:
         abort(500, message=('File system error: ' + e.strerror))
     return '', 204
Esempio n. 2
0
def file_paste():
    p = request.form['p']
    path = '/'+p
    action = session['clipboard']
    fs = users.get_clipboard(g.user_id)
    if action == 'Cut':
        for f in fs:
            files.move_file(f, path)
    else:
        for f in fs:
            files.copy_file(f, path)
    return redirect(url_for('.file_ui', p=p))
Esempio n. 3
0
def file_paste():
    p = request.form['p']
    path = '/' + p
    action = session['clipboard']
    fs = users.get_clipboard(g.user_id)
    if action == 'Cut':
        for f in fs:
            files.move_file(f, path)
    else:
        for f in fs:
            files.copy_file(f, path)
    return redirect(url_for('.file_ui', p=p))
Esempio n. 4
0
File: ufff.py Progetto: fiwippi/ufff
def main(scan_dir, output_dir):
    data = {}
    visited_folders = set() # Keeps track of which folders have been checked for additional files

    items =  list(Path(scan_dir).rglob("*"))
    if len(items) == 0:
        print(f"No files/folders in: {scan_dir}")
        exit(0)

    for item in items:
        if item.is_dir():
            continue

        if is_audio_file(item):
            # Load the file
            mutagen_file = load_mutagen(item)

            # Retrieve the tags we want
            filename = item.name # Filename
            album, album_artist, date, codec, title, tracknum = retrieve_metadata(mutagen_file, filename)

            # Album artist tag is required
            if album_artist == None:
                print(f"No \"album artist\" tag in file \"{item}\"")
                continue
            # Album tag is required
            if album == None:
                print(f"No \"album\" tag in file \"{item}\"")
                continue
            # Title tag is required
            if title == None:
                print(f"No \"title\" tag in file \"{item}\"")
                continue

            # Enables these keys to be hashable by ensuring they're strings
            # This check should only happen after they're confirmed to exist
            # Also cleans up album/artist/title names by removing whitespaces
            album_artist, album, title = str(album_artist), str(album), str(title)
            # Notifies user if extra whitespace is found in the core tags
            if album_artist != album_artist.strip():
                album_artist = album_artist.strip()
                print(f"Album artist tag for {item} has whitespace")
            if album != album.strip():
                album = album.strip()
                print(f"Album tag for {item} has whitespace")
            if title != title.strip():
                title = title.strip()
                print(f"Title tag for {item} has whitespace")

            # Ensure the Album and Album Artist keys exist in the data dictionary
            if album_artist not in data:
                data[album_artist] = {}
            if album not in data[album_artist]:
                data[album_artist][album] = {"date": set(), "codecs": set(), "songs": [], "extras": []}

            # Create a sanitised audio filename
            audio_filename = ""
            if tracknum != None:
                audio_filename = sanitise(f"{tracknum} {title}{item.suffix}")
            else:
                audio_filename = sanitise(f"{title}{item.suffix}")

            # Add the metadata to the data struct
            data[album_artist][album]["codecs"].add(codec)
            if date != "":
                data[album_artist][album]["date"].add(date)
            data[album_artist][album]["songs"].append([item.as_posix(), audio_filename])

            # Include additional files, e.g. covers. Anything in the same
            # directory as the audio file counts as an additional file
            if item.parent.as_posix() not in visited_folders:
                visited_folders.add(item.parent.as_posix())

                for extra in item.parent.iterdir():
                    if not extra.is_dir() and not is_audio_file(extra):
                        data[album_artist][album]["extras"].append([extra.parent.as_posix(), sanitise(extra.name)])

    # Once metadata is collected about each file they're processed and moved to a correctly named folder
    for artist in data:
        for album in data[artist]:
            codec = "-".join(sorted(data[artist][album]["codecs"]))
            date = "-".join(sorted(data[artist][album]["date"]))

            album_dirname = sanitise(f"{artist} – {album}{' (' + date + ') ' if date else ' '}[{codec}]")
            folder_path = (f"{Path(output_dir).as_posix()}/{sanitise(artist)}/{album_dirname}")

            # Copy songs
            for src, filename in data[artist][album]["songs"]:
                dst = f"{folder_path}/{filename}"
                if src != dst:
                    move_file(src, dst, output_dir)

            # Copy additional files
            for folder, filename in data[artist][album]["extras"]:
                src = f"{folder}/{filename}"
                dst = f"{folder_path}/{filename}"
                if src != dst:
                    move_file(src, dst, output_dir)

    # Removes all empty directories
    delete_empty(scan_dir)
Esempio n. 5
0
        def process_video(info):
            vid_path = videos_path + info['id'] + ".mp4"
            make_screenshots(dir_path, vid_path, info['id'],
                             info["screenshots"])
            return process_clip(info, resolution)

        clips = []
        for seq in collection["sequences"]:
            seq_trans = trans if seq["transitions"] else None
            seq_clips = list(map(process_video, seq['videos']))
            seq_out = concatenate_videoclips(seq_clips,
                                             method="compose",
                                             transition=seq_trans)
            if seq["sound_over"]:
                audio = AudioFileClip(seq["sound_over"]["filename"])
                audio = audio.subclip(
                    seq["sound_over"]["start"],
                    seq["sound_over"]["start"] + seq_out.duration)
                audio = audio_normalize(audio)
                seq_out = seq_out.set_audio(audio)
            clips.append(seq_out)

        out = concatenate_videoclips(clips, method="compose", transition=trans)
        out.write_videofile(dir_path + collection['id'] + ".mp4",
                            threads=4,
                            fps=30)

        move_file(collections_path + filename, dir_path + filename)
    except OSError as err:
        print("!!!!!!!! Couldn't process %s" % filename, err)