Ajout de films et suppression des fichiers non présents

This commit is contained in:
redstorm45 2017-11-02 11:47:43 +01:00
parent 78ed1d0ee1
commit e4c105b5ec
2 changed files with 53 additions and 75 deletions

49
main.py
View file

@ -78,10 +78,10 @@ def visit_folder(domain, api, rules, tok):
Lapi.append(F) Lapi.append(F)
print('got api for ',domain['server']+domain['path'],':', len(Lapi)) 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) #print('loc titles:', '|'.join(sorted([f.title for f in Lloc])))
print('api titles:', '|'.join(sorted([f.title for f in Lapi]))) #print('\n'*2)
return #print('api titles:', '|'.join(sorted([f.title for f in Lapi])))
# supprime les dossiers de l'api # supprime les dossiers de l'api
Lapi = [f for f in Lapi if tok.conf.is_valid_file(f.name)] Lapi = [f for f in Lapi if tok.conf.is_valid_file(f.name)]
@ -138,12 +138,12 @@ def visit_folder(domain, api, rules, tok):
for f, _ in Llink2: for f, _ in Llink2:
Lunref.remove(f) Lunref.remove(f)
print('missing (', len(Lmissing), '):',[str(e.api_id)+':'+repr(e) for e in Lmissing]) print('missing (', len(Lmissing), '):',[str(e.api_id)+':'+repr(e) for e in sorted(Lmissing, key=lambda e:repr(e))])
print('\n'*3) print('\n'*3)
print('unreferenced:','|'.join(str(f) for f in Lunref)) print('unreferenced:','|'.join(str(f) for f in sorted(Lunref, key=lambda e:repr(e))))
print('\n'*3) print('\n'*3)
print('unreferenced titles:', '|'.join(sorted([f.title for f in Lunref]))) print('unreferenced titles:', '|'.join(sorted([f.title for f in Lunref])))
'''
# Put les renommages / déplacements # Put les renommages / déplacements
i = 0 i = 0
for filmApi, filmLoc in Lrelink: for filmApi, filmLoc in Lrelink:
@ -151,7 +151,7 @@ def visit_folder(domain, api, rules, tok):
print('['+str(i)+'/'+str(len(Lrelink))+']'+'relink:', filmApi.title) print('['+str(i)+'/'+str(len(Lrelink))+']'+'relink:', filmApi.title)
try: try:
api.debug_print = True api.debug_print = True
api.put_file(id=filmApi.api_id, path='ftp://'+conf.get_domain(domain)+filmLoc.path, name=filmLoc.name) api.put_file(id=filmApi.api_id, path=domain['server']+filmLoc.path, name=filmLoc.name)
api.debug_print = False api.debug_print = False
time.sleep(1) time.sleep(1)
except Exception as e: except Exception as e:
@ -166,7 +166,7 @@ def visit_folder(domain, api, rules, tok):
print('['+str(i)+'/'+str(len(Llink))+']'+'link:', film.title) print('['+str(i)+'/'+str(len(Llink))+']'+'link:', film.title)
try: try:
api.debug_print = True api.debug_print = True
api.post_file(path='ftp://'+conf.get_domain(domain)+film.path, name=film.name, type='Film', type_id=filmID, **film.additional_info()) api.post_file(path=domain['server']+film.path, name=film.name, type='Film', type_id=filmID, **film.additional_info())
api.debug_print = False api.debug_print = False
time.sleep(1) time.sleep(1)
except Exception as e: except Exception as e:
@ -181,7 +181,7 @@ def visit_folder(domain, api, rules, tok):
print('['+str(i)+'/'+str(len(Llink2))+']'+'link2:', film.title) print('['+str(i)+'/'+str(len(Llink2))+']'+'link2:', film.title)
try: try:
api.debug_print = True api.debug_print = True
api.post_file(path='ftp://'+conf.get_domain(domain)+film.path, name=film.name, type='Film', type_id=filmID, **film.additional_info()) api.post_file(path=domain['server']+film.path, name=film.name, type='Film', type_id=filmID, **film.additional_info())
api.debug_print = False api.debug_print = False
time.sleep(1) time.sleep(1)
except Exception as e: except Exception as e:
@ -190,23 +190,22 @@ def visit_folder(domain, api, rules, tok):
raise Exception('end') raise Exception('end')
# Poste tout les films locaux # Poste tout les films locaux
'''
"""
i = 0 i = 0
for film in Lunref: for film in Lunref:
i += 1 i += 1
print('['+str(i)+'/'+str(len(Lunref))+']'+'post:', film.title, str(film.year)) print('['+str(i)+'/'+str(len(Lunref))+']'+'post:', film.title, str(film.info.get('YEAR')))
try: try:
posted = False posted = False
if film.year is not None: if 'YEAR' in film.info:
resp = api.post_film(title=film.title, year=film.year) resp = api.post_film(title=film.title, year=film.info['YEAR'])
if "id" in resp: if "id" in resp:
resp = api.post_file(path='ftp://'+conf.get_domain(domain)+film.path, name=film.name, type='Film', type_id=resp["id"], **film.additional_info()) print('post: path=',domain['server']+film.path)
resp = api.post_file(path=domain['server']+film.path, name=film.name, type='film', type_id=resp["id"])
posted = True posted = True
if not posted: if not posted:
resp = api.post_film(title=film.title) resp = api.post_film(title=film.title)
if "id" in resp: if "id" in resp:
resp = api.post_file(path='ftp://'+conf.get_domain(domain)+film.path, name=film.name, type='Film', type_id=resp["id"], **film.additional_info()) resp = api.post_file(path=domain['server']+film.path, name=film.name, type='film', type_id=resp["id"])
print('response:', resp) print('response:', resp)
time.sleep(1) time.sleep(1)
@ -214,16 +213,18 @@ def visit_folder(domain, api, rules, tok):
print(e) print(e)
print('film '+film.title+' not posted') print('film '+film.title+' not posted')
raise Exception('end') raise Exception('end')
"""
''' # Supprime les fichiers qui n'existent plus
# Marque comme broken les films référencés non présents
# TODO: màj des broken_links
i = 0
for film in Lmissing: for film in Lmissing:
i += 1 i += 1
print('['+str(i)+'/'+len(Lmissing)+']'+'broken:', film) print('['+str(i)+'/'+str(len(Lmissing))+']'+'missing:', film)
try:
resp = api.delete_file(id=film.api_id)
except Exception as e:
print(e)
print('film '+film.title+' not posted')
raise Exception('end')
time.sleep(1) time.sleep(1)
'''
print('visit finished') print('visit finished')
def main(): def main():

