Auteur Topic: Post processing script  (gelezen 3005 keer)

Offline leejoow

  • Bedankjes
  • -Gegeven: 0
  • -Ontvangen: 0
  • Berichten: 4
Post processing script
« Gepost op: 10 januari 2015, 15:14:41 »
Ik heb inmiddels auto-sub geïnstalleerd gekregen en het download netjes de files. Nu wil ik een script schrijven dat automatisch de subs merged in MKV bestanden.

Om alvast te proberen ben ik aan het stoeien met ExamplePostProcess.py. Ik krijg dit echter op geen enkele manier ingesteld dat hij ook daadwerkelijk het script uitvoert. Ik krijg een error in het log.

Ik heb het script helemaal gestript en enkel twee print commando's overgelaten:
#This Script is an example of what is possible with the
#PostProcess feature of Auto-Sub

import sys

#MAIN FUNCTION
print sys.argv[1]
print sys.argv[2]

Script: /volume1/@appstore/AutoSub-BootstrapBill/ExamplePostProcess.py
Melding: downloadSubs: PostProcess: /volume1/@appstore/AutoSub-BootstrapBill/ExamplePostProcess.py: line 4: import: not found

Script: phyton /volume1/@appstore/AutoSub-BootstrapBill/ExamplePostProcess.py
Melding: downloadSubs: PostProcess: /bin/sh: phyton: not found

Script: phyton2 /volume1/@appstore/AutoSub-BootstrapBill/ExamplePostProcess.py
downloadSubs: PostProcess: /bin/sh: phyton2: not found

Heeft iemand een idee wat er fout gaat?
  • Mijn Synology: DS214Play
  • HDD's: WD30EFRX

Ben(V)

  • Gast
Re: Post processing script
« Reactie #1 Gepost op: 10 januari 2015, 15:39:07 »
Hier een voorbeeld van een script dat ik zelf gebruik.
Je moet niet vergeten in je aanroep python met een full path te gebruiken.
Dit moet je bijvoorbeeld in de config van autosub zetten.
Citaat
/volume1/@appstore/python/bin/python2 /volume1/sync/AutoSub/AutoSubPostProcess.py

Uiteraard moet je het laatste path even aanpassen aan de folder waar jij je script hebt staan.

Code: (python) [Selecteer]
#
#This script is ment to be called from AutoSub as a postprocess when a sub is downloaded.
# The script is tested on a windows enviroment and on a synology enviroment
# It will expect the following arguments:
# argv[1]: Path + filename of the subtitle file
# argv[2]: Path + filename of the video file
# argv[3]: Language of the subtile (not used)
# argv[4]: Name of the Serie (not used)
# argv[5]: Season number of the serie
# argv[6]: Episode number of the serie
#
# The videofile and the subfile will be moved from where sickbeard put them
# to a new location accessble from my mediaplayer and will get a more userfriendly name like below
# /volume1/video/Alleen Series/Arrow/Seizoen 01/01. Pilot.mkv
#                                              /01. Pilot.srt
#                                              /02. Honor Thy Father.mkv
#                                              /02. Honor Thy Father.srt
#                                              /03. Lone Gunmen.mkv
#                                              /03. Lone Gunmen.srt
#                                              / etc .....
# /volume1/video/Alleen Series/Arrow/Seizoen 02/01. City of Heroes.mkv
#                                              /01. City of Heroes.srt
#                                              /02. Identity.mkv
#                                              /02. Identity.srt
#                                              / etc .....
# This script can easly be adapted to also move things like a folder thumbnail, episode thumbnail etc.
# After this rename-ing and moving the status in sickbeard will be updated to "Archived"(e.g. out of control of sickbeard)
# Information about the sickbeadr api can be found here: http://sickbeard.com/api/
# Sickbeard has a build in api-builder which can be invoked via the browser http://localhost:8083/api/builder
# substitute 'localhost' and 'port' with your the 'ipadress' and 'port' of your sickbeard installation and fill in the generated api-key of sickbeard

import os, urllib, json, sys, shutil, datetime, codecs

#-----------------------------------------------------------------------
# Some static information for easy changing
# The "src_loc" part of the files will be changed into "dest_loc" for the move operation
#-----------------------------------------------------------------------

