fork(1) download
  1. import re
  2. from datetime import datetime
  3.  
  4. def ExtractReleaseYear(title):
  5. rg = re.compile('.*([\[\(]?((?:19[0-9]|20[01])[0-9])[\]\)]?)', re.IGNORECASE|re.DOTALL)
  6. match = rg.search(title) # Using non-greedy match on filler
  7. if match:
  8. releaseYear = match.group(2)
  9. try:
  10. if int(releaseYear) >= 1900 and int(releaseYear) <= int(datetime.now().year) and int(releaseYear) <= 2099: # Film between 1900-2099
  11. return releaseYear
  12. except ValueError:
  13. print("ERROR: The film year in the file name could not be converted to an integer for comparison.")
  14. return ""
  15.  
  16. print(ExtractReleaseYear('2012.(2009).3D.1080p.BRRip.SBS.x264'))
  17. print(ExtractReleaseYear('Into.The.Storm.2012.1080p.WEB-DL.AAC2.0.H264'))
  18. print(ExtractReleaseYear('2001.A.Space.Odyssey.1968.1080p.WEB-DL.AAC2.0.H264'))
Success #stdin #stdout 0.01s 7260KB
stdin
Standard input is empty
stdout
2009
2012
1968