Use subprocess.run to call extract shell script
Signed-off-by: lzzy12 <jhashivam2020@gmail.com>
This commit is contained in:
parent
e77290528e
commit
b5a162f15d
|
|
@ -137,9 +137,11 @@ def is_magnet(url: str):
|
||||||
return True
|
return True
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
||||||
def is_mega_link(url: str):
|
def is_mega_link(url: str):
|
||||||
return "mega.nz" in url
|
return "mega.nz" in url
|
||||||
|
|
||||||
|
|
||||||
def new_thread(fn):
|
def new_thread(fn):
|
||||||
"""To use as decorator to make a function call threaded.
|
"""To use as decorator to make a function call threaded.
|
||||||
Needs import
|
Needs import
|
||||||
|
|
|
||||||
|
|
@ -1,2 +1,8 @@
|
||||||
class DirectDownloadLinkException(Exception):
|
class DirectDownloadLinkException(Exception):
|
||||||
|
"""Not method found for extracting direct download link from the http link"""
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
class NotSupportedExtractionArchive(Exception):
|
||||||
|
"""The archive format use is trying to extract is not supported"""
|
||||||
pass
|
pass
|
||||||
|
|
|
||||||
|
|
@ -5,6 +5,7 @@ import os
|
||||||
import pathlib
|
import pathlib
|
||||||
import magic
|
import magic
|
||||||
import tarfile
|
import tarfile
|
||||||
|
from .exceptions import NotSupportedExtractionArchive
|
||||||
|
|
||||||
|
|
||||||
def clean_download(path: str):
|
def clean_download(path: str):
|
||||||
|
|
@ -60,25 +61,25 @@ def get_base_name(orig_path: str):
|
||||||
if orig_path.endswith(".tar.bz2"):
|
if orig_path.endswith(".tar.bz2"):
|
||||||
return orig_path.replace(".tar.bz2", "")
|
return orig_path.replace(".tar.bz2", "")
|
||||||
elif orig_path.endswith(".tar.gz"):
|
elif orig_path.endswith(".tar.gz"):
|
||||||
return orig_path.replace(".tar.gz","")
|
return orig_path.replace(".tar.gz", "")
|
||||||
elif orig_path.endswith(".bz2"):
|
elif orig_path.endswith(".bz2"):
|
||||||
return orig_path.replace(".bz2","")
|
return orig_path.replace(".bz2", "")
|
||||||
elif orig_path.endswith(".gz"):
|
elif orig_path.endswith(".gz"):
|
||||||
return orig_path.replace(".gz","")
|
return orig_path.replace(".gz", "")
|
||||||
elif orig_path.endswith(".tar"):
|
elif orig_path.endswith(".tar"):
|
||||||
return orig_path.replace(".tar","")
|
return orig_path.replace(".tar", "")
|
||||||
elif orig_path.endswith(".tbz2"):
|
elif orig_path.endswith(".tbz2"):
|
||||||
return orig_path.replace("tbz2","")
|
return orig_path.replace("tbz2", "")
|
||||||
elif orig_path.endswith(".tgz"):
|
elif orig_path.endswith(".tgz"):
|
||||||
return orig_path.replace(".tgz","")
|
return orig_path.replace(".tgz", "")
|
||||||
elif orig_path.endswith(".zip"):
|
elif orig_path.endswith(".zip"):
|
||||||
return orig_path.replace(".zip","")
|
return orig_path.replace(".zip", "")
|
||||||
elif orig_path.endswith(".Z"):
|
elif orig_path.endswith(".Z"):
|
||||||
return orig_path.replace(".Z","")
|
return orig_path.replace(".Z", "")
|
||||||
elif orig_path.endswith(".rar"):
|
elif orig_path.endswith(".rar"):
|
||||||
return orig_path.replace(".rar","")
|
return orig_path.replace(".rar", "")
|
||||||
else:
|
else:
|
||||||
return "unsupported"
|
raise NotSupportedExtractionArchive('File format not supported for extraction')
|
||||||
|
|
||||||
|
|
||||||
def get_mime_type(file_path):
|
def get_mime_type(file_path):
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,7 @@ from bot import Interval, INDEX_URL
|
||||||
from bot import dispatcher, DOWNLOAD_DIR, DOWNLOAD_STATUS_UPDATE_INTERVAL, download_dict, download_dict_lock
|
from bot import dispatcher, DOWNLOAD_DIR, DOWNLOAD_STATUS_UPDATE_INTERVAL, download_dict, download_dict_lock
|
||||||
from bot.helper.ext_utils import fs_utils, bot_utils
|
from bot.helper.ext_utils import fs_utils, bot_utils
|
||||||
from bot.helper.ext_utils.bot_utils import setInterval
|
from bot.helper.ext_utils.bot_utils import setInterval
|
||||||
from bot.helper.ext_utils.exceptions import DirectDownloadLinkException
|
from bot.helper.ext_utils.exceptions import DirectDownloadLinkException, NotSupportedExtractionArchive
|
||||||
from bot.helper.mirror_utils.download_utils.aria2_download import AriaDownloadHelper
|
from bot.helper.mirror_utils.download_utils.aria2_download import AriaDownloadHelper
|
||||||
from bot.helper.mirror_utils.download_utils.mega_downloader import MegaDownloadHelper
|
from bot.helper.mirror_utils.download_utils.mega_downloader import MegaDownloadHelper
|
||||||
from bot.helper.mirror_utils.download_utils.direct_link_generator import direct_link_generator
|
from bot.helper.mirror_utils.download_utils.direct_link_generator import direct_link_generator
|
||||||
|
|
@ -20,6 +20,8 @@ from bot.helper.telegram_helper.filters import CustomFilters
|
||||||
from bot.helper.telegram_helper.message_utils import *
|
from bot.helper.telegram_helper.message_utils import *
|
||||||
import pathlib
|
import pathlib
|
||||||
import os
|
import os
|
||||||
|
import subprocess
|
||||||
|
import threading
|
||||||
|
|
||||||
ariaDlManager = AriaDownloadHelper()
|
ariaDlManager = AriaDownloadHelper()
|
||||||
ariaDlManager.start_listener()
|
ariaDlManager.start_listener()
|
||||||
|
|
@ -66,30 +68,29 @@ class MirrorListener(listeners.MirrorListeners):
|
||||||
return
|
return
|
||||||
elif self.extract:
|
elif self.extract:
|
||||||
download.is_extracting = True
|
download.is_extracting = True
|
||||||
|
try:
|
||||||
path = fs_utils.get_base_name(m_path)
|
path = fs_utils.get_base_name(m_path)
|
||||||
if path != "unsupported":
|
|
||||||
LOGGER.info(
|
LOGGER.info(
|
||||||
f"Extracting : {download_dict[self.uid].name()} "
|
f"Extracting : {name} "
|
||||||
)
|
)
|
||||||
download_dict[self.uid] = ExtractStatus(name, m_path, size)
|
with download_dict_lock:
|
||||||
os.system(f"extract '{m_path}'")
|
download_dict[self.uid] = ExtractStatus(name, m_path, size)
|
||||||
if not os.path.exists(path):
|
archive_result = subprocess.run(["extract", m_path])
|
||||||
self.onUploadError("Cannot extract file, check integrity of the file")
|
if archive_result.returncode == 0:
|
||||||
return
|
threading.Thread(target=os.remove, args=(m_path,)).start()
|
||||||
|
LOGGER.info(f"Deleting archive : {m_path}")
|
||||||
|
else:
|
||||||
|
LOGGER.warning('Unable to extract archive! Uploading anyway')
|
||||||
|
path = f'{DOWNLOAD_DIR}{self.uid}/{name}'
|
||||||
LOGGER.info(
|
LOGGER.info(
|
||||||
f'got path : {path}'
|
f'got path : {path}'
|
||||||
)
|
)
|
||||||
try:
|
|
||||||
os.remove(m_path)
|
except NotSupportedExtractionArchive:
|
||||||
LOGGER.info(f"Deleting archive : {m_path}")
|
|
||||||
except Exception as e:
|
|
||||||
LOGGER.error(str(e))
|
|
||||||
else:
|
|
||||||
LOGGER.info("Not any valid archive, uploading file as it is.")
|
LOGGER.info("Not any valid archive, uploading file as it is.")
|
||||||
path = f'{DOWNLOAD_DIR}{self.uid}/{download_dict[self.uid].name()}'
|
path = f'{DOWNLOAD_DIR}{self.uid}/{name}'
|
||||||
else:
|
else:
|
||||||
path = f'{DOWNLOAD_DIR}{self.uid}/{download_dict[self.uid].name()}'
|
path = f'{DOWNLOAD_DIR}{self.uid}/{name}'
|
||||||
up_name = pathlib.PurePath(path).name
|
up_name = pathlib.PurePath(path).name
|
||||||
LOGGER.info(f"Upload Name : {up_name}")
|
LOGGER.info(f"Upload Name : {up_name}")
|
||||||
drive = gdriveTools.GoogleDriveHelper(up_name, self)
|
drive = gdriveTools.GoogleDriveHelper(up_name, self)
|
||||||
|
|
|
||||||
6
extract
6
extract
|
|
@ -25,8 +25,10 @@ extract () {
|
||||||
*.rar)
|
*.rar)
|
||||||
a_dir=`expr "$arg" : '\(.*\).rar'` ;
|
a_dir=`expr "$arg" : '\(.*\).rar'` ;
|
||||||
mkdir "$a_dir" ;
|
mkdir "$a_dir" ;
|
||||||
7z x "$arg" -o"$a_dir" ;;
|
7z x "$arg" -o"$a_dir" ;;
|
||||||
*) echo "'$arg' cannot be extracted via extract()" ;;
|
*) echo "'$arg' cannot be extracted via extract()" 1>&2
|
||||||
|
exit 1 ;;
|
||||||
|
|
||||||
esac
|
esac
|
||||||
cd - || exit
|
cd - || exit
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue