-
Notifications
You must be signed in to change notification settings - Fork 0
/
cp2toto.py
executable file
·86 lines (67 loc) · 2.76 KB
/
cp2toto.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
import argparse
import asyncio
import re
import sys
import traceback
from utils.menu import select_destination, select_origin
from utils.misc import conversion_flow, remove_local_files
from utils.output import bye, welcome
from utils.scp_connect import scp
from utils.tg import send_message_to_telegram_channel
def main() -> None:
"""
This is the main function that orchestrates the file transfer process.
The function follows these steps:
1. Displays a welcome message to the user.
2. Prompts the user to select the files they want to transfer (origin files).
3. Asks the user to specify the destination folder where the files will be transferred
4. Asks the user if they want to convert the files to MP4 with H.265 codec.
5. Initiates file transfer process, copying selected files to the destination folder.
6. If successful, it asks the user if they want to remove the original files.
7. Also, if the destination folder is the 'movies/' folder, it asks to send a message
to the Telegram channel.
8. Finally, the function displays a farewell message and terminates the program.
Args:
-tg: Optional argument to send a message to the Telegram channel and skip the rest
of the flow.
The function handles two types of exceptions:
- KeyboardInterrupt:
If the user interrupts the program (e.g., by pressing Ctrl+C), the function
immediately exits.
- General exceptions:
If any other type of exception occurs, the function prints the exception details
and exits with a status code of 1.
"""
parser = argparse.ArgumentParser(
description="File management and optionally send a Telegram message."
)
parser.add_argument(
"-tg",
"--send_tg_message_only",
action="store_true",
help="Only send a message to the Telegram channel and skip the rest of the flow.",
)
args = parser.parse_args()
try:
welcome()
if args.send_tg_message_only:
asyncio.run(send_message_to_telegram_channel())
sys.exit()
origin_files = select_origin()
destination_folder = select_destination()
origin_files = conversion_flow(origin_files)
scp_completed = scp(origin_files, destination_folder)
if scp_completed:
pattern = r"/(movies|series)/"
if re.search(pattern, destination_folder) is not None:
asyncio.run(send_message_to_telegram_channel())
remove_local_files(origin_files)
bye()
except KeyboardInterrupt:
sys.exit()
except Exception as general_error:
print(f"A general error occurred: {general_error}")
traceback.print_exc()
sys.exit(1)
if __name__ == "__main__":
main()