Advertisement
Guest User

Untitled

a guest
Jul 4th, 2020
444
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 5.06 KB | None | 0 0
  1. import os, time, shutil, sys
  2. from os import environ, path
  3. fileSubs = open("/home/yannvs/Archive/SubsSeries.txt", "a")
  4. fileSubs.write("Scan iniciado: "+ time.ctime())
  5.  
  6. EventType = environ.get('sonarr_eventtype')
  7. #fileSubs.write("\nEventType: "+EventType)
  8. #Event type: Download ##Download or Upgrade, same answer
  9. if EventType == "Test":
  10.     sys.exit("Test event ok")
  11.  
  12. isUpgrade = environ.get('sonarr_isupgrade')
  13. #fileSubs.write("\nIs upgrade: "+isUpgrade)
  14. #Is upgrade: False
  15.  
  16. DriveFileName = os.path.basename( environ.get('sonarr_episodefile_relativepath') )
  17. #fileSubs.write("\nDriveFileName: "+DriveFileName)
  18. #DriveFileName: Most Dangerous Game - S01E03 - WEBDL-1080p.mkv
  19. DriveFileNameWO = DriveFileName[:-4]
  20. #fileSubs.write("\nDriveFileNameWO: "+DriveFileNameWO)
  21. #DriveFileNameWO: Most Dangerous Game - S01E03 - WEBDL-1080p
  22.  
  23. DriveFolderPath = environ.get('sonarr_series_path')+"/"
  24. #fileSubs.write("\nDriveFolderPath: "+DriveFolderPath)
  25. #DriveFolderPath: /home/yannvs/Media/TV Shows/Most Dangerous Game/
  26.  
  27. DriveSeriesFullPath = environ.get('sonarr_episodefile_path')
  28. #fileSubs.write("\nDriveMovieFullPath: "+DriveSeriesFullPath)
  29. #DriveSeriesFullPath: /home/yannvs/Media/TV Shows/Most Dangerous Game/Season 01/Most Dangerous Game - S01E03 - WEBDL-1080p.mkv
  30. DriveSeriesSeasonPath = os.path.dirname(DriveSeriesFullPath)+"/"
  31. #DriveSeriesSeasonPath: /home/yannvs/Media/TV Shows/Most Dangerous Game/Season 01/
  32.  
  33. HomeFolderPath = environ.get('sonarr_episodefile_sourcefolder')
  34. #fileSubs.write("\nHomeFolderPath: "+HomeFolderPath)
  35. #HomeFolderPath: /home/yannvs/Torrent/Most.Dangerous.Game.S01E03.The.Rules.1080p.WEB-DL.AAC2.0.H.264-WELP
  36. HomeFolderPathCheck = os.path.basename(HomeFolderPath)
  37. #fileSubs.write("\nHomeFolderPathCheck: "+HomeFolderPathCheck)
  38. #HomeFolderPathCheck = Most.Dangerous.Game.S01E03.The.Rules.1080p.WEB-DL.AAC2.0.H.264-WELP
  39.  
  40. HomeMovieFullPath = environ.get('sonarr_episodefile_sourcepath')
  41. #fileSubs.write("\nHomeMovieFullPath: "+HomeMovieFullPath)
  42. #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
  43.  
  44.  
  45. if EventType == "Download":
  46.     Season = 0
  47.     x = 0
  48.     while Season == 0:
  49.         x += 1
  50.         if "S"+str(x).zfill(2) in DriveFileNameWO:
  51.             Season = str(x).zfill(2)
  52.             #fileSubs.write("\nSeason: "+Season)
  53.             #Season: 01
  54.  
  55.     Episode = 0
  56.     y = 0
  57.     while Episode == 0:
  58.         y += 1
  59.         if "E"+str(y).zfill(2) in DriveFileNameWO:
  60.             Episode = str(y).zfill(2)
  61.             #fileSubs.write("\nEpisode: "+Episode)
  62.             #Episode: 03
  63.  
  64.     SE = "S"+Season+"E"+Episode
  65.     #fileSubs.write("\nSE: "+SE)
  66.     #SE: S01E03
  67.  
  68.  
  69.     HomeFolderPath = HomeFolderPath+"/"
  70.     for (path, root, files) in os.walk(HomeFolderPath):
  71.        
  72.         #fileSubs.write("\nPathAtual: "+path)
  73.         for eachfile in files:
  74.            
  75.             if path.endswith("/"):
  76.                 CurrentBasenameFolder = os.path.basename(path[:-1])
  77.             else:
  78.                 CurrentBasenameFolder = os.path.basename(path)
  79.                 path = path+"/"
  80.             #fileSubs.write("\nPath&Basename: "+CurrentBasenameFolder)
  81.  
  82.             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":
  83.                 #fileSubs.write("\nPath&Basename access")
  84.                
  85.                 if SE in eachfile:
  86.                     if eachfile.lower().endswith(".pt.srt") or eachfile.lower().endswith(".por.srt") or eachfile.lower().endswith(".portugues.srt"):
  87.                         shutil.copy(path+eachfile, DriveSeriesSeasonPath + DriveFileNameWO + ".pt.srt")
  88.                         fileSubs.write("\n1->"+os.path.join(path,eachfile))
  89.                         continue
  90.  
  91.                     if eachfile.lower().endswith("_forced.srt") or eachfile.lower().endswith(".forced.srt"):
  92.                         shutil.copy(path+eachfile, DriveSeriesSeasonPath + DriveFileNameWO + ".pt.forced.srt")
  93.                         fileSubs.write("\n2->"+os.path.join(path,eachfile))
  94.                         continue
  95.  
  96.                     if eachfile.lower().endswith(".en.srt"):
  97.                         shutil.copy(path+eachfile, DriveSeriesSeasonPath + DriveFileNameWO + ".en.srt")
  98.                         fileSubs.write("\n3->"+os.path.join(path,eachfile))
  99.                         continue
  100.  
  101.                     if eachfile.lower().endswith(".srt"):
  102.                         #fileSubs.write("\n"+path+eachfile+"----"+DriveSeriesSeasonPath + DriveFileNameWO + ".pt.srt")
  103.                         shutil.copy(path+eachfile, DriveSeriesSeasonPath + DriveFileNameWO + ".pt.srt")
  104.                         fileSubs.write("\n4->"+os.path.join(path,eachfile))
  105.                         continue
  106.  
  107. fileSubs.write("\nScan terminado: "+ time.ctime()+"\n\n")
  108. fileSubs.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement