pywaybackup 1.0.1__tar.gz → 1.0.2__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: pywaybackup
3
- Version: 1.0.1
3
+ Version: 1.0.2
4
4
  Summary: Download snapshots from the Wayback Machine
5
5
  Home-page: https://github.com/bitdruid/python-wayback-machine-downloader
6
6
  Author: bitdruid
@@ -9,6 +9,8 @@ License: MIT
9
9
  Keywords: wayback machine internet archive
10
10
  Description-Content-Type: text/markdown
11
11
  License-File: LICENSE
12
+ Requires-Dist: requests==2.31.0
13
+ Requires-Dist: tqdm==4.66.2
12
14
 
13
15
  # archive wayback downloader
14
16
 
@@ -60,7 +62,7 @@ This script allows you to download content from the Wayback Machine (archive.org
60
62
  #### Optional Arguments
61
63
 
62
64
  - `-l`, `--list`: Only print the snapshots available within the specified range. Does not download the snapshots.
63
- - `-e`, `--explicit`: Only download the explicit given url. No wildcard subdomains or paths.
65
+ - `-e`, `--explicit`: Only download the explicit given url. No wildcard subdomains or paths. Use e.g. to get root-only snapshots.
64
66
  - `-o`, `--output`: The folder where downloaded files will be saved.
65
67
 
66
68
  - **Range Selection:**<br>
@@ -83,8 +85,8 @@ Specify the range in years or a specific timestamp either start, end or both. If
83
85
  Download latest snapshot of all files:<br>
84
86
  `waybackup -u http://example.com -c`
85
87
 
86
- Download latest snapshot of all files with retries:<br>
87
- `waybackup -u http://example.com -c --retry 3`
88
+ Download latest snapshot of a specific file:<br>
89
+ `waybackup -u http://example.com/subdir/file.html -c`
88
90
 
89
91
  Download all snapshots sorted per timestamp with a specified range and do not follow redirects:<br>
90
92
  `waybackup -u http://example.com -f -r 5 --no-redirect`
@@ -101,6 +103,84 @@ Download all snapshots and output a json response:<br>
101
103
  List available snapshots per timestamp without downloading and save a csv file to home folder:<br>
102
104
  `waybackup -u http://example.com -f -l --csv /home/user/Downloads`
103
105
 
106
+ ## Output path structure
107
+
108
+ The output path is currently structured as follows by an example for the query:<br>
109
+ `http://example.com/subdir1/subdir2/assets/`:
110
+ <br><br>
111
+ For the current version (`-c`):
112
+ - The requested path will only include all files/folders starting from your query-path.
113
+ ```
114
+ your/path/waybackup_snapshots/
115
+ └── the_root_of_your_query/ (example.com/)
116
+ └── subdir1/
117
+ └── subdir2/
118
+ └── assets/
119
+ ├── image.jpg
120
+ ├── style.css
121
+ ...
122
+ ```
123
+ For all versions (`-f`):
124
+ - Will currently create a folder named as the root of your query. Inside this folder, you will find all timestamps and per timestamp the path you requested.
125
+ ```
126
+ your/path/waybackup_snapshots/
127
+ └── the_root_of_your_query/ (example.com/)
128
+ ├── yyyymmddhhmmss/
129
+ │ ├── subidr1/
130
+ │ │ └── subdir2/
131
+ │ │ └── assets/
132
+ │ │ ├── image.jpg
133
+ │ │ └── style.css
134
+ ├── yyyymmddhhmmss/
135
+ │ ├── subdir1/
136
+ │ │ └── subdir2/
137
+ │ │ └── assets/
138
+ │ │ ├── image.jpg
139
+ │ │ └── style.css
140
+ ...
141
+ ```
142
+
143
+
144
+ ### Json Response
145
+
146
+ For download queries:
147
+
148
+ ```
149
+ [
150
+ {
151
+ "file": "/your/path/waybackup_snapshots/example.com/yyyymmddhhmmss/index.html",
152
+ "id": 1,
153
+ "redirect_timestamp": "yyyymmddhhmmss",
154
+ "redirect_url": "http://web.archive.org/web/yyyymmddhhmmssid_/http://example.com/",
155
+ "response": 200,
156
+ "timestamp": "yyyymmddhhmmss",
157
+ "url_archive": "http://web.archive.org/web/yyyymmddhhmmssid_/http://example.com/",
158
+ "url_origin": "http://example.com/"
159
+ },
160
+ ...
161
+ ]
162
+ ```
163
+
164
+ For list queries:
165
+
166
+ ```
167
+ [
168
+ {
169
+ "digest": "DIGESTOFSNAPSHOT",
170
+ "id": 1,
171
+ "mimetype": "text/html",
172
+ "status": "200",
173
+ "timestamp": "yyyymmddhhmmss",
174
+ "url": "http://example.com/"
175
+ },
176
+ ...
177
+ ]
178
+ ```
179
+
180
+ ## CSV Output
181
+
182
+ The csv contains the json response in a table format.
183
+
104
184
  ## Contributing
105
185
 
106
186
  I'm always happy for some feature requests to improve the usability of this script.
@@ -48,7 +48,7 @@ This script allows you to download content from the Wayback Machine (archive.org
48
48
  #### Optional Arguments
49
49
 
50
50
  - `-l`, `--list`: Only print the snapshots available within the specified range. Does not download the snapshots.
51
- - `-e`, `--explicit`: Only download the explicit given url. No wildcard subdomains or paths.
51
+ - `-e`, `--explicit`: Only download the explicit given url. No wildcard subdomains or paths. Use e.g. to get root-only snapshots.
52
52
  - `-o`, `--output`: The folder where downloaded files will be saved.
53
53
 
54
54
  - **Range Selection:**<br>
@@ -71,8 +71,8 @@ Specify the range in years or a specific timestamp either start, end or both. If
71
71
  Download latest snapshot of all files:<br>
72
72
  `waybackup -u http://example.com -c`
73
73
 
74
- Download latest snapshot of all files with retries:<br>
75
- `waybackup -u http://example.com -c --retry 3`
74
+ Download latest snapshot of a specific file:<br>
75
+ `waybackup -u http://example.com/subdir/file.html -c`
76
76
 
77
77
  Download all snapshots sorted per timestamp with a specified range and do not follow redirects:<br>
78
78
  `waybackup -u http://example.com -f -r 5 --no-redirect`
@@ -89,6 +89,84 @@ Download all snapshots and output a json response:<br>
89
89
  List available snapshots per timestamp without downloading and save a csv file to home folder:<br>
90
90
  `waybackup -u http://example.com -f -l --csv /home/user/Downloads`
91
91
 
92
+ ## Output path structure
93
+
94
+ The output path is currently structured as follows by an example for the query:<br>
95
+ `http://example.com/subdir1/subdir2/assets/`:
96
+ <br><br>
97
+ For the current version (`-c`):
98
+ - The requested path will only include all files/folders starting from your query-path.
99
+ ```
100
+ your/path/waybackup_snapshots/
101
+ └── the_root_of_your_query/ (example.com/)
102
+ └── subdir1/
103
+ └── subdir2/
104
+ └── assets/
105
+ ├── image.jpg
106
+ ├── style.css
107
+ ...
108
+ ```
109
+ For all versions (`-f`):
110
+ - Will currently create a folder named as the root of your query. Inside this folder, you will find all timestamps and per timestamp the path you requested.
111
+ ```
112
+ your/path/waybackup_snapshots/
113
+ └── the_root_of_your_query/ (example.com/)
114
+ ├── yyyymmddhhmmss/
115
+ │ ├── subidr1/
116
+ │ │ └── subdir2/
117
+ │ │ └── assets/
118
+ │ │ ├── image.jpg
119
+ │ │ └── style.css
120
+ ├── yyyymmddhhmmss/
121
+ │ ├── subdir1/
122
+ │ │ └── subdir2/
123
+ │ │ └── assets/
124
+ │ │ ├── image.jpg
125
+ │ │ └── style.css
126
+ ...
127
+ ```
128
+
129
+
130
+ ### Json Response
131
+
132
+ For download queries:
133
+
134
+ ```
135
+ [
136
+ {
137
+ "file": "/your/path/waybackup_snapshots/example.com/yyyymmddhhmmss/index.html",
138
+ "id": 1,
139
+ "redirect_timestamp": "yyyymmddhhmmss",
140
+ "redirect_url": "http://web.archive.org/web/yyyymmddhhmmssid_/http://example.com/",
141
+ "response": 200,
142
+ "timestamp": "yyyymmddhhmmss",
143
+ "url_archive": "http://web.archive.org/web/yyyymmddhhmmssid_/http://example.com/",
144
+ "url_origin": "http://example.com/"
145
+ },
146
+ ...
147
+ ]
148
+ ```
149
+
150
+ For list queries:
151
+
152
+ ```
153
+ [
154
+ {
155
+ "digest": "DIGESTOFSNAPSHOT",
156
+ "id": 1,
157
+ "mimetype": "text/html",
158
+ "status": "200",
159
+ "timestamp": "yyyymmddhhmmss",
160
+ "url": "http://example.com/"
161
+ },
162
+ ...
163
+ ]
164
+ ```
165
+
166
+ ## CSV Output
167
+
168
+ The csv contains the json response in a table format.
169
+
92
170
  ## Contributing
93
171
 
94
172
  I'm always happy for some feature requests to improve the usability of this script.
@@ -36,11 +36,11 @@ class SnapshotCollection:
36
36
  @classmethod
37
37
  def create_collection(cls):
38
38
  new_collection = []
39
- for cdx_entry in cls.SNAPSHOT_COLLECTION:
39
+ for idx, cdx_entry in enumerate(cls.SNAPSHOT_COLLECTION):
40
40
  timestamp, url = cdx_entry["timestamp"], cdx_entry["url"]
41
41
  url_archive = f"http://web.archive.org/web/{timestamp}{cls._url_get_filetype(url)}/{url}"
42
42
  collection_entry = {
43
- "id": cls.SNAPSHOT_COLLECTION.index(cdx_entry),
43
+ "id": idx,
44
44
  "timestamp": timestamp,
45
45
  "url_archive": url_archive,
46
46
  "url_origin": url,
@@ -65,7 +65,7 @@ class SnapshotCollection:
65
65
  - download_file: The output path for the snapshot entry (str) with filename.
66
66
  """
67
67
  timestamp, url = collection_entry["timestamp"], collection_entry["url_origin"]
68
- domain, subdir, filename = cls._url_split(url)
68
+ domain, subdir, filename = cls.url_split(url, index=True)
69
69
  if cls.MODE_CURRENT:
70
70
  download_dir = os.path.join(output, domain, subdir)
71
71
  else:
@@ -109,12 +109,17 @@ class SnapshotCollection:
109
109
  return urltype
110
110
 
111
111
  @classmethod
112
- def _url_split(cls, url):
112
+ def url_split(cls, url, index=False):
113
113
  """
114
114
  Split a URL into domain, subdir and filename.
115
115
  """
116
+ if not urlparse(url).scheme:
117
+ url = "http://" + url
116
118
  parsed_url = urlparse(url)
117
- domain = parsed_url.netloc
118
- subdir = parsed_url.path.strip("/").rsplit("/", 1)[0]
119
- filename = parsed_url.path.split("/")[-1] or "index.html"
119
+ domain = parsed_url.netloc.split("@")[-1].split(":")[0] # split mailto: and port
120
+ filename = parsed_url.path.split("/")[-1]
121
+ if index is True and filename == "":
122
+ filename = "index.html"
123
+ subdir = parsed_url.path.strip("/").replace(filename, "").strip("/")
124
+ filename = filename.replace("%20", " ") # replace url encoded spaces
120
125
  return domain, subdir, filename
@@ -0,0 +1 @@
1
+ __version__ = "1.0.2"
@@ -89,12 +89,25 @@ def query_list(url: str, range: int, start: int, end: int, explicit: bool, mode:
89
89
  try:
90
90
  v.write("\nQuerying snapshots...")
91
91
  query_range = ""
92
+
92
93
  if not range:
93
94
  if start: query_range = query_range + f"&from={start}"
94
95
  if end: query_range = query_range + f"&to={end}"
95
96
  else:
96
97
  query_range = "&from=" + str(datetime.now().year - range)
97
- cdx_url = f"*.{url}/*" if not explicit else f"{url}"
98
+
99
+ # parse user input url and create according cdx url
100
+ domain, subdir, filename = sc.url_split(url)
101
+ if domain and not subdir and not filename:
102
+ cdx_url = f"*.{domain}/*" if not explicit else f"{domain}"
103
+ if domain and subdir and not filename:
104
+ cdx_url = f"{domain}/{subdir}/*"
105
+ if domain and subdir and filename:
106
+ cdx_url = f"{domain}/{subdir}/{filename}/*"
107
+ if domain and not subdir and filename:
108
+ cdx_url = f"{domain}/{filename}/*"
109
+
110
+ print(f"---> {cdx_url}")
98
111
  cdxQuery = f"https://web.archive.org/cdx/search/xd?output=json&url={cdx_url}{query_range}&fl=timestamp,digest,mimetype,statuscode,original&filter!=statuscode:200"
99
112
  cdxResult = requests.get(cdxQuery)
100
113
  sc.create_list(cdxResult, mode)
@@ -121,6 +134,7 @@ def download_list(output, retry, no_redirect, workers):
121
134
  else:
122
135
  batch_size = sc.count_list()
123
136
  sc.create_collection()
137
+ v.write("\n-----> Snapshots prepared")
124
138
  batch_list = [sc.SNAPSHOT_COLLECTION[i:i + batch_size] for i in range(0, len(sc.SNAPSHOT_COLLECTION), batch_size)]
125
139
  threads = []
126
140
  worker = 0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: pywaybackup
3
- Version: 1.0.1
3
+ Version: 1.0.2
4
4
  Summary: Download snapshots from the Wayback Machine
5
5
  Home-page: https://github.com/bitdruid/python-wayback-machine-downloader
6
6
  Author: bitdruid
@@ -9,6 +9,8 @@ License: MIT
9
9
  Keywords: wayback machine internet archive
10
10
  Description-Content-Type: text/markdown
11
11
  License-File: LICENSE
12
+ Requires-Dist: requests==2.31.0
13
+ Requires-Dist: tqdm==4.66.2
12
14
 
13
15
  # archive wayback downloader
14
16
 
@@ -60,7 +62,7 @@ This script allows you to download content from the Wayback Machine (archive.org
60
62
  #### Optional Arguments
61
63
 
62
64
  - `-l`, `--list`: Only print the snapshots available within the specified range. Does not download the snapshots.
63
- - `-e`, `--explicit`: Only download the explicit given url. No wildcard subdomains or paths.
65
+ - `-e`, `--explicit`: Only download the explicit given url. No wildcard subdomains or paths. Use e.g. to get root-only snapshots.
64
66
  - `-o`, `--output`: The folder where downloaded files will be saved.
65
67
 
66
68
  - **Range Selection:**<br>
@@ -83,8 +85,8 @@ Specify the range in years or a specific timestamp either start, end or both. If
83
85
  Download latest snapshot of all files:<br>
84
86
  `waybackup -u http://example.com -c`
85
87
 
86
- Download latest snapshot of all files with retries:<br>
87
- `waybackup -u http://example.com -c --retry 3`
88
+ Download latest snapshot of a specific file:<br>
89
+ `waybackup -u http://example.com/subdir/file.html -c`
88
90
 
89
91
  Download all snapshots sorted per timestamp with a specified range and do not follow redirects:<br>
90
92
  `waybackup -u http://example.com -f -r 5 --no-redirect`
@@ -101,6 +103,84 @@ Download all snapshots and output a json response:<br>
101
103
  List available snapshots per timestamp without downloading and save a csv file to home folder:<br>
102
104
  `waybackup -u http://example.com -f -l --csv /home/user/Downloads`
103
105
 
106
+ ## Output path structure
107
+
108
+ The output path is currently structured as follows by an example for the query:<br>
109
+ `http://example.com/subdir1/subdir2/assets/`:
110
+ <br><br>
111
+ For the current version (`-c`):
112
+ - The requested path will only include all files/folders starting from your query-path.
113
+ ```
114
+ your/path/waybackup_snapshots/
115
+ └── the_root_of_your_query/ (example.com/)
116
+ └── subdir1/
117
+ └── subdir2/
118
+ └── assets/
119
+ ├── image.jpg
120
+ ├── style.css
121
+ ...
122
+ ```
123
+ For all versions (`-f`):
124
+ - Will currently create a folder named as the root of your query. Inside this folder, you will find all timestamps and per timestamp the path you requested.
125
+ ```
126
+ your/path/waybackup_snapshots/
127
+ └── the_root_of_your_query/ (example.com/)
128
+ ├── yyyymmddhhmmss/
129
+ │ ├── subidr1/
130
+ │ │ └── subdir2/
131
+ │ │ └── assets/
132
+ │ │ ├── image.jpg
133
+ │ │ └── style.css
134
+ ├── yyyymmddhhmmss/
135
+ │ ├── subdir1/
136
+ │ │ └── subdir2/
137
+ │ │ └── assets/
138
+ │ │ ├── image.jpg
139
+ │ │ └── style.css
140
+ ...
141
+ ```
142
+
143
+
144
+ ### Json Response
145
+
146
+ For download queries:
147
+
148
+ ```
149
+ [
150
+ {
151
+ "file": "/your/path/waybackup_snapshots/example.com/yyyymmddhhmmss/index.html",
152
+ "id": 1,
153
+ "redirect_timestamp": "yyyymmddhhmmss",
154
+ "redirect_url": "http://web.archive.org/web/yyyymmddhhmmssid_/http://example.com/",
155
+ "response": 200,
156
+ "timestamp": "yyyymmddhhmmss",
157
+ "url_archive": "http://web.archive.org/web/yyyymmddhhmmssid_/http://example.com/",
158
+ "url_origin": "http://example.com/"
159
+ },
160
+ ...
161
+ ]
162
+ ```
163
+
164
+ For list queries:
165
+
166
+ ```
167
+ [
168
+ {
169
+ "digest": "DIGESTOFSNAPSHOT",
170
+ "id": 1,
171
+ "mimetype": "text/html",
172
+ "status": "200",
173
+ "timestamp": "yyyymmddhhmmss",
174
+ "url": "http://example.com/"
175
+ },
176
+ ...
177
+ ]
178
+ ```
179
+
180
+ ## CSV Output
181
+
182
+ The csv contains the json response in a table format.
183
+
104
184
  ## Contributing
105
185
 
106
186
  I'm always happy for some feature requests to improve the usability of this script.
@@ -1 +0,0 @@
1
- __version__ = "1.0.1"
File without changes
File without changes
File without changes