英文:
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.
import os
with os.scandir(path) as files:
for file in files:
...
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:
import os
with os.scandir(path) as files:
for file in files:
num = 01
if any(str(num) in file.name):
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
import os
with os.scandir(path) as files:
for file in files:
...
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:
import os
with os.scandir(path) as files:
for file in files:
num = 01
if any(str(num) in file.name):
print("yes")
but i got an error.
答案1
得分: 0
以下是您要翻译的代码部分:
#!/usr/bin/env python3
import glob
import os,sys
import re
import json
try:
movie_path_orig = sys.argv[1]
except:
print(f"使用 ./{sys.argv[0]} <电影路径>")
sys.exit(0)
movie_path = os.path.join(movie_path_orig, "*.mkv")
print(f"处理 {movie_path}..")
files = glob.glob(movie_path)
summary = {}
for f in files:
r=re.search("^(.*)S([0-9]{2})E([0-9]{2})(.*)", f)
prefix = r.group(1)
s = int(r.group(2)) # 季节
e = int(r.group(3)) # 集数
suffix = r.group(4)
if prefix not in summary.keys():
summary[prefix] = { 'seasons': { f"{s}": e }, 'prefix': prefix, 'suffix': suffix}
else:
if f"{s}" not in summary[prefix]['seasons'].keys():
summary[prefix]['seasons'][f"{s}"] = e
else:
summary[prefix]['seasons'][f"{s}"] = max(summary[prefix]['seasons'][f"{s}"], e)
print(json.dumps(summary, sort_keys=True, indent=4))
for i in summary.keys():
for season in summary[i]['seasons'].keys():
for episode in range(1, summary[i]['seasons'][season]+1):
s = "{:02d}".format(int(season))
e = "{:02d}".format(episode)
file2chk = f"{summary[i]['prefix']}S{s}E{e}{summary[i]['suffix']}"
if not os.path.exists(file2chk):
print(f"缺失 {file2chk}")
英文:
maybe this can help:
#!/usr/bin/env python3
import glob
import os,sys
import re
import json
try:
movie_path_orig = sys.argv[1]
except:
print(f"use ./{sys.argv[0]} <movie path>")
sys.exit(0)
movie_path = os.path.join(movie_path_orig, "*.mkv")
print(f"Processing {movie_path}..")
files = glob.glob(movie_path)
summary = {}
for f in files:
r=re.search("^(.*)S([0-9]{2})E([0-9]{2})(.*)", f)
prefix = r.group(1)
s = int(r.group(2)) #season
e = int(r.group(3)) #episode
suffix = r.group(4)
if prefix not in summary.keys():
summary[prefix] = { 'seasons': { f"{s}": e }, 'prefix': prefix, 'suffix': suffix}
else:
if f"{s}" not in summary[prefix]['seasons'].keys():
summary[prefix]['seasons'][f"{s}"] = e
else:
summary[prefix]['seasons'][f"{s}"] = max(summary[prefix]['seasons'][f"{s}"], e)
print(json.dumps(summary, sort_keys=True, indent=4))
for i in summary.keys():
for season in summary[i]['seasons'].keys():
for episode in range(1, summary[i]['seasons'][season]+1):
s = "{:02d}".format(int(season))
e = "{:02d}".format(episode)
file2chk = f"{summary[i]['prefix']}S{s}E{e}{summary[i]['suffix']}"
if not os.path.exists(file2chk):
print(f"missing {file2chk}")
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:
name.Joint.Economic.Area.S01E01.720p.NF.WEBRip.x264-GalaxyTV.mkv
name.Joint.Economic.Area.S02E03.720p.NF.WEBRip.x264-GalaxyTV.mkv
it outputs:
Processing movies/*.mkv..
{
"movies/name.Joint.Economic.Area.": {
"prefix": "movies/name.Joint.Economic.Area.",
"seasons": {
"1": 1,
"2": 3
},
"suffix": ".720p.NF.WEBRip.x264-GalaxyTV.mkv"
}
}
missing movies/name.Joint.Economic.Area.S02E01.720p.NF.WEBRip.x264-GalaxyTV.mkv
missing movies/name.Joint.Economic.Area.S02E02.720p.NF.WEBRip.x264-GalaxyTV.mkv
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论