mirror of
https://github.com/Arrowar/StreamingCommunity.git
synced 2025-06-07 12:05:35 +00:00
Fix tor dont save file, fix update version to latest commit.
This commit is contained in:
parent
49e1dd2c3a
commit
9d74ae2a2d
@ -31,7 +31,6 @@ REQUEST_TIMEOUT = config_manager.get_float('REQUESTS', 'timeout')
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class TOR_downloader:
|
class TOR_downloader:
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
"""
|
"""
|
||||||
@ -89,7 +88,6 @@ class TOR_downloader:
|
|||||||
except Exception as e:
|
except Exception as e:
|
||||||
logging.error(f"Failed to add magnet link: {str(e)}")
|
logging.error(f"Failed to add magnet link: {str(e)}")
|
||||||
|
|
||||||
|
|
||||||
def start_download(self):
|
def start_download(self):
|
||||||
"""
|
"""
|
||||||
Starts downloading the latest added torrent and monitors progress.
|
Starts downloading the latest added torrent and monitors progress.
|
||||||
@ -190,14 +188,16 @@ class TOR_downloader:
|
|||||||
Moves downloaded files of the latest torrent to another location.
|
Moves downloaded files of the latest torrent to another location.
|
||||||
|
|
||||||
Parameters:
|
Parameters:
|
||||||
- save_path (str): Current save path (output directory) of the torrent.
|
- save_path (str): Current save path (output directory) of the torrent.
|
||||||
- destination (str, optional): Destination directory to move files. If None, moves to current directory.
|
- destination (str, optional): Destination directory to move files. If None, moves to current directory.
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
- bool: True if files are moved successfully, False otherwise.
|
- bool: True if files are moved successfully, False otherwise.
|
||||||
"""
|
"""
|
||||||
time.sleep(2)
|
|
||||||
|
|
||||||
|
video_extensions = {'.mp4', '.mkv', 'avi'}
|
||||||
|
time.sleep(2)
|
||||||
|
|
||||||
# List directories in the save path
|
# List directories in the save path
|
||||||
dirs = [d for d in os.listdir(self.save_path) if os.path.isdir(os.path.join(self.save_path, d))]
|
dirs = [d for d in os.listdir(self.save_path) if os.path.isdir(os.path.join(self.save_path, d))]
|
||||||
|
|
||||||
@ -205,9 +205,18 @@ class TOR_downloader:
|
|||||||
if self.torrent_name.split(" ")[0] in dir_name:
|
if self.torrent_name.split(" ")[0] in dir_name:
|
||||||
dir_path = os.path.join(self.save_path, dir_name)
|
dir_path = os.path.join(self.save_path, dir_name)
|
||||||
|
|
||||||
shutil.move(dir_path, destination)
|
# Ensure destination is set; if not, use current directory
|
||||||
logging.info(f"Moved directory {dir_name} to {destination}")
|
destination = destination or os.getcwd()
|
||||||
break
|
|
||||||
|
# Move only video files
|
||||||
|
for file_name in os.listdir(dir_path):
|
||||||
|
file_path = os.path.join(dir_path, file_name)
|
||||||
|
|
||||||
|
# Check if it's a file and if it has a video extension
|
||||||
|
if os.path.isfile(file_path) and os.path.splitext(file_name)[1] in video_extensions:
|
||||||
|
shutil.move(file_path, os.path.join(destination, file_name))
|
||||||
|
logging.info(f"Moved file {file_name} to {destination}")
|
||||||
|
|
||||||
|
time.sleep(2)
|
||||||
self.qb.delete_permanently(self.qb.torrents()[-1]['hash'])
|
self.qb.delete_permanently(self.qb.torrents()[-1]['hash'])
|
||||||
return True
|
return True
|
||||||
|
@ -18,13 +18,13 @@ local_path = os.path.join(".")
|
|||||||
from Src.Upload.version import __author__, __title__
|
from Src.Upload.version import __author__, __title__
|
||||||
|
|
||||||
|
|
||||||
def move_content(source: str, destination: str) :
|
def move_content(source: str, destination: str):
|
||||||
"""
|
"""
|
||||||
Move all content from the source folder to the destination folder.
|
Move all content from the source folder to the destination folder.
|
||||||
|
|
||||||
Parameters:
|
Parameters:
|
||||||
source (str): The path to the source folder.
|
- source (str): The path to the source folder.
|
||||||
destination (str): The path to the destination folder.
|
- destination (str): The path to the destination folder.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
os.makedirs(destination, exist_ok=True)
|
os.makedirs(destination, exist_ok=True)
|
||||||
@ -37,8 +37,8 @@ def move_content(source: str, destination: str) :
|
|||||||
# If it's a directory, recursively call the function
|
# If it's a directory, recursively call the function
|
||||||
if os.path.isdir(source_path):
|
if os.path.isdir(source_path):
|
||||||
move_content(source_path, destination_path)
|
move_content(source_path, destination_path)
|
||||||
|
|
||||||
# Otherwise, move the file, replacing if it already exists
|
# Otherwise, move the file, replacing if it already exists
|
||||||
else:
|
else:
|
||||||
shutil.move(source_path, destination_path)
|
shutil.move(source_path, destination_path)
|
||||||
|
|
||||||
@ -48,15 +48,15 @@ def keep_specific_items(directory: str, keep_folder: str, keep_file: str):
|
|||||||
Delete all items in the directory except for the specified folder and file.
|
Delete all items in the directory except for the specified folder and file.
|
||||||
|
|
||||||
Parameters:
|
Parameters:
|
||||||
directory (str): The path to the directory.
|
- directory (str): The path to the directory.
|
||||||
keep_folder (str): The name of the folder to keep.
|
- keep_folder (str): The name of the folder to keep.
|
||||||
keep_file (str): The name of the file to keep.
|
- keep_file (str): The name of the file to keep.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
try:
|
try:
|
||||||
if not os.path.exists(directory) or not os.path.isdir(directory):
|
if not os.path.exists(directory) or not os.path.isdir(directory):
|
||||||
raise ValueError(f"Error: '{directory}' is not a valid directory.")
|
raise ValueError(f"Error: '{directory}' is not a valid directory.")
|
||||||
|
|
||||||
# Iterate through items in the directory
|
# Iterate through items in the directory
|
||||||
for item in os.listdir(directory):
|
for item in os.listdir(directory):
|
||||||
item_path = os.path.join(directory, item)
|
item_path = os.path.join(directory, item)
|
||||||
@ -64,14 +64,15 @@ def keep_specific_items(directory: str, keep_folder: str, keep_file: str):
|
|||||||
# Check if the item is the specified folder or file
|
# Check if the item is the specified folder or file
|
||||||
if os.path.isdir(item_path) and item != keep_folder:
|
if os.path.isdir(item_path) and item != keep_folder:
|
||||||
shutil.rmtree(item_path)
|
shutil.rmtree(item_path)
|
||||||
|
|
||||||
elif os.path.isfile(item_path) and item != keep_file:
|
elif os.path.isfile(item_path) and item != keep_file:
|
||||||
os.remove(item_path)
|
os.remove(item_path)
|
||||||
|
|
||||||
except PermissionError as pe:
|
except PermissionError as pe:
|
||||||
print(f"PermissionError: {pe}. Check permissions and try running the script with admin privileges.")
|
console.print(f"[red]PermissionError: {pe}. Check permissions and try again.")
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(f"Error: {e}")
|
console.print(f"[red]Error: {e}")
|
||||||
|
|
||||||
|
|
||||||
def download_and_extract_latest_commit():
|
def download_and_extract_latest_commit():
|
||||||
@ -79,63 +80,68 @@ def download_and_extract_latest_commit():
|
|||||||
Download and extract the latest commit from a GitHub repository.
|
Download and extract the latest commit from a GitHub repository.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
# Get the latest commit information using GitHub API
|
try:
|
||||||
api_url = f'https://api.github.com/repos/{__author__}/{__title__}/commits?per_page=1'
|
|
||||||
response = httpx.get(api_url)
|
|
||||||
console.log("[green]Making a request to GitHub repository...")
|
|
||||||
|
|
||||||
if response.status_code == 200:
|
# Get the latest commit information using GitHub API
|
||||||
commit_info = response.json()[0]
|
api_url = f'https://api.github.com/repos/{__author__}/{__title__}/commits?per_page=1'
|
||||||
commit_sha = commit_info['sha']
|
response = httpx.get(api_url, timeout=10)
|
||||||
zipball_url = f'https://github.com/{__author__}/{__title__}/archive/{commit_sha}.zip'
|
console.log("[green]Requesting latest commit from GitHub repository...")
|
||||||
console.log("[green]Getting zip file from repository...")
|
|
||||||
|
|
||||||
# Download the zipball
|
if response.status_code == 200:
|
||||||
response = httpx.get(zipball_url, follow_redirects=True, timeout=10)
|
commit_info = response.json()[0]
|
||||||
|
commit_sha = commit_info['sha']
|
||||||
|
zipball_url = f'https://github.com/{__author__}/{__title__}/archive/{commit_sha}.zip'
|
||||||
|
console.log("[green]Downloading latest commit zip file...")
|
||||||
|
|
||||||
# Extract the content of the zipball into a temporary folder
|
# Download the zipball
|
||||||
temp_path = os.path.join(os.path.dirname(os.getcwd()), 'temp_extracted')
|
response = httpx.get(zipball_url, follow_redirects=True, timeout=10)
|
||||||
with ZipFile(BytesIO(response.content)) as zip_ref:
|
temp_path = os.path.join(os.path.dirname(os.getcwd()), 'temp_extracted')
|
||||||
zip_ref.extractall(temp_path)
|
|
||||||
console.log("[green]Extracting file ...")
|
|
||||||
|
|
||||||
# Move files from the temporary folder to the current folder
|
# Extract the content of the zipball into a temporary folder
|
||||||
for item in os.listdir(temp_path):
|
with ZipFile(BytesIO(response.content)) as zip_ref:
|
||||||
item_path = os.path.join(temp_path, item)
|
zip_ref.extractall(temp_path)
|
||||||
destination_path = os.path.join(local_path, item)
|
console.log("[green]Extracting files...")
|
||||||
shutil.move(item_path, destination_path)
|
|
||||||
|
|
||||||
# Remove the temporary folder
|
# Move files from the temporary folder to the current folder
|
||||||
shutil.rmtree(temp_path)
|
for item in os.listdir(temp_path):
|
||||||
|
item_path = os.path.join(temp_path, item)
|
||||||
|
destination_path = os.path.join(local_path, item)
|
||||||
|
shutil.move(item_path, destination_path)
|
||||||
|
|
||||||
# Move all folder to main folder
|
# Remove the temporary folder
|
||||||
new_folder_name = f"{__title__}-{commit_sha}"
|
shutil.rmtree(temp_path)
|
||||||
move_content(new_folder_name, ".")
|
|
||||||
|
|
||||||
# Remove old temp folder
|
# Move all folder to main folder
|
||||||
shutil.rmtree(new_folder_name)
|
new_folder_name = f"{__title__}-{commit_sha}"
|
||||||
|
move_content(new_folder_name, ".")
|
||||||
|
|
||||||
console.log(f"[cyan]Latest commit downloaded and extracted successfully.")
|
# Remove old temp folder
|
||||||
else:
|
shutil.rmtree(new_folder_name)
|
||||||
console.log(f"[red]Failed to fetch commit information. Status code: {response.status_code}")
|
console.log("[cyan]Latest commit downloaded and extracted successfully.")
|
||||||
|
else:
|
||||||
|
console.log(f"[red]Failed to fetch commit information. Status code: {response.status_code}")
|
||||||
|
|
||||||
|
except httpx.RequestError as e:
|
||||||
|
console.print(f"[red]Request failed: {e}")
|
||||||
|
|
||||||
|
except Exception as e:
|
||||||
|
console.print(f"[red]An unexpected error occurred: {e}")
|
||||||
|
|
||||||
|
|
||||||
def main_upload():
|
def main_upload():
|
||||||
"""
|
"""
|
||||||
Main function to upload the latest commit of a GitHub repository.
|
Main function to upload the latest commit of a GitHub repository.
|
||||||
"""
|
"""
|
||||||
|
cmd_insert = Prompt.ask("[bold red]Are you sure you want to delete all files? (Only 'Video' folder and 'update_version.py' will remain)", choices=['y', 'n'], default='y', show_choices=True)
|
||||||
cmd_insert = Prompt.ask("[bold red]Are you sure you want to delete all files? (Only videos folder will remain)[/bold red] [yes/no]")
|
|
||||||
|
|
||||||
if cmd_insert.lower() == "yes":
|
if cmd_insert.lower() == "yes":
|
||||||
console.print("[red]Deleting all files except the videos folder...")
|
console.print("[red]Deleting all files except 'Video' folder and 'update_version.py'...")
|
||||||
|
|
||||||
# Remove all old file
|
|
||||||
keep_specific_items(".", "Video", "upload.py")
|
keep_specific_items(".", "Video", "upload.py")
|
||||||
|
|
||||||
download_and_extract_latest_commit()
|
download_and_extract_latest_commit()
|
||||||
|
|
||||||
else:
|
else:
|
||||||
console.print("[red]Operation cancelled.")
|
console.print("[red]Operation cancelled.")
|
||||||
|
|
||||||
main_upload()
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
main_upload()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user