Tout modifié pour la nouvelle API
This commit is contained in:
parent
d1de6ffe09
commit
cb4ea4d419
5 changed files with 86 additions and 95 deletions
41
main.py
41
main.py
|
@ -42,7 +42,7 @@ def ftpwalk(directory, ftp):
|
|||
# mais retourne les résultats intermédiaires
|
||||
yield (current, Ldirs, Lfiles)
|
||||
|
||||
def visit_folder(domain, api, rules):
|
||||
def visit_folder(domain, api, rules, tok):
|
||||
# Connection au serveur
|
||||
print('connect to:', domain['server'])
|
||||
ftp = FTP(domain['server'][6:], user=domain['username'], passwd=domain['password'])
|
||||
|
@ -58,21 +58,33 @@ def visit_folder(domain, api, rules):
|
|||
for f in files:
|
||||
match = filerule.match_rules(path+'/'+f, rules)
|
||||
if match:
|
||||
print('got match:',match[1], 'name:',path+'/'+f)
|
||||
F = file.File(path+'/'+f, match[1])
|
||||
#print('got match:',match[1], 'name:',path+'/'+f)
|
||||
F = file.File(path, f, match[1])
|
||||
F.extract_title(tok)
|
||||
Lloc.append(F)
|
||||
ftp.close()
|
||||
print('total:',len(Lloc))
|
||||
exit(0)
|
||||
# Application des règles de chemins
|
||||
|
||||
# Récupère les fichiers de l'api
|
||||
Lapi = []
|
||||
for info in api.get_files(path='ftp://'+domain['server']+domain['path'], like=1):
|
||||
Lapi.append(file.File(info['path'][len('ftp://'+domain['server']):], info['name'], api_id=info['filable_id']))
|
||||
for info in api.get_files(path=domain['server']+domain['path'], like=1, filable=1):
|
||||
nfo = {}
|
||||
if not info['filable']:
|
||||
print('nfo:', info)
|
||||
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'])
|
||||
F.extract_title(tok)
|
||||
Lapi.append(F)
|
||||
|
||||
print('got api for ',domain['server']+domain['path'],':', len(Lapi))
|
||||
print('loc titles:', '|'.join(sorted([f.title for f in Lloc])))
|
||||
print('\n'*2)
|
||||
print('api titles:', '|'.join(sorted([f.title for f in Lapi])))
|
||||
return
|
||||
|
||||
# supprime les dossiers de l'api
|
||||
Lapi = [f for f in Lapi if conf.is_valid_file(f.name)]
|
||||
Lapi = [f for f in Lapi if tok.conf.is_valid_file(f.name)]
|
||||
|
||||
# Compare avec la liste de l'api
|
||||
Lmissing = [f for f in Lapi if f not in Lloc] # fichiers non présents localement
|
||||
|
@ -117,19 +129,20 @@ def visit_folder(domain, api, rules):
|
|||
Llink2 = []
|
||||
for film in Lunref:
|
||||
for title, fid in API_alltitles:
|
||||
if title==film.simple_name:
|
||||
if title==film.title:
|
||||
Llink2.append((film, fid))
|
||||
break
|
||||
#print(film, ' <-> ', [f for f in APIfilms if f['id']==fid][0]['title'])
|
||||
|
||||
print('easy ref:', sorted(Llink2, key=lambda f:str(f)))
|
||||
for f, _ in Llink2:
|
||||
Lunref.remove(f)
|
||||
|
||||
print('missing:',[str(e.api_id)+':'+repr(e) for e in Lmissing])
|
||||
print('missing (', len(Lmissing), '):',[str(e.api_id)+':'+repr(e) for e in Lmissing])
|
||||
print('\n'*3)
|
||||
print('unreferenced:','\n'.join(str(f) for f in Lunref))
|
||||
print('unreferenced:','|'.join(str(f) for f in Lunref))
|
||||
print('\n'*3)
|
||||
print('unreferenced titles:', '\n'.join(sorted([f.title for f in Lunref])))
|
||||
print('unreferenced titles:', '|'.join(sorted([f.title for f in Lunref])))
|
||||
'''
|
||||
# Put les renommages / déplacements
|
||||
i = 0
|
||||
|
@ -222,7 +235,7 @@ 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)
|
||||
visit_folder(fold, api, applicable, tokens)
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue