New handling method

This commit is contained in:
redstorm 2017-05-27 18:03:47 +02:00
parent defcc3d618
commit b305f63b46
7 changed files with 172 additions and 122 deletions

54
file.py
View file

@ -1,3 +1,4 @@
#coding:utf-8
import posixpath
class File:
@ -7,12 +8,14 @@ class File:
def __init__(self, path, name,api_id=None):
self.path = path
self.name = name
self.fullname = path+name
'''
self.info_lang = []
self.info_quality = []
self.info_subtitles = []
self.year = self._find_year()
self.title = self._get_title()
self.title = ''
self.simple_name = self.title.replace(' ', '')
'''
self.api_id = api_id
def get_ext(self):
@ -23,36 +26,15 @@ class File:
_, ext = posixpath.splitext(self.name)
return ext
def _get_title(self):
fname, ext = posixpath.splitext(self.name)
def _extract_title(self, title, tok):
# extrait un titre de film depuis la variable #TITLE#
fname, ext = posixpath.splitext(title)
# 1) séparateurs
fname = fname.replace('.', ' ')
fname = fname.replace('_', ' ')
fname = fname.replace('-', ' ')
# 2.1) marqueurs de qualitée
for m in ['HDRiP', 'HDRip', 'HDTS', 'HD', 'DVDRIP', 'DvDRIP', '720p', '1080p', 'DVDSCR', 'BluRay', 'BrRip', 'BRRip']:
if m in fname:
self.info_quality.append(m)
fname = fname.replace(m, '')
# 2.2) marqueur de sous-titres
for m in ['SRT FR', 'STFR', 'STEN']:
if m in fname:
self.info_subtitles.append(m)
fname = fname.replace(m, '')
# 2.3) marqueurs de langues & sous-titres
for m in ['VOSTFR', 'VOST-FR', 'VOSTMulti']:
if m in fname:
self.info_lang.append(m)
self.info_subtitles.append(m)
fname = fname.replace(m, '')
# 2.4) marqueurs de langues
for m in ['VO', 'VF','FRENCH', 'FR', 'ENG', '[Eng]', 'VJAP']:
if m in fname:
self.info_lang.append(m)
fname = fname.replace(m, '')
# 2.5) marqueurs autres
for m in ['UNCENSORED', 'X264', 'x264', 'X265', '[www Cpasbien com]', '[www newpct1 com]', 'YIFY', 'JYK']:
fname = fname.replace(m, '')
# 2) marqueurs
fname, info = tok.tokenize(fname)
# 3) minuscule
fname = fname.lower()
# 4) année
@ -61,20 +43,12 @@ class File:
fname = fname.replace('[ '+str(self.year)+' ]', '')
fname = fname.replace('['+str(self.year)+' ]', '')
fname = fname.replace('[ '+str(self.year)+']', '')
# 5) espaces en bout et centraux
# 5) espaces en bout, centraux et rajoutés
fname = fname.lstrip().rstrip()
while ' ' in fname:
fname = fname.replace(' ', ' ')
return fname
def _find_year(self):
fname, ext = posixpath.splitext(self.name)
fname = fname.replace(' ', '')
for i in range(1800, 2100):
if '['+str(i)+']' in fname:
return i
return None
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
@ -89,7 +63,7 @@ class File:
for m in ['VOSTFR', 'VOST-FR', 'VOSTMulti', 'VO']:
if m in self.info_lang:
info['lang'] = 'VO'
for m in ['ENG', '[Eng]']:
for m in ['ENG', '[Eng]', 'VEN']:
pass # notation?
for m in ['VJAP']:
pass # notation?
@ -97,10 +71,10 @@ class File:
if m in self.info_lang:
info['lang'] = 'FR'
if len(self.info_quality) > 0:
for m in ['HDRiP', 'HDTS', 'HD', '720p', 'BluRay']:
for m in ['HDRiP', 'HDRip', 'HDrip', 'HDTS', 'HD', '720p', 'BluRay']:
if m in self.info_quality:
info['quality'] = 'HD'
for m in ['DVDRIP', 'DVDSCR']:
for m in ['DVDRIP', 'DvDrip', 'DvDRIP', 'DVDrip', 'DVDSCR']:
pass # qualité?
for m in ['1080p']:
if m in self.info_quality: