Here is a way to use use youtube-dl programmatically with Python, and strip the filename from spaces and special characters by using the ‘restrictfilenames’ options :

import youtube_dl
import os
import pyperclip

home_dir = os.path.expanduser("~")

url = pyperclip.paste().strip()

filetmpl = u'%(title)s.%(ext)s'

ydl_opts = {"outtmpl": os.path.join(home_dir, filetmpl), "restrictfilenames": True}

with youtube_dl.YoutubeDL(ydl_opts) as ydl:
    ydl.download([url])

Pyperclip is here used to get the url from the clipboard, you can of course edit this script as you wish.