Script to Download Fonts in Bulk From dafont.com

Being into design related stuff since joining college, I've found it a necessity to maintain a decent font collection. In this post, I will share and explain the script which helped me to create my collection.

What my script does is download fonts directly off a top 20 list of fonts from dafont.com, for each sub-category available there.

The website has a very organized way to let users download fonts. First, there are categories like Fancy, Foreign Look, Techno, Gothic etc. Under each of these categories, there are sub-categories. Each subcategory has an ID which will help our purpose.

You can just change the ID range in the script to download fonts of different category.

The Script

#! /usr/bin/python

# Name: dafont.com Bulk Download Tool
# Version: 0.3
# Summary: A tool for downloading top 20 fonts of each sub-category of dafont.com
# License: BSD
# Author: Pranav Ashok
# Author-email: iam@pranavashok.com
# Author-homepage: http://pranavashok.com/blog
# Support: http://pranavashok.com/blog/2010/05/script-to-download-fonts-in-bulk-from-dafont-com
# Support: Twitter (@pranavashok)

from BeautifulSoup import BeautifulSoup
import re
import os
import commands
import string

for cat in range(101, 119): #ID Range 101-119
	url = 'http://www.dafont.com/theme.php?cat=%d&nb_ppp=20' % cat
	contents = commands.getoutput("curl -s '"+url+"'")

	w = open('downloader.sh', 'a')
	
	soup = BeautifulSoup(contents)
	directory = soup.find('title').contents
	wholeTag = soup.findAll('a', {"class" : "dl"})
	directory[0] = string.rstrip(directory[0], " | dafont.com")
	fontCat, useless, subCat = directory[0].partition(" > ")
	
	w.write('mkdir \"%s\"\n' % fontCat)
	w.write('cd \"%s\"\n' % fontCat)

	w.write('mkdir \"%s\"\n' % subCat)
	w.write('cd \"%s\"\n' % subCat)
	for link in wholeTag:
		name = os.path.basename(link['href'])
		fileName, fileExt = os.path.splitext(name)
		fileName = string.lstrip(fileName, "?f=")
		w.write('wget -c -O \"%s.zip\" \"%s\" \n' % (fileName, link['href']))
	w.write('cd ..\n')
	w.write('cd ..\n')
	w.close()

Dependencies

This script has used python library called BeautifulSoup for parsing HTML. If you are a developer, I'd recommend you to try BeautifulSoup. It's got a nice documentation and it's easy to use.

Usage

1. Download dafont.com Bulk Downloader Tool
2. Extract the files
3. Open terminal and navigate to the folder where final.py is located.
4. Execute the command

$ python final.py

5. A file called downloader.sh would have been generated in the folder.
6. Copy it to the place where you want the fonts to be downloaded.
7. Navigate to that folder in terminal and run the command

$ sh downloader.sh

8. You'll have a neatly organized collection of fonts. All you gotta do now is extract them from their archives.

Enjoy! And please post your suggestions.

Published by

Pranav

I'm a student pursuing a masters degree in Theoretical Computer Science. Prior to this, I completed my bachelors in Computer Science and Engineering and worked for an year, until I realized that the slogging off at an office in front of the computer is not the job for me. I am easily fascinated and distracted by everything under the sun, which has kept me busy trying to figure out what I am going to. I love dreaming about making radical life decisions, bringing happiness on faces and about a world full of meadows and fluttery creatures and people who do not judge you for what you love doing.

6 thoughts on “Script to Download Fonts in Bulk From dafont.com”

  1. python Final.py

    Traceback (most recent call last):  File "Final.py", line 26, in     directory = soup.find('title').contentsAttributeError: 'NoneType' object has no attribute 'contents'

  2. Thank you for sharing this little gem
    I'm trying to improve this script, to fetch all fonts within a category.
    Will you mind if I publish it (giving you credits)?

    Cheers

  3. directory = soup.find('title').contents
    AttributeError: 'NoneType' object has no attribute 'contents'

    pls tell me how to resolve this error..

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>