rajiv-v
10/6/2015 - 11:14 PM

Rename the video files and subtitle files to match the movie name from the folder name. Then execute mkvmerge and create a mkv file.

Rename the video files and subtitle files to match the movie name from the folder name. Then execute mkvmerge and create a mkv file.


# ~/.bashrc: executed by bash(1) for non-login shells.

# Note: PS1 and umask are already set in /etc/profile. You should not
# need this unless you want different defaults for root.
# PS1='${debian_chroot:+($debian_chroot)}\h:\w\$ '
# umask 022

# You may uncomment the following lines if you want `ls' to be colorized:
# export LS_OPTIONS='--color=auto'
# eval "`dircolors`"
# alias ls='ls $LS_OPTIONS'
# alias ll='ls $LS_OPTIONS -l'
# alias l='ls $LS_OPTIONS -lA'
#
# Some more alias to avoid making mistakes:
# alias rm='rm -i'
# alias cp='cp -i'
# alias mv='mv -i'

alias dl='cd /data/Transmission/Downloads'
alias mov='cd /data/Videos/Movies'
alias makemkv='python /usr/local/bin/automkvmerge.py'
export LD_LIBRARY_PATH="/apps/plexmediaserver/Binaries"
export PLEX_MEDIA_SERVER_APPLICATION_SUPPORT_DIR="/apps/plexmediaserver/MediaLibrary"
export PATH=$PATH:/apps/plexmediaserver/Binaries
"Plex Media Scanner" --scan --refresh --section 2


Plex API : "846cbd44a1b025a65da6592223f043896ae71795"

# English   - Section 1
# HD        - Section 2
# Tamil     - Section 4
# Hindi     - Section 5
# Malayalam - Section 6

# Download Subtitles with Subliminal 
subliminal download -l en <Movie-file.ext> -v

# In the downloads directory
rsync -avPn "Movie (Year)" /data/Videos/Movies/English #Dry Run
rsync -avP "Movie (Year)" /data/Videos/Movies/English #Actual Run

#optional remove old mp4/mkv files
rm *.mp4
rm *-1*
# 1. Copy automkvmerge.py python file to usr/local/bin
cd /usr/local/bin
chmod +x automkvmerge.py

# 2. Now update bashrc file.

cp ~/.bashrc ~/.bashrc.bak
nano ~/.bashrc

# 3. Add the following to the end of the file. 
alias makemkv='python /usr/local/bin/automkvmerge.py'

# 4. Exit ssh and reconnect
'''
Created on Oct 6, 2015

@author: rv279r
'''

import os
from subprocess import Popen

print os.getcwd()

theDir = os.getcwd()
title = os.getcwd().split('/')[-1]
print 'Title Name: ' + title

vidCounter = 0
srtCounter = 0
vidExt = ['mp4','avi','mkv']
subExt = ['srt']

for root, dirs, files in os.walk(theDir):
    for name in files:    
        if name.lower().endswith(tuple(vidExt)):
            vidCounter += 1
            print "Video file " + str(vidCounter) + " : " + name
        if name.lower().endswith(tuple(subExt)):
            srtCounter += 1
            print "Subtitle file " + str(srtCounter) + " : " + name

print 'Video Files Found: ' + str(vidCounter)
print 'Subtitle Files Found: ' + str(srtCounter)

if (vidCounter == 1) and (srtCounter == 1):
    for root, dirs, files in os.walk(theDir):
        for name in files:
            if name.lower().endswith(tuple(subExt)):
                subExtn = os.path.splitext(name)[1]
                inSubfile = title + subExtn
                os.rename(os.path.join(root, name),os.path.join(root,inSubfile))
                print "Renamed: " + name + " to " + inSubfile
                
            if name.lower().endswith(tuple(vidExt)):
                vidExtn = os.path.splitext(name)[1]
                inVidfile = title + "-1" + vidExtn
                os.rename(os.path.join(root, name),os.path.join(root,inVidfile))
                print "Renamed: " + name + " to " + inVidfile
    
    print
    print

    titleExt = title + '.mkv'

    print ' '.join(['mkvmerge','-o',titleExt,inVidfile,inSubfile])

    Popen(["mkvmerge", "-o", titleExt, inVidfile, inSubfile])


elif (vidCounter > 1) or (srtCounter > 1):
    print "Error! : Multiple Video/Subtitle Sources"