Skip to content

Instantly share code, notes, and snippets.

@pncnmnp

pncnmnp/random_episode.py

Last active Apr 12, 2019
Embed
What would you like to do?
edit the 'path' variable to the place where your tv show directories are, then edit command line options accordingly.
from random import choice
from os import listdir, chdir, system
from os.path import isdir
from glob import glob
#from subprocess import Popen
from readline import parse_and_bind
from pprint import pprint
from sys import argv
'''
NOTE: This code supports 2-level directory structure.
Episodes can be either in some sort of 'seasons' dir
or they can all be in the root dir.
'''
# enter your media library path
path = '/home/parthparikh/parth/seasons/'
# command line options
names = {'f':'Friends/', 'h':'HIMYM/', 't':'The Big Bang Theory/', 's':'Seinfeld/'}
lock = False
try:
if argv[1] in names:
path += names[argv[1]]
lock = True
except:
pass
if not lock:
print('Enter \' q \' or \'\' to exit!')
while(not lock):
try:
chdir(path)
parse_and_bind("tab: complete")
title = input('Enter name of show: ')
if isdir(path+title+'/'):
path += title + '/'
break
elif title == 'q':
exit(0)
else:
print('Available options: ')
pprint(glob('*'))
except:
break
seasons = choice(listdir(path))
if seasons[-1] != '/':
seasons += '/'
path += seasons
try:
if path[:-1].split('.')[-1] in ['mkv', 'mp4', 'm4v', 'avi']:
system("vlc '"+path[:-1]+"'")
else:
episodes = glob(path+'*.mkv')+glob(path+'*.mp4')+glob(path+'*.m4v')+glob(path+'*.avi')
episode = choice(episodes)
print(episode)
# Put your vlc-media-player path ( different for mac, windows and linux )
# Popen(["/usr/bin/vlc","%s" % episode])
system("vlc '"+episode+"'")
lock = True
except:
if lock:
print('Error! Terminating! Check your vlc path or directory path!')
@pncnmnp

This comment has been minimized.

Copy link
Owner Author

@pncnmnp pncnmnp commented Feb 7, 2019

Change your .bashrc file to something like:
alias tv='python3.5 /file_path/random_episode.py'
Then use tv <command_line_show_shortcut>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment