Skip to content

Instantly share code, notes, and snippets.

@ahmedash95
Last active December 14, 2017 01:02
Show Gist options
  • Save ahmedash95/349e46505cb1a8e10929b3f72b3b1188 to your computer and use it in GitHub Desktop.
Save ahmedash95/349e46505cb1a8e10929b3f72b3b1188 to your computer and use it in GitHub Desktop.
PluralSight courses sorter

PluralSight sorter

This script will help you to sort videos just use it as below and let him deal with it ;)

$ python ps-sorter.py "/path/to/course-directory"
"""
Plural Sight Courses sorter
@author: <[email protected]> Ahmed Ashraf
@twitter: @ahmedash95
This script will help you to sort videos
just use it as below and let him deal with it ;)
```
$ python ps-sorter.py "/path/to/course-directory"
```
"""
import sys
from os import listdir,sep,rename
from os.path import isfile, join
args = sys.argv
# directory of videos
course_directory = args[1]
# List all video files inside this directory
files = [f for f in listdir(course_directory) if isfile(join(course_directory, f))]
def get_new_file_name(name):
return "-".join(name.split("-")[-2:]).split('.')[0] + " - " + name
def rename_file(path,old,new):
rename(path + sep + old,path + sep + new)
# Get new names for files
files_names = []
for f in files:
new_name = get_new_file_name(f)
files_names.append([f,new_name])
sorted_files_list = sorted(files_names, key=lambda k: k[1])
# rename files
i = 1
for old_name,new_name in sorted_files_list:
new_name_schema = "{0:02} - ".format(i) + new_name
rename_file(course_directory,old_name,new_name_schema)
print "Done For File : {}".format(new_name)
i+=1
print "Your course files has been sorted succesfully"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment