Skip to content

Commit

Permalink
V1.0.0
Browse files Browse the repository at this point in the history
Initial Version
  • Loading branch information
BenjV committed Jan 3, 2017
1 parent f277d4f commit 33906e1
Show file tree
Hide file tree
Showing 337 changed files with 105,535 additions and 0 deletions.
2 changes: 2 additions & 0 deletions AddicMapping.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
{
}
162 changes: 162 additions & 0 deletions AutoSub.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,162 @@
import sys
import getopt
import os
import signal
import time
import locale
import platform,shutil
from uuid import getnode

# Root path
base_path = os.path.dirname(os.path.abspath(__file__))

# Insert local directories into path
sys.path.insert(0, os.path.join(base_path, 'library'))


#signal.signal(signal.SIGTERM, autosub.AutoSub.signal_handler)

help_message = '''
Usage:
-h (--help) Prints this message
-c (--config=) Forces AutoSub.py to use a configfile other than ./config.properties
-d (--daemon) Run AutoSub in the background
-l (--nolaunch) Stop AutoSub from launching a webbrowser
Example:
python AutoSub.py
python AutoSub.py -d
python AutoSub.py -d -l
python AutoSub.py -c/home/user/config.properties
python AutoSub.py --config=/home/user/config.properties
python AutoSub.py --config=/home/user/config.properties --daemon
'''

# TODO: comments in everyfile

class Usage(Exception):
def __init__(self, msg):
self.msg = msg

def main(argv=None):

import autosub

#From Sickbeard / Headphones
try:
locale.setlocale(locale.LC_ALL, "")
autosub.SYSENCODING = locale.getpreferredencoding()
except (locale.Error, IOError):
pass

# for OSes that are poorly configured, like synology & slackware
if not autosub.SYSENCODING or autosub.SYSENCODING in ('ANSI_X3.4-1968', 'US-ASCII', 'ASCII'):
autosub.SYSENCODING = 'UTF-8'

Update = False
if argv is None:
argv = sys.argv
try:
try:
opts, args= getopt.getopt(argv[1:], "hc:dlu", ["help","config=","daemon","nolaunch","updated="])
except getopt.error, msg:
raise Usage(msg)

# option processing
for option, value in opts:
if option in ("-h", "--help"):
raise Usage(help_message)
if option in ("-c", "--config"):
if os.path.exists(value):
autosub.CONFIGFILE = value
else:
print "ERROR: Configfile does not exists."
os._exit(0)
if option in ("-l", "--nolaunch"):
autosub.LAUNCHBROWSER = False
if option in ("-d", "--daemon"):
if sys.platform == "win32":
print "ERROR: No support for daemon mode in Windows"
# TODO: Service support for Windows
else:
autosub.DAEMON = True
if option in ("-u"):
autosub.UPDATED = True

except Usage, err:
print >> sys.stderr, sys.argv[0].split("/")[-1] + ": " + str(err.msg)
print >> sys.stderr, "\t for help use --help"
return 2

#load configuration

print "AutoSub: Initializing variables and loading config"
autosub.Initialize()

#here we remove the beautifull soap folders because we don't use them anymore.
BsPath = os.path.join(autosub.PATH,'library','beautifulsoup')
Bs4Path = os.path.join(autosub.PATH,'library','bs4')
try:
if os.path.isdir(BsPath):
shutil.rmtree(BsPath)
if os.path.isdir(Bs4Path):
shutil.rmtree(Bs4Path)
except Exception as error:
print 'Autosub could not remove the absolute beautifullsoap folders'
# check the logfile location and make it the default if neccessary
LogPath,LogFile = os.path.split(autosub.LOGFILE)
if not LogFile:
LogFile = u"AutoSubService.log"
try:
if not os.path.exists(LogPath):
try:
os.makedirs(LogPath)
except Exception as error:
print "Could not create log folder, fallback to default"
LogPath = autosub.PATH
except Exception as error:
LogPath = autosub.PATH
autosub.LOGFILE = os.path.join(LogPath,LogFile)

autosub.NODE_ID = getnode()

import autosub.AutoSub

# setup de signal handler for Terminat en Keyboard interupt.
signal.signal(signal.SIGTERM, autosub.AutoSub.signal_handler)
signal.signal(signal.SIGINT, autosub.AutoSub.signal_handler)

print "AutoSub: Starting output to log. Bye!"
log = autosub.initLogging(autosub.LOGFILE)

if autosub.DAEMON:
autosub.AutoSub.daemon()
os.chdir(autosub.PATH)

autosub.PID = str(os.getpid())
try:
with open('autosub.pid' , "w", 0) as pidfile:
pidfile.write(autosub.PID + '\n')
except Exception as error:
log.error('AutoSub: Could not create the PID file. Error is:', error)
sys.exit(1)

import autosub.Db
#make sure that sqlite database is loaded after you deamonise
autosub.Db.initDatabase()

log.info("AutoSub: PID is: %s" %str(os.getpid()))
log.debug("AutoSub: Systemencoding is: %s" %autosub.SYSENCODING)
log.debug("AutoSub: Configversion is: %d" %autosub.CONFIGVERSION)
log.debug("AutoSub: Dbversion is: %d" %autosub.DBVERSION)
log.debug("AutoSUb: Autosub version is: %s" %autosub.version.autosubversion)

autosub.AutoSub.start()

log.info("AutoSub: Going into a loop to keep the main thread going")

while True:
time.sleep(1)
if __name__ == "__main__":
sys.exit(main())
78 changes: 78 additions & 0 deletions ExamplePostProcess.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
#------------------------------------------------------------------------------------------------------------------
# This Script is an example of what is possible with the
# PostProcess feature of Auto-Sub
# It will expect the following arguments from autosub:
# argv[1]: Path + filename of the subtitle file
# argv[2]: Path + filename of the video file
# argv[3]: Language of the subtile
# argv[4]: Name of the Serie
# argv[5]: Season number of the serie
# argv[6]: Episode number of the serie
#
# This example moves the videofile and the subfile to a different location.
#------------------------------------------------------------------------------------------------------------------

import os, shutil, errno

#---------------------------------------#
# This is the Start of the main program #
#---------------------------------------#

# First we move the parameters we got from autosub to some easy reading names.
SubSpecs = sys.argv[1]
VideoSpecs = sys.argv[2]
Language = sys.argv[3]
SerieName = sys.argv[4]
SeasonNum = sys.argv[5]
EpisodeNum = sys.argv[6]

#-----------------------------------------------------------------------------------------------------------------#
# Put her the part of the foldername(SrtRoot) you want to be replaced with another folder(DstRooT. #
# Beware, Linux systems are case sensitive!!! #
# If you use a '\' character in a string you have to escape it with another '\' and use '\\' insted. #
#-----------------------------------------------------------------------------------------------------------------#
#SrtRoot = '/volume1/video/series'
#DstRoot = '/volume1/video/tv/shows'
SrtRoot = 'D:\sync\Tv Series'
DstRoot = 'D:\sync\TV\Series'

# here we normalise the path for the current OS
DstRoot = os.path.normpath(DstRoot)
SrtRoot = os.path.normpath(SrtRoot)
#-----------------------------------------------------------------------------------------------------------------#
# Here we create the destination folder.
# We catch the error and if it already exitst its fine otherwise we leave
#-----------------------------------------------------------------------------------------------------------------#

try:
os.makedirs(DstRoot)
except OSError as exception:
if exception.errno != errno.EEXIST:
sys.stdout.write('- Could not create destination folder')
sys.exit(0)
#-----------------------------------------------------------------------------------------------------------------#
# Here we create the destination files specs bij replacing the first part of the spec with a new part
#-----------------------------------------------------------------------------------------------------------------#
DstSubSpecs = SubSpecs.replace(SrtRoot,DstRoot)

