Solution: Python subtitle downloader

Development | Programming languages
Python script to automatically download subtitles for any movie/tv series episode.
No attachments.
__author__ = 'aman'
import hashlib
import os
import sys
import urllib.request, urllib.parse
import urllib3

def get_hash(name):
    readsize = 64 * 1024
    with open(name, 'rb') as f:
        size = os.path.getsize(name)
        data =, os.SEEK_END)
        data +=
    return hashlib.md5(data).hexdigest()
# Add as necessary
videoExtensions = [".avi",".mp4",".mkv",".mpg",".mpeg",".mov",".rm",".vob",".wmv",".flv",".3gp"]
def subGetter(filename):
        originalFileName = filename
        for videoExt in videoExtensions:
            filename = filename.replace(videoExt, "")
        if originalFileName == filename:
            return "Not a media file."
        hash = get_hash(originalFileName)
        headers = { 'User-Agent' : 'SubDB/1.0 (subtitle-downloader/1.0;' }
        link = "" + hash + "&language=en"
        req = urllib.request.Request(link, None, headers)
        response = urllib.request.urlopen(req).read()
        with open (filename + ".srt", "wb") as subtitle:
            print("Success! " + filename)
        print ("Not found! " + filename)
# Replace with the path to your movie directory        
rootdir = "c:\\Movies\\"
# Iterate the root directory recursively using os.walk and for each video file present get the subtitle
for root, subFolders, files in os.walk(rootdir):
    for file in files:
        fname = os.path.join(root, file)

on May 06th, 2019 (9:44 pm)
What masters said
You must sign in to comment!!
All comments
This solution has not been commented yet.