Last active
April 11, 2023 08:04
-
-
Save pncnmnp/62f9775103c4166f861777d5108f3c9b to your computer and use it in GitHub Desktop.
edit the 'path' variable to the place where your tv show directories are, then edit command line options accordingly.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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!') |
Years later, I realized that this can be done in 1 line of bash script:
cd ~/shows/ && cd "$(ls | sort -R | tail -1)" && cd "$(ls | sort -R | tail -1)" && vlc "$(ls ./*.mp4 ./*.mkv | sort -R | tail -1)"
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Change your
.bashrc
file to something like:alias tv='python3.5 /file_path/random_episode.py'
Then use
tv <command_line_show_shortcut>