Monday 27 October 2008

Hide your subtitle files

In nautilus, i like to be able to browse through my movies without having to see subtitle files. Using the terminal, i navigate to my film folder and run this command occasionally to add the filenames of subtitle files to the .hidden file, which describes what should be normally viewable within the window. The subs still play fine of course, but i dont have to see them cluttering up my view.

ls *.ifo *.idx *.sub *.srt >> .hidden | uniq -u > .hidden

The command lists all files with the target extention, appends them to the .hidden, then gets rid of duplicates and writes the unique list back to .hidden. the reason for this is that i may want additional content to be in my .hidden file and a straight ls *.ifo *.idx *.sub *.srt > .hidden would wipe that out

Sunday 12 October 2008

Merge two avi parts into one.

I've lost count of how many times i've had to fish out this command from some script or other to give to someone over at ubuntu forums to help them out. It's not that its ingenious or anything, but more that the first thing someone tries when they want to merge a split movie is cat. cat's great for a lot of things, but video isnt one of them. it usually spits out a file that's the size of movie_cd1.avi + movie_cd2.avi, but with only the video from movie_cd1. especially annoying when you only find out halfway through watching it :p

This below has served me well and if i post it here i dont have to go fishing around my hard drive for it ever again. The -forceidx flag usually solves audio sync issues that can arise and works about 95% of what i throw at it.
mencoder -forceidx -oac copy -ovc copy -o out.avi cd1.avi cd2.avi

Thursday 9 October 2008

automatically add cd2 to playlist if present

This will , as the name suggests, add movie cd1.avi and movie cd2.avi to a playlist, if its present. This means there's no messing around in the middle of a film if your films are encoded to fit on two 700mb cds for example; it'll just play the 2nd part right after the first.

It'll only work if the first filename contains cd1 or CD1. I put this script in my /usr/bin folder and mark it as executible, then just using nautilus i set my video files to open with it instead of with a normal video player. If the filename doesn't contain cd1 or CD1, it'll just play the file normally. This is set up for gmplayer, but it works fine in xine (the -idx flag can be removed if using xine or a xine-based player)

#! /usr/bin/python

import sys, os

s = sys.argv[1]
cd2 = s.strip().replace('cd1', 'cd2')
cd2 = t.strip().replace('CD1', 'CD2')
if s == cd2:
os.system('''gmplayer "''' + s +'''"''')
else:
os.system('''gmplayer -idx "''' + s + '''" "''' + cd2+'''"''')

Wednesday 8 October 2008

play from rar archive


Another right-click menu entry I've set up in nautilus-actions is a 'play from rar' button. Now, for some irritating reason, i cant get it to pass anything beyond the parameter %M, so i had to put it in a script. It doesn't really need to be a python script, but mine is python anyway because i like messing with python, no matter how trivial the task at hand may be ;)

The other reason it's in python is because it's part of a movie catalogue program im writing, much like a lot of my other scripts.

All this script really does is execute the command:
unrar p -inul ARCHIVE.rar |mplayer -fs -noidx -

I use mplayer, and i like it to come up fullscreen, hence the -fs flag. -noidx is needed because the file is essentially being streamed from the rar archive. Xine and VLC should probably work just as well with the right setting flags.

#! /usr/bin/python

import sys, os

video = sys.argv[1]
os.system("unrar p -inul " + video + "|mplayer -fs -noidx -")

right-click, view movie's imdb page

I've been using this for a while now. If like me, you have a large proportion of your films legally backed up on your hard drive but dont deal with a media centre app, you want a nice quick method for looking up the plot synopsys, rating, or review on imdb.com. Well this is the script i use:

#! /usr/bin/python

import sys, os, os.path

myPath = sys.argv[1]
(dirName, fileName) = os.path.split(myPath)
(fileBaseName, fileExtension)=os.path.splitext(fileName)
t = fileBaseName.lower()
t = t.strip().replace("'", "")
t = t.strip().replace('cd1', '')
t = t.strip().replace('cd2', '')
t = t.strip().replace('CD1', '')
t = t.strip().replace('CD2', '')
t = t.strip().replace('.', ' ')
t = t.strip().replace('-', ' ')
t = t.strip().replace('_', ' ')
t = t.split('x264')
t = t[0].split('xvid')
t = t[0].split('divx')
t = t[0].split('unrated')
t = t[0].split('dvdr')
t = t[0].split('dvdrip') 
t = t[0].split(' cam ')
t = t[0].split(' ts ')
t = t[0].split(' scr ')
t = t[0].split('screener')
t = t[0].split('dvdscr')
t = t[0].split('r5')
t = t[0].split('limited')
t = t[0].split('internal')
t = t[0]
os.system('''firefox "google.com/search?btnI=1&q='''+ t + ''' imdb"''')

It's located at ~/scripts/imdb but you can put it anywhere of course. I create an entry on the right-click menu using nautilus-actions but if you don't use gnome you'll have to use an alternative method. This screencap should illustrate how I've set up nautilus-actions: