----------------------------------- Original Post ------------------------------------------------
Hey Folks,
I am currently working on a Queue-Script which shall extract videos from .rar files while there are still parts remaining in the queue.
I already tested this by creating a multipart-rar-archive with some .mkv in it. It seems that WinRAR is "able" to update/append to extracted files, but does so by completely replacing the file.
Now I came along with a workaround, which would call WinRAR/Unrar every time a .rar file is downloaded and extract all data into a temp file, read the byte length from the existing file, substract that from the temp file and append the remaining data to the existing one. This way, it is possible to open the video in VLC (for example), when only one file of a multipart-rar-archive has been downloaded while continously adding data to the file/stream, so that you can watch a video while downloading it.
My problem with putting this nice behaviour in a Queue-Script is that I need the file name of the .rar as well as the number in the queue, to be able to tell wether it is the first file (or the last) and pass the right file to WinRAR/Unrar. Can anyone help me to get that information (maybe add it to os.environ, @hugbug? )?
I'm currently testing this on Windows, but could imagine a version for OSMC, etc. as well.
Here's what I have so far (work in progress, dont hate ):
Code: Select all
##############################################################################
### NZBGET QUEUE SCRIPT ###
### QUEUE EVENTS: FILE_DOWNLOADED
# Stream video while downloading.
#
# This script partially extracts video from .rar files
# so that you can view them while downloading.
#
# NOTE: This script requires Python to be installed on your system.
### NZBGET QUEUE SCRIPT ###
##############################################################################
import sys, os
UNRAR_PATH = "C:\\Program Files\\WinRAR\\UnRAR.exe"
def appendFile(source, destination):
with open(source, "rb") as s, open(destination, "a+b") as d:
s.seek(os.path.getsize(destination))
chunk = "."
while chunk != "":
chunk = s.read(1024)
d.write(chunk)
appendFile("PATH_TO_TEMP_FILE", "PATH_TO_EXISTING_FILE");