004a / conv2mp4-py

Python script for automatic converts

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

conv2mp4-py

Python 2.7 script that recursively searches through a defined file path and converts MKV, AVI, FLV, and MPEG files to MP4 using handbrake (with AAC audio). It then refreshes a Plex library, and deletes the source file upon success and moves the new files into the defines directory (Plex Library directories for example). Fails over to ffmpeg encode if conversion failure is detected. The purpose of this script is to reduce the number of transcodes performed by a Plex server, by processing all files into an MP4 format.

Dependencies
This script requires Python, Filebot, ffmpeg and Handbrake to be installed on your computer. You can download them from here:
Python
FileBot
ffmpeg
Handbrake

Usage
You need to launch either with the bundled launcher script or manually from a commandline: There is only one argument: the path to the media files

User-defined variables
There are several user-defined variables you will need to edit using notepad or a program like Notepad++.

NOTE: to use a mapped drive, you must run net use z: \server\share /persistent:yes as the user you're going to run the script as (generally Administrator) prior to running the script.

FFMPEG = path to ffmpeg.exe
HANDBRAKE = path to HandBrakeCLI.exe
FILEBOT = path to FileBot.exe
MEDIA_PATH = Path to your uncoverted media

ENABLE_PLEX_UPDATE Set to True to enable the script to update your server
NOTE: Requires PLEX_IP and PLEX_TOKEN to work.
PLEX_IP = the IP address and port of your Plex server (for the purpose of refreshing its library)
PLEX_TOKEN = your Plex server's token (for the purpose of refreshing its library).
NOTE: See https://support.plex.tv/hc/en-us/articles/204059436-Finding-your-account-token-X-Plex-Token for instructions on retrieving your Plex server's token. Your Plex server's token is also easy to retrieve with Couchpotato or SickRage.

MAX_CONVERT_ITEMS = Maximum number of files to convert in one go
LOCALE = Three digit code for your language for example for Hungarian it's 'hun'

Target Folders for converted files
MOVIE_TARGET = Path where you want your movies
TVSHOW_TARGET = Path where you want your TV SHows
LANG_MOVIE_TARGET = Path where you want your foreign language movies
LANG_TVSHOW_TARGET = Path where you want your foreign langue Tv Shows

FOREIGN = Set to true if you want the script to take foreign language into account
PREFER_METADATA = The Script tries to match the description and the metadata of the subtitles in the file, you can try turning it on and off to see if the subtitles were matched better
EXTRACT_SRT = Whether to extract the subtitles from files into external SRTs (External SRT files don't trigger transcoding, while embedded might)

MOVE_FILES = Whether to allow to move the files to new directories or keep them in the same
CREATE_MOVIE_DIRS = Whether to create a directory for each movie file: e.g. it will put the movie Pacific Rim and all it's subtitles to the folder [MOVIE_TARGET or LANG_MOVIE_TARGET]\Pacific Rim (2013)\
CREATE_TVSHOW_DIRS = Whether to create a directory for each TV Show: e.g. it will put the tv show Modern Family and all it's episodes and subtitles to the folder [TVSHOW_TARGET or LANG_TVSHOW_TARGET]\Modern Family\
CREATE_SEASON_DIRS = Used together with CREATE_TVSHOW_DIRS, also adds a Season folder. e.g. first Season of Modern Family will get put into: [TVSHOW_TARGET or LANG_TVSHOW_TARGET]\Modern Family\Season 01\
NOTE: Only Works with CREATE_TVSHOW_DIRS set to True
REMOVE_OLD = Whether to remove the files that have been already converted and are no longer needed
HARD_LINK = Whether to create hardlink between folders, for example if you have a movie with both English and Foreign audio and you want plex to detect it in both the English and Foreign Library the easiest way is to Hard link the directories
NOTE: Only Works with FOREIGN and MOVE_FILES set to True

About

Python script for automatic converts

License:GNU General Public License v3.0


Languages

Language:Python 100.0%