Project pyCountVids - Python Script To Count Total Videos in a Directory
So, I've started working on my long awaited project by implementing it in small increments. First, I've decided to write a python script that counts total videos in a directory and its sub-directory.
This script can be run by typing in the following command:
Hope it comes useful to anyone looking for such script.
Ciao.
MG
#!/usr/bin/env python2
import os
import sys
rootDir = sys.argv[1]
totalVideoCounter = 0
videoExtension = [".3g2", ".3gp", ".asf", ".asx", ".avi", ".flv", \
".m2ts", ".mkv", ".mov", ".mp4", ".mpg", ".mpeg", \
".rm", ".swf", ".vob", ".wmv", "m4v"]
for dirPath, subdirList, fileList in os.walk(rootDir,topdown=False):
dirName = dirPath.split(os.path.sep)[-1]
videoCounter = 0
for fname in fileList:
if fname.endswith(tuple(videoExtension)):
videoCounter +=1
totalVideoCounter +=1
if (videoCounter > 0):
print('Found directory: %s' %dirName )
print('Total videos found: %i' %videoCounter)
This script can be run by typing in the following command:
$ ./list-videos.py ~/Videos/Movies/
This will list the total videos in sub-directory and videos lying outside sub-directories but inside the main directory.
This script is pretty self-explanatory and can be better understood by just googling.Hope it comes useful to anyone looking for such script.
Ciao.
MG
Comments
Post a Comment