View file

@ -49,6 +49,7 @@ class Piexel:
if code == 403: # FORBIDDEN if code == 403: # FORBIDDEN
raise InvalidToken(data['message']) raise InvalidToken(data['message'])
elif code == 400: elif code == 400:
print('error:', response.text)
raise ParameterError(data['message']) raise ParameterError(data['message'])
return data return data
@ -143,15 +144,39 @@ class Piexel:
:param params: paramètres à passer :param params: paramètres à passer
""" """
fields = self._get_request(['title', 'year'], ['title'], **params) fields = self._get_request(['title', 'year'], ['title'], **params)
return self._get_response('films', fields, 'post') return self._get_response('film', fields, 'post')
def post_file(self, **params): def post_file(self, **params):
""" """
Ajoute un fichier Ajoute un fichier
:param params: paramètres à passer :param params: paramètres à passer
""" """
fields = self._get_request(['path', 'name', 'type', 'type_id', 'quality', 'lang', 'subtitles'], ['path', 'name', 'type', 'type_id'], **params) fields = self._get_request(['path', 'name', 'type', 'type_id'], ['path', 'name', 'type', 'type_id'], **params)
return self._get_response('files', fields, 'post') return self._get_response('file', fields, 'post')
def post_file_language(self, file, **params):
"""
Ajoute une langue à un fichier
:param params: paramètres à passer
"""
fields = self._get_request(['value'], ['value'], **params)
return self._get_response('languages/'+str(file)+'/attach', fields, 'post')
def post_file_subtitle(self, file, **params):
"""
Ajoute une langue à un fichier
:param params: paramètres à passer
"""
fields = self._get_request(['value'], ['value'], **params)
return self._get_response('subtitle-languages/'+str(file)+'/attach', fields, 'post')
def post_file_qualities(self, file, **params):
"""
Ajoute une langue à un fichier
:param params: paramètres à passer
"""
fields = self._get_request(['value'], ['value'], **params)
return self._get_response('qualities/'+str(file)+'/attach', fields, 'post')
def post_subtitle(self, **params): def post_subtitle(self, **params):
""" """
@ -233,54 +258,6 @@ class Piexel:
fields = self._get_request(['id', 'treated'], ['id', 'treated'], **params) fields = self._get_request(['id', 'treated'], ['id', 'treated'], **params)
return self._get_response('broken', fields, 'put') return self._get_response('broken', fields, 'put')
def delete_film(self, **params):
"""
Supprime un film
:param params: paramètres à passer
"""
fields = self._get_request(['id'], ['id'], **params)
return self._get_response('films', fields, 'delete')
def delete_file(self, **params):
"""
Supprime un fichier
:param params: paramètres à passer
"""
fields = self._get_request(['id'], ['id'], **params)
return self._get_response('files', fields, 'delete')
def delete_subtitle(self, **params):
"""
Supprime un sous-titre
:param params: paramètres à passer
"""
fields = self._get_request(['id'], ['id'], **params)
return self._get_response('subtitles', fields, 'delete')
def delete_serie(self, **params):
"""
Supprime une série
:param params: paramètres à passer
"""
fields = self._get_request(['id'], ['id'], **params)
return self._get_response('series', fields, 'delete')
def delete_episode(self, **params):
"""
Supprime un épisode d'une série
:param params: paramètres à passer
"""
fields = self._get_request(['id'], ['id'], **params)
return self._get_response('episodes', fields, 'delete')
def delete_broken(self, **params):
"""
Supprime un lien mort
:param params: paramètres à passer
"""
fields = self._get_request(['id'], ['id'], **params)
return self._get_response('broken', fields, 'delete')
if __name__ == '__main__': if __name__ == '__main__':
piexel = Piexel('http://piexel.rez', 'app', 'token') piexel = Piexel('http://piexel.rez', 'app', 'token')