icon_direct_download_urls = ["https://example.com/font1.ttf","https://example.com/font.ttf"] #give here the font url
fontNames = ["font1.ttf","font2.ttf"] #give here the font name with extension in the same order corresponding to their url in the icon_direct_download_urls
restart = 0 # give 0 to restart. give 1 if you don't want to restart


import os
import shutil
import ctypes
import ssl
import urllib2

class disable_file_system_redirection:
    _disable = ctypes.windll.kernel32.Wow64DisableWow64FsRedirection
    _revert = ctypes.windll.kernel32.Wow64RevertWow64FsRedirection
    def __enter__(self):
        self.old_value = ctypes.c_long()
        self.success = self._disable(ctypes.byref(self.old_value))
    def __exit__(self, type, value, traceback):
        if self.success:
            self._revert(self.old_value)

def copy_and_create_reg(path):
    files = os.listdir(path)
    with disable_file_system_redirection():
        for i in files:
            Name,Extension = os.path.splitext(i)
            if Extension.lower()==".ttf" or Extension.lower()==".otf":
                shutil.copy(path+"\%s"%(i),r"C:\Windows\Fonts")
                print(os.popen('reg add "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Fonts" /v "%s (TrueType)" /t REG_SZ /d "%s" /f'%(Name,i)).read())
                print("successfully installed %s"%(i))
        
        if restart==0:
            print("restarting the system")
            print(os.popen("shutdown -r -t 0"))
        elif restart==1:
            print("please restart your system for the changes to take effect")

def downloadFile(DownTo, fromURL):
    headers = {'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/74.0.3729.169 Safari/537.36'}
    context = ssl._create_unverified_context()
    request = urllib2.Request(fromURL, headers=headers)
    req = urllib2.urlopen(request,context=context)
    try:
        with open(DownTo, 'wb') as f:
            while True:
                chunk = req.read(100*1000*1000)
                if chunk:
                    f.write(chunk)
                else:
                    break
        if os.path.isfile(DownTo):
            return '{} - {}KB'.format(DownTo, os.path.getsize(DownTo)/1024)
		
    except:
        return 'Please Check URL or Download Path!'
    
def run(ls):    
    workdir=os.environ['PROGRAMDATA']+r'\temp\Fonts'
    if not os.path.isdir(workdir): 
        os.makedirs(workdir)
    for url,fn in ls:
        downloadFile(workdir + "\%s"%(fn),url)
    copy_and_create_reg(workdir)
    shutil.rmtree(workdir)

url_with_filename = list(zip(icon_direct_download_urls,fontNames))

run(url_with_filename)