src_loc     = '/volume1/sync/TvSeries'

dst_loc     = '/volume1/sync/Alleen Series'
HistoryLoc  = '/volume1/sync/AutoSub/AutoSubPostProcessHistory.csv'

# List of characters not allowed in a filename
not_allowed_table = dict.fromkeys(map(ord, '/\:*?"<>|'), None)

# Sickbeard Commands and information
# If sickbeard is located on the another machine replace "localhost" with the IPnumber of that machine
# The portnumber is the port sickbeard is using
# The apikey must be generated by your own sickbeard installation

IpAdress    = 'localhost'
port        = '<put here the portnumber used by SickRage>'
ApiKey      = '<Put here yours apikey from SickRage>'

# Copy the arguments from AutoSub to variables for easy changing
sub         = sys.argv[1]
video       = sys.argv[2]
Season      = sys.argv[5]
Episode     = sys.argv[6]

sys.stdout.write("Postprocess routine started")
sys.stdout.flush()

# Opening for Append of the history file so we will know want the original filename was in case we have to search for a better subfile
if not os.path.isfile(HistoryLoc):
HistoryFile = codecs.open(HistoryLoc,encoding='cp1252',mode='a')
HistoryFile.write('"Datum/Tijd","Location","Title","Original Filename"\r\n')
else:
HistoryFile = codecs.open(HistoryLoc,encoding='cp1252',mode='a')


# Here we create the new location for the sub file
# First we find the Serie name.
# I decided to use the directoryname because that is created by sickbeard and is exactly equal to the seriename as used by sickbeard.
# So we get the name from the last directory of the full path
# In case of the serie "Marvel Agents of S.H.I.E.L.D." we have to add an extra dot to the name because a directory name cannot end with a dot and is removed when creating the direcory by sickbeard
# but sickbeard uses the name including the last dot.
# We also change the filenames into easy names (like : %E. EpisodeTitle.mkv and %E. EpisodeTitle.srt)

Serie = video.split("/")[-2]
if 'Marvel' in Serie:
    Serie = Serie + '.'


# Here we use the urllib to open a stream from sickbeard with the "Shows" command
# We get a structure with info about all shows in sickbeard
# Fist we open the stream with the correct command (see sickbeard API documentation)
# Then we read the number of bytes we have to read and convert the resulting json structure in a python structure.

GetShowList = "http://" + IpAdress + ":" + port + "/api/" + ApiKey + "/?cmd=shows&sort=name"
fp = urllib.urlopen(GetShowList)
headers = fp.info()
bytecount = int(headers['content-length'])
SickbeardShows = json.loads(fp.read(bytecount))
fp.close
if (SickbeardShows['result'] != "success") :
    sys.stdout.write("Connection with Sickbeard failed.")
    sys.stdout.flush()
    sys.stderr.write("Connection with Sickbeard failed. ")
    sys.stderr.flush()
    sys.exit(1)
else:
    Tvdbid = str(SickbeardShows['data'][Serie]['indexerid'])
    fp= urllib.urlopen("http://localhost:" + port + "/api/" + ApiKey + "/?cmd=episode&indexerid=" + Tvdbid + "&season=" + Season + "&episode=" + Episode)
    headers = fp.info()
    bytecount = int(headers['content-length'])
    EpisodeInfo = json.loads(fp.read(bytecount))
    fp.close
    if (EpisodeInfo['result'] != "success") :
        sys.stderr.write("No information on this episode available from sickbeard. ")
        sys.stderr.flush()
        sys.exit(1)
EpisodeName = EpisodeInfo['data']['name'].translate(not_allowed_table)

# All info is gathered and we build the destination path for the file moving operation
#  - Split the source in a path and a filename
#  - Retrieve the file extension of the video file
#  - Construct the new locations
#  - Create a "Seizoen" subdirectory if not yet present

src_path, video_file = os.path.split(video)
temp, video_ext = os.path.splitext(video_file)
SeasonPath = src_path.replace(src_loc, dst_loc,1) + "/" + "Seizoen " + Season
Episode_Title = unicode(Episode + ". " + EpisodeName + video_ext)
video_dst = unicode(SeasonPath + "/" + Episode_Title)
sub_dst   = video_dst.replace(video_ext, ".srt")