# Now we move the subtilefile, if we fail we leave with a error message
try:
shutil.move(SubSpecs,DstSubSpecs)
except Exception as error:
sys.stdout.write(error)
sys.exit(0)

#-----------------------------------------------------------------------------------------------------------------#
# Here we create the destination files specs bij replacing the first part of the spec with a new part
#-----------------------------------------------------------------------------------------------------------------#
DstVideoSpecs = VideoSpecs.replace(SrtRoot,DstRoot)
#-----------------------------------------------------------------------------------------------------------------#
# Now we move the subtilefile, if we fail we leave with a error message
#-----------------------------------------------------------------------------------------------------------------#
try:
shutil.move(VideoSpecs,DstVideoSpecs)
except Exception as error:
sys.stdout.write(error)
sys.exit(0)
sys.stdout.write(" - Postprocess routine finished succesfull")
sys.exit(0)
88 changes: 88 additions & 0 deletions README.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
README

Important info.
Due to changes in the Website of Opensubtitle the scraper for Opensubtitles does not work anymore.
Until this is fixed it is no longer possible to use Opensubtitles

+--- AutoSub
|
+--- Uses SubtitleSeeker API, supporting the following website:
| +--- Podnapisi
| +--- Subscene
|
+--- Opensubtitles support.
| +--- Requires account.
| \--- Limited downloads per 24 hours. (Regular: 30 - VIP: 55)
|
+--- Addic7ed support.
| +--- Requires account.
| \--- Limited downloads per 24 hours. (Regular: 30 - VIP: 55)
|
+--- Notifications
| +--- Windows & Windows Phone
| | +--- Pushalot
| | \--- Growl
| +--- Android
| | +--- Notify My Android
| | \--- Pushover
| +--- OSX & iDevices
| | +--- Pushover
| | +--- Growl
| | +--- Prowl
| | \--- Boxcar
| \--- Other
| +--- Email
| +--- Twitter
| +--- Telegram
| \--- Plex Media Server
|
\--- Features
+--- Mobile template, automatically detected.
+--- Multiple folder support, separate folders with a comma. Example: D:\Series1,D:\Series2
+--- Select which languages you want to allow(Dutch and/or English).
+--- Select if you want a notification for a sub.
+--- Select the suffix you want to use for the language (only one suffix can be empty)
+--- Choose if you want to search for an other language if the dutch sub is not available
+--- Remove English subtitle when the Dutch subtitle has been downloaded.
+--- Configure a custom post-process script.
+---
\--- Home tables.
+--- Both
| +--- Select 10, 25, 50, 100, All items to display. Options are stored using localStorage.
| \--- Search field, which allows you to search on show name.
+--- Wanted
| +--- Option to skip show when clicking on the wrench symbol.
| +--- Red Color shows which match criteria is used (e.g. Source, Quality, Codec , Release Group)
| +--- Option to skip season when clicking on the season.
| +--- Show ImdbId and AddiceID which are also hyperlink tot those websites.
+ \--- Display videofilename by hovering over the show name
+--- Downloaded
+--- Display original subtitle and website by hovering over the show name
\--- Preview of the sub file

To use:

Ubuntu
Make sure you have python installed. Also you need the python-cheetah package:
* sudo apt-get install python-cheetah
* Download the zip file from our download section
* Unzip the file, change to the directory where AutoSub.py is located
* Start the script: "python AutoSub.py"
* A webbrowser should now open
* Go to the config page, check the settings, make sure you set atleast: path
(Should point to the location where AutoSub.py is located. Seriespath (Should point to the root of your series folder)
* Shutdown AutoSub and start it again
Enjoy your subtitles!

Requirements for running AutoSub:
- Install Cheetah : https://pypi.python.org/pypi/Cheetah/2.4.4
- Python2.7

For Synology users use python from the SynoCommunity this has cheetah already included

You can use a version lower than python2.7 but as an additional dependency, you have to install
the python html5lib module: https://pypi.python.org/pypi/html5lib/1.0b3




Loading

0 comments on commit 33906e1

Please sign in to comment.