Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import os, time, shutil, sys
- from os import environ, path
- fileSubs = open("/home/yannvs/Archive/SubsSeries.txt", "a")
- fileSubs.write("Scan iniciado: "+ time.ctime())
- EventType = environ.get('sonarr_eventtype')
- #fileSubs.write("\nEventType: "+EventType)
- #Event type: Download ##Download or Upgrade, same answer
- if EventType == "Test":
- sys.exit("Test event ok")
- isUpgrade = environ.get('sonarr_isupgrade')
- #fileSubs.write("\nIs upgrade: "+isUpgrade)
- #Is upgrade: False
- DriveFileName = os.path.basename( environ.get('sonarr_episodefile_relativepath') )
- #fileSubs.write("\nDriveFileName: "+DriveFileName)
- #DriveFileName: Most Dangerous Game - S01E03 - WEBDL-1080p.mkv
- DriveFileNameWO = DriveFileName[:-4]
- #fileSubs.write("\nDriveFileNameWO: "+DriveFileNameWO)
- #DriveFileNameWO: Most Dangerous Game - S01E03 - WEBDL-1080p
- DriveFolderPath = environ.get('sonarr_series_path')+"/"
- #fileSubs.write("\nDriveFolderPath: "+DriveFolderPath)
- #DriveFolderPath: /home/yannvs/Media/TV Shows/Most Dangerous Game/
- DriveSeriesFullPath = environ.get('sonarr_episodefile_path')
- #fileSubs.write("\nDriveMovieFullPath: "+DriveSeriesFullPath)
- #DriveSeriesFullPath: /home/yannvs/Media/TV Shows/Most Dangerous Game/Season 01/Most Dangerous Game - S01E03 - WEBDL-1080p.mkv
- DriveSeriesSeasonPath = os.path.dirname(DriveSeriesFullPath)+"/"
- #DriveSeriesSeasonPath: /home/yannvs/Media/TV Shows/Most Dangerous Game/Season 01/
- HomeFolderPath = environ.get('sonarr_episodefile_sourcefolder')
- #fileSubs.write("\nHomeFolderPath: "+HomeFolderPath)
- #HomeFolderPath: /home/yannvs/Torrent/Most.Dangerous.Game.S01E03.The.Rules.1080p.WEB-DL.AAC2.0.H.264-WELP
- HomeFolderPathCheck = os.path.basename(HomeFolderPath)
- #fileSubs.write("\nHomeFolderPathCheck: "+HomeFolderPathCheck)
- #HomeFolderPathCheck = Most.Dangerous.Game.S01E03.The.Rules.1080p.WEB-DL.AAC2.0.H.264-WELP
- HomeMovieFullPath = environ.get('sonarr_episodefile_sourcepath')
- #fileSubs.write("\nHomeMovieFullPath: "+HomeMovieFullPath)
- #HomeMovieFullPath: /home/yannvs/Torrent/Most.Dangerous.Game.S01E03.The.Rules.1080p.WEB-DL.AAC2.0.H.264-WELP/Most.Dangerous.Game.S01E03.The.Rules.1080p.WEB-DL.AAC2.0.H.264-WELP.mkv
- if EventType == "Download":
- Season = 0
- x = 0
- while Season == 0:
- x += 1
- if "S"+str(x).zfill(2) in DriveFileNameWO:
- Season = str(x).zfill(2)
- #fileSubs.write("\nSeason: "+Season)
- #Season: 01
- Episode = 0
- y = 0
- while Episode == 0:
- y += 1
- if "E"+str(y).zfill(2) in DriveFileNameWO:
- Episode = str(y).zfill(2)
- #fileSubs.write("\nEpisode: "+Episode)
- #Episode: 03
- SE = "S"+Season+"E"+Episode
- #fileSubs.write("\nSE: "+SE)
- #SE: S01E03
- HomeFolderPath = HomeFolderPath+"/"
- for (path, root, files) in os.walk(HomeFolderPath):
- #fileSubs.write("\nPathAtual: "+path)
- for eachfile in files:
- if path.endswith("/"):
- CurrentBasenameFolder = os.path.basename(path[:-1])
- else:
- CurrentBasenameFolder = os.path.basename(path)
- path = path+"/"
- #fileSubs.write("\nPath&Basename: "+CurrentBasenameFolder)
- if CurrentBasenameFolder == HomeFolderPathCheck or CurrentBasenameFolder.lower() == "legenda" or CurrentBasenameFolder.lower() == "legendas" or CurrentBasenameFolder.lower() == "subtitle" or CurrentBasenameFolder.lower() == "subtitles" or CurrentBasenameFolder.lower() == "sub" or CurrentBasenameFolder.lower() == "subs":
- #fileSubs.write("\nPath&Basename access")
- if SE in eachfile:
- if eachfile.lower().endswith(".pt.srt") or eachfile.lower().endswith(".por.srt") or eachfile.lower().endswith(".portugues.srt"):
- shutil.copy(path+eachfile, DriveSeriesSeasonPath + DriveFileNameWO + ".pt.srt")
- fileSubs.write("\n1->"+os.path.join(path,eachfile))
- continue
- if eachfile.lower().endswith("_forced.srt") or eachfile.lower().endswith(".forced.srt"):
- shutil.copy(path+eachfile, DriveSeriesSeasonPath + DriveFileNameWO + ".pt.forced.srt")
- fileSubs.write("\n2->"+os.path.join(path,eachfile))
- continue
- if eachfile.lower().endswith(".en.srt"):
- shutil.copy(path+eachfile, DriveSeriesSeasonPath + DriveFileNameWO + ".en.srt")
- fileSubs.write("\n3->"+os.path.join(path,eachfile))
- continue
- if eachfile.lower().endswith(".srt"):
- #fileSubs.write("\n"+path+eachfile+"----"+DriveSeriesSeasonPath + DriveFileNameWO + ".pt.srt")
- shutil.copy(path+eachfile, DriveSeriesSeasonPath + DriveFileNameWO + ".pt.srt")
- fileSubs.write("\n4->"+os.path.join(path,eachfile))
- continue
- fileSubs.write("\nScan terminado: "+ time.ctime()+"\n\n")
- fileSubs.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement