-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathgd2tg.py
55 lines (46 loc) · 1.7 KB
/
gd2tg.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
import copy_gdrive
import os
import split
import subprocess
import sys
def download_and_upload(gdrive_link):
gdrive_link = sys.argv[1]
gdrive_id = copy_gdrive.get_id(gdrive_link)
new_gdrive_link = copy_gdrive.copy_copy_get_link(gdrive_id)
new_gdrive_id = copy_gdrive.get_id(new_gdrive_link)
filename = copy_gdrive.download_file(new_gdrive_id)
path = 'tmp'
if split.must_split(path, filename):
print('\n\nMust split, compressing\n\n')
nof_parts = split.compress(path, filename)
print('\n\nCompression completed')
print('\n\nParts: {}'.format(str(nof_parts)))
dest_filenames = split.get_compressed_filenames(filename, nof_parts)
must_split = True
else:
print('\n\nSmall file, skipping compression')
dest_filenames = [filename]
must_split = False
for f in dest_filenames:
print('\n\nUploading {}\n\n'.format(f))
porcess_out = subprocess.Popen('python telegramfilemanager.py "{}"'.format(
path + ('/_rar/' if must_split else '/') + f
), shell=True)
if porcess_out.wait() != 0:
print('\n\nError uploading your file:\n--STDERR')
print(porcess_out.stderr)
print('\n\n--\n\n--STDOUT')
print(porcess_out.stdout)
print('\n\n--')
quit()
print('Uploaded {}'.format(f))
if must_split:
split.clean_compressed_files(path, dest_filenames)
os.remove(path + '/' + filename)
copy_gdrive.delete_file(new_gdrive_id)
if __name__ == '__main__':
if len(sys.argv) < 2:
print('Syntax: python gdrive_to_telegram.py [gdrive link]')
quit()
else:
download_and_upload(sys.argv[1])