我可以翻译这句话:”how can i know how many episode of a movie do i have in my file”。

huangapple go评论101阅读模式
英文:

how can i know how many episode of a movie do i have in my file

问题

I wanna know how many episodes of a movie I have in my file. The name of episodes are something like this: "name.S01E01.720p.WEB-DL.mkv", "name.S01E02..." I think I should use something like this, but I don't know what's next.

  1. import os
  2. with os.scandir(path) as files:
  3. for file in files:
  4. ...

But every movie has a specific name (for example) "name.Joint.Economic.Area.S01E01.720p.NF.WEBRip.x264-GalaxyTV" or something else, and I wanna write a code that would work with any kind of names. I think the way that I'm doing this is not a professional way to do it.

I used this code:

  1. import os
  2. with os.scandir(path) as files:
  3. for file in files:
  4. num = 01
  5. if any(str(num) in file.name):
  6. print("yes")

But I got an error.

英文:

i wanna know how many episode of a movie i have in my file.
the name of episodes are something like this:
"name.S01E01.720p.WEB-DL.mkv", "name.S01E02..."
i think i should use something like this but idk what's next

  1. import os
  2. with os.scandir(path) as files:
  3. for file in files:
  4. ...

but every movie has a specific name (for example)"name.Joint.Economic.Area.S01E01.720p.NF.WEBRip.x264-GalaxyTV" or some thing else and i wanna write a code that would work with any kind of names

i think the way that im doing this is not a professional way to do it.

i used this one:

  1. import os
  2. with os.scandir(path) as files:
  3. for file in files:
  4. num = 01
  5. if any(str(num) in file.name):
  6. print("yes")

but i got an error.

答案1

得分: 0

以下是您要翻译的代码部分:

  1. #!/usr/bin/env python3
  2. import glob
  3. import os,sys
  4. import re
  5. import json
  6. try:
  7. movie_path_orig = sys.argv[1]
  8. except:
  9. print(f"使用 ./{sys.argv[0]} <电影路径>")
  10. sys.exit(0)
  11. movie_path = os.path.join(movie_path_orig, "*.mkv")
  12. print(f"处理 {movie_path}..")
  13. files = glob.glob(movie_path)
  14. summary = {}
  15. for f in files:
  16. r=re.search("^(.*)S([0-9]{2})E([0-9]{2})(.*)", f)
  17. prefix = r.group(1)
  18. s = int(r.group(2)) # 季节
  19. e = int(r.group(3)) # 集数
  20. suffix = r.group(4)
  21. if prefix not in summary.keys():
  22. summary[prefix] = { 'seasons': { f"{s}": e }, 'prefix': prefix, 'suffix': suffix}
  23. else:
  24. if f"{s}" not in summary[prefix]['seasons'].keys():
  25. summary[prefix]['seasons'][f"{s}"] = e
  26. else:
  27. summary[prefix]['seasons'][f"{s}"] = max(summary[prefix]['seasons'][f"{s}"], e)
  28. print(json.dumps(summary, sort_keys=True, indent=4))
  29. for i in summary.keys():
  30. for season in summary[i]['seasons'].keys():
  31. for episode in range(1, summary[i]['seasons'][season]+1):
  32. s = "{:02d}".format(int(season))
  33. e = "{:02d}".format(episode)
  34. file2chk = f"{summary[i]['prefix']}S{s}E{e}{summary[i]['suffix']}"
  35. if not os.path.exists(file2chk):
  36. print(f"缺失 {file2chk}")
英文:

maybe this can help:

  1. #!/usr/bin/env python3
  2. import glob
  3. import os,sys
  4. import re
  5. import json
  6. try:
  7. movie_path_orig = sys.argv[1]
  8. except:
  9. print(f&quot;use ./{sys.argv[0]} &lt;movie path&gt;&quot;)
  10. sys.exit(0)
  11. movie_path = os.path.join(movie_path_orig, &quot;*.mkv&quot;)
  12. print(f&quot;Processing {movie_path}..&quot;)
  13. files = glob.glob(movie_path)
  14. summary = {}
  15. for f in files:
  16. r=re.search(&quot;^(.*)S([0-9]{2})E([0-9]{2})(.*)&quot;, f)
  17. prefix = r.group(1)
  18. s = int(r.group(2)) #season
  19. e = int(r.group(3)) #episode
  20. suffix = r.group(4)
  21. if prefix not in summary.keys():
  22. summary[prefix] = { &#39;seasons&#39;: { f&quot;{s}&quot;: e }, &#39;prefix&#39;: prefix, &#39;suffix&#39;: suffix}
  23. else:
  24. if f&quot;{s}&quot; not in summary[prefix][&#39;seasons&#39;].keys():
  25. summary[prefix][&#39;seasons&#39;][f&quot;{s}&quot;] = e
  26. else:
  27. summary[prefix][&#39;seasons&#39;][f&quot;{s}&quot;] = max(summary[prefix][&#39;seasons&#39;][f&quot;{s}&quot;], e)
  28. print(json.dumps(summary, sort_keys=True, indent=4))
  29. for i in summary.keys():
  30. for season in summary[i][&#39;seasons&#39;].keys():
  31. for episode in range(1, summary[i][&#39;seasons&#39;][season]+1):
  32. s = &quot;{:02d}&quot;.format(int(season))
  33. e = &quot;{:02d}&quot;.format(episode)
  34. file2chk = f&quot;{summary[i][&#39;prefix&#39;]}S{s}E{e}{summary[i][&#39;suffix&#39;]}&quot;
  35. if not os.path.exists(file2chk):
  36. print(f&quot;missing {file2chk}&quot;)

first, you need to know the last episode of each season for each movie (first for), then check for everything starting from episode 01 (second for). Just make sure you have the last episode.

for a movie dir with:

  1. name.Joint.Economic.Area.S01E01.720p.NF.WEBRip.x264-GalaxyTV.mkv
  2. name.Joint.Economic.Area.S02E03.720p.NF.WEBRip.x264-GalaxyTV.mkv

it outputs:

  1. Processing movies/*.mkv..
  2. {
  3. &quot;movies/name.Joint.Economic.Area.&quot;: {
  4. &quot;prefix&quot;: &quot;movies/name.Joint.Economic.Area.&quot;,
  5. &quot;seasons&quot;: {
  6. &quot;1&quot;: 1,
  7. &quot;2&quot;: 3
  8. },
  9. &quot;suffix&quot;: &quot;.720p.NF.WEBRip.x264-GalaxyTV.mkv&quot;
  10. }
  11. }
  12. missing movies/name.Joint.Economic.Area.S02E01.720p.NF.WEBRip.x264-GalaxyTV.mkv
  13. missing movies/name.Joint.Economic.Area.S02E02.720p.NF.WEBRip.x264-GalaxyTV.mkv

huangapple
  • 本文由 发表于 2023年3月21日 02:51:15
  • 转载请务必保留本文链接:https://go.coder-hub.com/75794200-2.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定