Séparation des fichiers films et épisodes
This commit is contained in:
parent
68ba13ca0f
commit
3788f4147a
2 changed files with 35 additions and 8 deletions
12
file.py
12
file.py
|
@ -6,13 +6,14 @@ class File:
|
|||
"""
|
||||
Décrit une référence de fichier dans le disque
|
||||
"""
|
||||
def __init__(self, path, name, info, api_id=None, api_fileid=None):
|
||||
def __init__(self, path, name, info, api_id=None, api_fileid=None, api_fileable_type=None):
|
||||
self.path = path
|
||||
self.name = name
|
||||
self.info = info
|
||||
self.markers = {}
|
||||
self.api_id = api_id
|
||||
self.api_fileid = api_fileid
|
||||
self.fileable_type = {None: None, 'App//Film':'film', 'App//Episode':'episode'}[api_fileable_type]
|
||||
|
||||
def get_ext(self):
|
||||
_, ext = posixpath.splitext(self.name)
|
||||
|
@ -60,12 +61,19 @@ class File:
|
|||
while ' ' in fname:
|
||||
fname = fname.replace(' ', ' ')
|
||||
self.title = fname
|
||||
# 7) type: épisode / film
|
||||
if not self.fileable_type:
|
||||
for m in ['SERIE', 'EPISODE_NUM', 'SEASON_NUM']:
|
||||
if m in self.markers:
|
||||
self.fileable_type = 'episode'
|
||||
if not self.fileable_type and 'TITLE' in self.markers:
|
||||
self.fileable_type = 'film'
|
||||
|
||||
def filename_same(self, other):
|
||||
# Compare les noms de fichiers de self et de other
|
||||
# En supprimant les espaces, la date, et les marques de qualitée
|
||||
return self.name == other.name
|
||||
|
||||
|
||||
def __eq__(self, other):
|
||||
return (self.path, self.name) == (other.path, other.name)
|
||||
|
||||
|
|
31
main.py
31
main.py
|
@ -68,21 +68,37 @@ def visit_folder(domain, api, rules, tok):
|
|||
F.extract_title(tok)
|
||||
Lloc.append(F)
|
||||
ftp.close()
|
||||
print('total:',len(Lloc))
|
||||
print('total loc for ',domain['server']+domain['path'],':', len(Lloc))
|
||||
# Récupère les fichiers de l'api
|
||||
Lapi = []
|
||||
for info in api.get_files(path=domain['server']+domain['path'], like=1, filable=1):
|
||||
nfo = {}
|
||||
if not info['filable']:
|
||||
print('nfo:', info)
|
||||
print('nfo:', info) # le fileable associé a été supprimé
|
||||
else:
|
||||
year = int(info['filable']['release_date'][:4])
|
||||
nfo['YEAR'] = year
|
||||
F = file.File(info['path'][len(domain['server']):], info['name'], nfo, api_id=info['filable_id'], api_fileid=info['id'])
|
||||
F = file.File(info['path'][len(domain['server']):], info['name'], nfo, api_id=info['filable_id'], api_fileid=info['id'], api_fileable_type=info['fileable_type'])
|
||||
F.extract_title(tok)
|
||||
Lapi.append(F)
|
||||
print('total api for ',domain['server']+domain['path'],':', len(Lapi))
|
||||
|
||||
# traite les films
|
||||
Lfilm_loc = [f for f in Lloc if f.fileable_type == 'film']
|
||||
Lfilm_api = [f for f in Lapi if f.fileable_type == 'film']
|
||||
handle_films(Lfilm_loc, Lfilm_api, api, rules, tok)
|
||||
|
||||
# traite les épisodes
|
||||
Lepisode_loc = [f for f in Lloc if f.fileable_type == 'episode']
|
||||
Lepisode_api = [f for f in Lapi if f.fileable_type == 'episode']
|
||||
handle_episodes(Lepisode_loc, Lepisode_api, api, rules, tok)
|
||||
|
||||
print('visit finished ',domain['server']+domain['path'])
|
||||
|
||||
def handle_films(Lfilm_loc, Lfilm_api, api, rules, tok):
|
||||
Lloc = Lfilm_loc
|
||||
Lapi = Lfilm_api
|
||||
|
||||
print('got api for ',domain['server']+domain['path'],':', len(Lapi))
|
||||
#print('loc titles:', '|'.join(sorted([f.title for f in Lloc])))
|
||||
#print('loc titles:', '|'.join(sorted([f.title for f in Lloc])))
|
||||
#print('\n'*2)
|
||||
|
@ -256,7 +272,11 @@ def visit_folder(domain, api, rules, tok):
|
|||
|
||||
# TODO: traiter les films non postés
|
||||
|
||||
print('visit finished')
|
||||
def handle_episodes(Lepisode_loc, Lepisode_api, api, rules, tok):
|
||||
Lloc = Lepisode_loc
|
||||
Lapi = Lepisode_api
|
||||
|
||||
# supprime les fichiers invalides
|
||||
|
||||
def post_markers(api, file_, fileid):
|
||||
for lang in file_.markers['lang']:
|
||||
|
@ -279,7 +299,6 @@ def main():
|
|||
for fold in folders:
|
||||
applicable = [filerule.FileRule(re.escape(fold['path'])+'\\/'+r['regex'], conf) for r in rules if int(r['indexer_folder_id']) == fold['id']]
|
||||
visit_folder(fold, api, applicable, tokens)
|
||||
return
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue