Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix problème encodage UTF8 et recherche des trailers vf #5

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 12 additions & 8 deletions couchpotato/core/helpers/encoding.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,16 +36,20 @@ def toUnicode(original, *args):
return six.text_type(original, *args)
except:
try:
detected = detect(original)
from couchpotato.environment import Env
return original.decode(Env.get("encoding"))
except:
try:
if detected.get('confidence') > 0.8:
return original.decode(detected.get('encoding'))
detected = detect(original)
try:
if detected.get('confidence') > 0.8:
return original.decode(detected.get('encoding'))
except:
pass

return ek(original, *args)
except:
pass

return ek(original, *args)
except:
raise
raise
except:
log.error('Unable to decode value "%s..." : %s ', (repr(original)[:20], traceback.format_exc()))
return 'ERROR DECODING STRING'
Expand Down
19 changes: 11 additions & 8 deletions couchpotato/core/helpers/variable.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import sys
import traceback

from couchpotato.core.helpers.encoding import simplifyString, toSafeString, ss, sp
from couchpotato.core.helpers.encoding import simplifyString, toSafeString, ss, sp, toUnicode
from couchpotato.core.logger import CPLog
import six
from six.moves import map, zip, filter
Expand All @@ -25,17 +25,17 @@ def fnEscape(pattern):
def link(src, dst):
if os.name == 'nt':
import ctypes
if ctypes.windll.kernel32.CreateHardLinkW(six.text_type(dst), six.text_type(src), 0) == 0: raise ctypes.WinError()
if ctypes.windll.kernel32.CreateHardLinkW(toUnicode(dst), toUnicode(src), 0) == 0: raise ctypes.WinError()
else:
os.link(src, dst)
os.link(toUnicode(src), toUnicode(dst))


def symlink(src, dst):
if os.name == 'nt':
import ctypes
if ctypes.windll.kernel32.CreateSymbolicLinkW(six.text_type(dst), six.text_type(src), 1 if os.path.isdir(src) else 0) in [0, 1280]: raise ctypes.WinError()
if ctypes.windll.kernel32.CreateSymbolicLinkW(toUnicode(dst), toUnicode(src), 1 if os.path.isdir(src) else 0) in [0, 1280]: raise ctypes.WinError()
else:
os.symlink(src, dst)
os.link(toUnicode(src), toUnicode(dst))


def getUserDir():
Expand Down Expand Up @@ -142,17 +142,14 @@ def getExt(filename):

