-
Notifications
You must be signed in to change notification settings - Fork 30
/
gparch_cli.py
165 lines (137 loc) · 5.6 KB
/
gparch_cli.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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
"""
CLI Interface
Archiver for Google Photos
By: Nick Dawson | [email protected]
"""
"""
Archiver For Google Photos
- A tool to maintain an archive/mirror of your Google Photos library for backup purposes.
Copyright (C) 2021 Nicholas Dawson
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
"""
import argparse
from os import getcwd
from colorama import Fore, init
from gparch import VERSION, PhotosAccount
if __name__ == "__main__":
init() # Init colorama
CWD = getcwd()
DEFAULT_THREADS = 8
parser = argparse.ArgumentParser(
description="If no directory arg is provided the program will default to the current working directory. "
"If no credentials are provided the program will search for 'credentials.json' in the directory. "
"If no download options are provided, the program will download everything. "
"The program automatically skips downloading existing files so running the program with any"
" download option after downloading items already will update everything without re-downloading or"
" deleting existing media. It will only ensure everything is downloaded from Google Photos."
)
parser.add_argument(
"directory",
nargs="?",
default=CWD,
help="directory where your photo library is saved",
)
parser.add_argument(
"-c",
"--credentials",
help="path to Google Cloud OAuth2 Credentials (default: {CURRENT_DIR}/credentials.json)",
type=str,
)
parser.add_argument(
"-d", "--debug", help="enable debugging mode", action="store_true"
)
parser.add_argument(
"-t",
"--threads",
help="amount of threads to use when downloading media items (default: 8)",
default=DEFAULT_THREADS,
type=int,
)
parser.add_argument(
"-a",
"--albums",
help="download all albums YOU have created",
action="store_true",
)
parser.add_argument(
"-s",
"--shared",
help="download all shared albums (with you/from you)",
action="store_true",
)
parser.add_argument(
"-f",
"--favorites",
help="download all media from your library that is marked as favorite",
action="store_true",
)
args = parser.parse_args()
# Welcome Message
print(Fore.BLUE + "================================")
print(Fore.RED + "Archiver for Google Photos (CLI)")
print(Fore.YELLOW + " - By: Nick Dawson")
print(Fore.YELLOW + " - GitHub @NicholasDawson")
print(Fore.YELLOW + " - https://ndawson.me")
print(
Fore.RED + "\nReport all issues on GitHub:"
"\nhttps://github.com/NicholasDawson/ArchiverForGooglePhotos/issues"
)
print(Fore.RED + "Version -> " + VERSION)
print(Fore.BLUE + "================================")
if args.credentials is None:
args.credentials = args.directory + "/credentials.json"
# Init PhotosAccount object
account = PhotosAccount(args.credentials, args.directory, args.threads, args.debug)
account.get_google_api_service()
# ==============
# ARG PROCESSING
# - downloaded in order of importance
# - (fav) -> (albums) -> (shared) -> (library)
# - this is because media is only downloaded and stored in one location
# so we want it to be in the most specific place possible
# ==============
# Handler for downloading everything default option (when no download options are specified)
download_everything = False
if not args.favorites and not args.shared and not args.albums:
args.favorites = True
args.shared = True
args.albums = True
download_everything = True
# Download everything
try:
if args.favorites:
print(Fore.YELLOW + "Reading Favorites List From Server..." + Fore.BLUE)
account.download_favorites()
print(Fore.GREEN + "✔ Finished Downloading Favorites.")
if args.albums:
print(Fore.YELLOW + "Reading Albums List From Server..." + Fore.BLUE)
account.download_all_albums()
print(Fore.GREEN + "✔ Finished Downloading Albums.")
if args.shared:
print(Fore.YELLOW + "Reading Shared Albums List From Server..." + Fore.BLUE)
account.download_all_shared_albums()
print(Fore.GREEN + "✔ Finished Downloading Shared Albums.")
if download_everything:
print(Fore.YELLOW + "Reading Entire Library From Server..." + Fore.BLUE)
account.download_library()
print(Fore.GREEN + "✔ Finished Downloading Everything.")
# Finish up and close program
finally:
# Close db connection
account.con.close()
# Print session stats
seconds, downloads = account.get_session_stats()
print(Fore.RED + "\n=============")
print("SESSION STATS")
print("=============")
print(Fore.BLUE + f"Seconds: {Fore.YELLOW}{seconds:.{2}f}s")
print(Fore.BLUE + f"Downloads: {Fore.YELLOW}{downloads} items")