#!/usr/bin/env python3

import os
import sys
from urllib.parse import unquote

def rewrite_file(filename):
    with open(filename, 'r') as f:
        content = f.read()

    new_content = unquote(content)

    with open(filename, 'w') as f:
        f.write(new_content)

if __name__ == '__main__':
    try:
        filename = sys.argv[1]
    except IndexError:
        print('You must provide a filename.')
        print('Usage: {} playlist.m3u'.format(os.path.split(__file__)[-1]))
        exit(1)
    rewrite_file(filename)