# Now we check wether the "Seizoen" directory already exists
# if not we create it.

if not os.path.isdir(SeasonPath):
    os.mkdir(SeasonPath)


# Here we move the files the new location.
# We use shutil.move instead of os.rename so the destination can also be another disk or network location.
if not os.path.isfile(sub_dst):
    # move the subfile
    shutil.move(sub,sub_dst)
    if not os.path.isfile(video_dst):
        shutil.move(video,video_dst)
        LogTime = datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")
        HistoryFile.write('"' + LogTime + '"' + ',"' + SeasonPath + "/" + '"' + ',"' + Episode_Title + '"'+ ',"' + video_file  + '"\r\n')
        SetStatus   = "http://" + IpAdress + ":" + port + "/api/" + ApiKey + "/?cmd=episode.setstatus&indexerid=" + Tvdbid + "&season=" + Season + "&episode="+ Episode + "&status=archived&force=1"
        fp= urllib.urlopen(SetStatus)
        headers = fp.info()
        bytecount = int(headers['content-length'])
        StatusResult = json.loads(fp.read(bytecount))
        fp.close
        if StatusResult['result'] != "success" :
            sys.stderr.write("Status change in Sickbeard Failed!")
            sys.stderr.flush()
    else:
        sys.stderr.write( " " + video_dst + "Already exists!")
        sys.stderr.flush()
        sys.exit(1)
else:
    sys.stderr.write(" " + sub_dst + " Already exists!")
    sys.stderr.flush()
    sys.exit(1)
HistoryFile.close()
sys.exit(0)

Offline Matr1x

  • Global Moderator
  • MVP
  • *
  • Bedankjes
  • -Gegeven: 270
  • -Ontvangen: 771
  • Berichten: 5.090
Re: Post processing script
« Reactie #2 Gepost op: 10 januari 2015, 18:59:11 »
Goed bezig Ben(V)...

Toch ben ik blij dat mijn mediaspeler gewoon naar de meta data kijkt (NFO bestand) en het dus niet uitmaakt hoe het bestand heet of waar het staat. Hier wordt eigenlijk alles automatisch gedaan door de pakketten zelf. Ik heb dus geen scripts nodig om dit te regelen. Maar compliment voor het script, want dat ziet er erg goed uit.
  • Mijn Synology: DS224+
  • HDD's: 2x HAT3300-4T
  • Extra's: MR2200ac / RT2600ac

Ben(V)

  • Gast
Re: Post processing script
« Reactie #3 Gepost op: 10 januari 2015, 19:16:08 »
Om nog even terug te komen op de vraag van leejow.
Je kunt die subtitles erin mixen met behulp van ffmpeg (staat standaard op je NAS).
Dat kan met het volgende commando:

ffmpeg -i "movie.mkv" -i "sub.srt" -c copy -map 0 -map 1 "movie_with_sub.mkv"

Je kunt zoiets aanroepen in Python met behulp van popen.


 

sabnzbplus en post-proc voor newzbin

Gestart door daferraBoard SABnzbd (usenet)

Reacties: 5
Gelezen: 7708
Laatste bericht 08 januari 2008, 18:47:08
door daferra
Post scripts toevoegen NZBGet

Gestart door nasbirdBoard NZBGet

Reacties: 3
Gelezen: 3694
Laatste bericht 13 maart 2015, 18:37:17
door nasbird
Post Scripts werken niet

Gestart door sjors86Board NZBGet

Reacties: 2
Gelezen: 3943
Laatste bericht 09 november 2015, 10:37:57
door Zidane10
film gedownload, post-process gedraaid en nu film niet te vinden?

Gestart door SonnemaBoard NZBGet

Reacties: 3
Gelezen: 2137
Laatste bericht 10 april 2013, 18:53:28
door Sonnema
Versleutelvirus Synology nu ook bij Post NL

Gestart door dukardBoard The lounge

Reacties: 12
Gelezen: 5086
Laatste bericht 18 oktober 2014, 14:47:01
door Robert Koopman