mirror of
https://github.com/KevinMidboe/transatlanticTorrentExpress.git
synced 2025-10-29 18:00:19 +00:00
Merge pull request #3 from KevinMidboe/fix/folderless-files
Fix: Error when transferring without a parent folder
This commit is contained in:
@@ -12,7 +12,7 @@ except Exception:
|
|||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
from logger import logger
|
from logger import logger
|
||||||
from utils import getConfig, readAvgSpeedFromDisk, writeAvgSpeedToDisk
|
from utils import getConfig, readAvgSpeedFromDisk, writeAvgSpeedToDisk, VIDEO_EXTENSIONS
|
||||||
|
|
||||||
ESTIMATED_TRANSFER_SPEED=readAvgSpeedFromDisk()
|
ESTIMATED_TRANSFER_SPEED=readAvgSpeedFromDisk()
|
||||||
TRANSFER_SPEED_UNIT="Mb/s"
|
TRANSFER_SPEED_UNIT="Mb/s"
|
||||||
@@ -118,8 +118,16 @@ def transferFiles(files, localPath, remotePath, host=None, user=None):
|
|||||||
file = os.path.join(remotePath, file)
|
file = os.path.join(remotePath, file)
|
||||||
spaceEscapedFile = file.replace(' ', '\\ ')
|
spaceEscapedFile = file.replace(' ', '\\ ')
|
||||||
|
|
||||||
|
# check if file is folder-less, if so create folder and update localPath
|
||||||
|
folderedLocalPath = None
|
||||||
|
filename, fileExtension = os.path.splitext(file)
|
||||||
|
if fileExtension in VIDEO_EXTENSIONS:
|
||||||
|
folderedLocalPath = os.path.join(localPath, filename)
|
||||||
|
os.makedirs(folderedLocalPath)
|
||||||
|
|
||||||
|
# Build rsync command
|
||||||
if host and user:
|
if host and user:
|
||||||
cmd = "rsync -rz {}@{}:'{}' '{}'".format(user, host, spaceEscapedFile, localPath)
|
cmd = "rsync -rz {}@{}:'{}' '{}'".format(user, host, spaceEscapedFile, folderedLocalPath or localPath)
|
||||||
else:
|
else:
|
||||||
cmd = "rsync -rz '{}' '{}'".format(spaceEscapedFile, localPath)
|
cmd = "rsync -rz '{}' '{}'".format(spaceEscapedFile, localPath)
|
||||||
|
|
||||||
|
|||||||
12
utils.py
12
utils.py
@@ -4,6 +4,14 @@ from configparser import RawConfigParser, NoOptionError
|
|||||||
|
|
||||||
pwd = os.path.dirname(os.path.abspath(__file__))
|
pwd = os.path.dirname(os.path.abspath(__file__))
|
||||||
|
|
||||||
|
VIDEO_EXTENSIONS = ('.3g2', '.3gp', '.3gp2', '.3gpp', '.60d', '.ajp', '.asf', '.asx', '.avchd', '.avi', '.bik',
|
||||||
|
'.bix', '.box', '.cam', '.dat', '.divx', '.dmf', '.dv', '.dvr-ms', '.evo', '.flc', '.fli',
|
||||||
|
'.flic', '.flv', '.flx', '.gvi', '.gvp', '.h264', '.m1v', '.m2p', '.m2v', '.m4e',
|
||||||
|
'.m4v', '.mjp', '.mjpeg', '.mjpg', '.mkv', '.moov', '.mov', '.movhd', '.movie', '.movx', '.mp4',
|
||||||
|
'.mpe', '.mpeg', '.mpg', '.mpv', '.mpv2', '.mxf', '.nsv', '.nut', '.ogg', '.ogm' '.ogv', '.omf',
|
||||||
|
'.ps', '.qt', '.ram', '.rm', '.rmvb', '.swf', '.ts', '.vfw', '.vid', '.video', '.viv', '.vivo',
|
||||||
|
'.vob', '.vro', '.wm', '.wmv', '.wmx', '.wrap', '.wvx', '.wx', '.x264', '.xvid')
|
||||||
|
|
||||||
class NoneOptionConfigParser(RawConfigParser):
|
class NoneOptionConfigParser(RawConfigParser):
|
||||||
def get(self, section, option):
|
def get(self, section, option):
|
||||||
try:
|
try:
|
||||||
@@ -30,7 +38,7 @@ def writeAvgSpeedToDisk(speed):
|
|||||||
path = os.path.join(pwd, '.avgspeed.txt')
|
path = os.path.join(pwd, '.avgspeed.txt')
|
||||||
|
|
||||||
with open(path, 'w') as f:
|
with open(path, 'w') as f:
|
||||||
f.write(str(int(speed)))
|
f.write(str(int(speed or 100)))
|
||||||
f.close()
|
f.close()
|
||||||
|
|
||||||
def readAvgSpeedFromDisk():
|
def readAvgSpeedFromDisk():
|
||||||
@@ -43,4 +51,4 @@ def readAvgSpeedFromDisk():
|
|||||||
if data == '':
|
if data == '':
|
||||||
data = '1'
|
data = '1'
|
||||||
|
|
||||||
return int(data)
|
return int(data)
|
||||||
|
|||||||
Reference in New Issue
Block a user