#!/usr/bin/env python3

from argparse import ArgumentParser
from os import makedirs
from shutil import copy
import urllib.parse


def main():
    parser = ArgumentParser()
    parser.add_argument('playlist')
    parser.add_argument('directory')

    args = parser.parse_args()

    makedirs(args.directory, exist_ok=True)

    with open(args.playlist) as file:
        data = file.read().splitlines()

    files = []
    for i in data:
        if i.startswith('file://'):
            #files.append("'" + urllib.parse.unquote(i)[7:] + "'")
            files.append(urllib.parse.unquote(i)[7:])

    for j in files:
        copy(j, args.directory)


if __name__ == '__main__':
    main()