def cleanHost(host, protocol = True, ssl = False, username = None, password = None):
"""Return a cleaned up host with given url options set

Changes protocol to https if ssl is set to True and http if ssl is set to false.
>>> cleanHost("localhost:80", ssl=True)
'https://localhost:80/'
>>> cleanHost("localhost:80", ssl=False)
'http://localhost:80/'

Username and password is managed with the username and password variables
>>> cleanHost("localhost:80", username="user", password="passwd")
'http://user:passwd@localhost:80/'

Output without scheme (protocol) can be forced with protocol=False
>>> cleanHost("localhost:80", protocol=False)
'localhost:80'
Expand Down Expand Up @@ -411,3 +408,9 @@ def find(func, iterable):
return item

return None


def compareVersions(version1, version2):
def normalize(v):
return [int(x) for x in re.sub(r'(\.0+)*$','', v).split(".")]
return cmp(normalize(version1), normalize(version2))
14 changes: 7 additions & 7 deletions couchpotato/core/media/_base/providers/torrent/t411.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@
class Base(TorrentProvider):

urls = {
'test': 'http://www.t411.in/',
'detail': 'http://www.t411.in/torrents/?id=%s',
'search': 'http://www.t411.in/torrents/search/?',
'test': 'http://www.t411.ch/',
'detail': 'http://www.t411.ch/torrents/?id=%s',
'search': 'http://www.t411.ch/torrents/search/?',
}

http_time_between_calls = 1 #seconds
Expand Down Expand Up @@ -120,8 +120,8 @@ def _search(self, movie, quality, results):
testname=namer_check.correctName(name,movie)
if testname==0:
continue
url = ('http://www.t411.in/torrents/download/?id=%s' % idt)
detail_url = ('http://www.t411.in/torrents/?id=%s' % idt)
url = ('http://www.t411.ch/torrents/download/?id=%s' % idt)
detail_url = ('http://www.t411.ch/torrents/?id=%s' % idt)
leecher = result.findAll('td')[8].text
size = result.findAll('td')[5].text
age = result.findAll('td')[4].text
Expand Down Expand Up @@ -185,7 +185,7 @@ def login(self):
]

try:
response = self.opener.open('http://www.t411.in/users/login/', self.getLoginParams())
response = self.opener.open('http://www.t411.ch/users/login/', self.getLoginParams())
except urllib2.URLError as e:
log.error('Login to T411 failed: %s' % e)
return False
Expand Down Expand Up @@ -234,7 +234,7 @@ def download(self, url = '', nzb_id = ''):
'tab': 'searcher',
'list': 'torrent_providers',
'name': 't411',
'description': 'See <a href="https://www.t411.in/">T411</a>',
'description': 'See <a href="https://www.t411.ch/">T411</a>',
'icon' : 'iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAIAAACQkWg2AAAAA3NCSVQICAjb4U/gAAACdklEQVQokW2RX0hTcRTHz+/+cbvz3m1srbv8M6Ws6SbK1hRTkUoKIui5jIJ8sz9vQQTRQxDRexCkIGgmSC+B1YNWNCIrRQ3Z2PyTf5pb2/S2ud2/2723hyIt/b4cDud7+H4OB2CXrpOW+wYLYPju0R66DTABEAWYB7i6lwHtbEYAKi5crPE36Wa6QGKQyYylk1cePPwX4FqPquSSiZVHAN+Gh/JihpezUpGXinmxkBN5Lvjm5U4/1hzwS5JsJIkzkWnmZDtSZF2WQZZ0SSoIgiSJXq+37VjLNhLL7h/ofUzg0Dceutl1ejHOoa0fScUQW1rouXQWw3ANULXbt8cNJ7pudPrcd/pmLp8PBNpa344HDYTqYc2Ls58G+59sI/0uTgBTKj78OQIdTb6W5gKg+PpKaPprUoLB/mBHY/v/CacARru7ucaG6NCrj5vp2rpDWvmBDa83PzDwdJVOl5Zo8S+JQhoD7E/CGMBEKLyYTNWjLKNl6KkP5OsXbE1leGqdNFoBd3K034jbcJzYfqfPTpUZjOHkmkmS+SpzinXYlxdGM+4I5ezkoyHSUcIjHXHY3wWPqM9SOg2ataFMlvQ6YWs5FIvaKxxgmzEfrWYOazanXuAxAGBwGALoNcWePxtx8cKR4wGuBFZo05TI2gXViE3SaiyVn3bQRgU0DABuVdHn7na6iuSMAOk2X6WnrqLcMVlqTVQ5lHw2VaQURtNN+7YoD7L4cQCQKGo9GJsUEGC6bNPfzc1xpZAjWuH7+3u+xHy+BuFLLkYsx7la0yrCAeqdZg0h1kDQFkpVlSyvrG1krM5mNbtK/9wM0wddjF6UNywElpWVX6HUDxDMdBkmAAAAAElFTkSuQmCC',
'wizard': True,
'options': [
Expand Down
8 changes: 4 additions & 4 deletions couchpotato/core/media/movie/providers/metadata/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import traceback

from couchpotato.core.event import addEvent, fireEvent
from couchpotato.core.helpers.encoding import sp
from couchpotato.core.helpers.encoding import sp, toUnicode
from couchpotato.core.helpers.variable import getIdentifier, underscoreToCamel
from couchpotato.core.logger import CPLog
from couchpotato.core.media._base.providers.metadata.base import MetaDataBase
Expand Down Expand Up @@ -32,9 +32,9 @@ def create(self, message = None, group = None):
except:
log.error('Failed to update movie, before creating metadata: %s', traceback.format_exc())

root_name = self.getRootName(group)
meta_name = os.path.basename(root_name)
root = os.path.dirname(root_name)
root_name = toUnicode(self.getRootName(group))
meta_name = toUnicode(os.path.basename(root_name))
root = toUnicode(os.path.dirname(root_name))

movie_info = group['media'].get('info')

Expand Down
2 changes: 1 addition & 1 deletion couchpotato/core/plugins/renamer.py
Original file line number Diff line number Diff line change
Expand Up @@ -650,7 +650,7 @@ def scan(self, base_folder = None, release_download = None, to_folder = None):
group_folder = media_folder
else:
# Delete the first empty subfolder in the tree relative to the 'from' folder
group_folder = sp(os.path.join(base_folder, os.path.relpath(group['parentdir'], base_folder).split(os.path.sep)[0]))
group_folder = sp(os.path.join(base_folder, toUnicode(os.path.relpath(group['parentdir'], base_folder)).split(os.path.sep)[0]))

try:
if self.conf('cleanup') or self.conf('move_leftover'):
Expand Down
2 changes: 1 addition & 1 deletion couchpotato/core/plugins/scanner.py
Original file line number Diff line number Diff line change
Expand Up @@ -569,7 +569,7 @@ def getSubtitleLanguage(self, group):
scan_result = []
for p in paths:
if not group['is_dvd']:
video = Video.from_path(sp(p))
video = Video.from_path(toUnicode(sp(p)))
video_result = [(video, video.scan())]
scan_result.extend(video_result)

Expand Down
56 changes: 40 additions & 16 deletions couchpotato/core/plugins/trailer.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,30 +20,47 @@ def searchSingle(self, message = None, group = None):
if not group: group = {}
if self.isDisabled() or len(group['files']['trailer']) > 0: return

trailers = fireEvent('trailer.search', group = group, merge = True)
if self.conf('usevf'):
try:
filename = self.conf('name').replace('<filename>', group['filename'].decode('latin-1'))
except:
filename = self.conf('name').replace('<filename>', group['filename'])
try:
destination = os.path.join(group['destination_dir'].decode('latin-1'), filename)
except:
destination = os.path.join(group['destination_dir'], filename)
trailers = fireEvent('vftrailer.search', group = group, filename=filename, destination=destination, merge = True)
else :
trailers = fireEvent('trailer.search', group = group, merge = True)
if not trailers or trailers == []:
log.info('No trailers found for: %s', getTitle(group))
return False

for trailer in trailers.get(self.conf('quality'), []):
if self.conf('usevf'):
log.info('Trailers found in VF for: %s', getTitle(group))
return True
else:

ext = getExt(trailer)
filename = self.conf('name').replace('<filename>', group['filename']) + ('.%s' % ('mp4' if len(ext) > 5 else ext))
destination = os.path.join(group['destination_dir'], filename)
if not os.path.isfile(destination):
trailer_file = fireEvent('file.download', url = trailer, dest = destination, urlopen_kwargs = {'headers': {'User-Agent': 'Quicktime'}}, single = True)
if trailer_file and os.path.getsize(trailer_file) < (1024 * 1024): # Don't trust small trailers (1MB), try next one
os.unlink(trailer_file)
continue
else:
log.debug('Trailer already exists: %s', destination)
for trailer in trailers.get(self.conf('quality'), []):

group['renamed_files'].append(destination)
ext = getExt(trailer)
filename = self.conf('name').replace('<filename>', group['filename']) + ('.%s' % ('mp4' if len(ext) > 5 else ext))
destination = os.path.join(group['destination_dir'], filename)
if not os.path.isfile(destination):
trailer_file = fireEvent('file.download', url = trailer, dest = destination, urlopen_kwargs = {'headers': {'User-Agent': 'Quicktime'}}, single = True)
if os.path.getsize(trailer_file) < (1024 * 1024): # Don't trust small trailers (1MB), try next one
os.unlink(trailer_file)
continue
else:
log.debug('Trailer already exists: %s', destination)

# Download first and break
break
group['renamed_files'].append(destination)

# Download first and break
break

return True

return True


config = [{
Expand All @@ -61,6 +78,13 @@ def searchSingle(self, message = None, group = None):
'default': False,
'type': 'enabler',
},
{
'name': 'usevf',
'label' : 'Search french Trailers (beta)',
'default': False,
'advanced': True,
'type': 'bool',
},
{
'name': 'quality',
'default': '720p',
Expand Down