Platform tools (#40)

* Added Platform Tools

* autopep8 action fixes (#39)

* autopep8 action fixes (#41)
This commit is contained in:
Peter Taylor 2022-03-26 23:59:49 +00:00 committed by GitHub
parent 170253793e
commit 9370bbfe46
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 19 additions and 4 deletions

View file

@ -23,7 +23,13 @@ This uses the same API the itchio app uses to download the files. If you have 2F
python -m itchiodl.downloader --api-key=KEYHERE --jobs=4
# via setup-tools entry point
itch-download -k KEYHERE
# download with multiple threads
itch-download -k KEYHERE -j 4
# only download osx or cross platform downloads
itch-download -p osx
```
## Add All Games in a bundle to your library

View file

@ -15,6 +15,11 @@ def main():
"--api-key",
help="Use API key instead of username/password")
parser.add_argument(
"-p",
"--platform",
help="Platform to download for (default: all), will accept values like 'windows', 'linux', 'osx' and android")
parser.add_argument(
"-j",
"--jobs",
@ -35,7 +40,7 @@ def main():
lib = itchiodl.Library(l, args.jobs)
lib.load_games()
lib.download_library()
lib.download_library(args.platform)
if __name__ == "__main__":

View file

@ -34,7 +34,7 @@ class Game:
for d in j["uploads"]:
self.downloads.append(d)
def download(self, token):
def download(self, token, platform):
if os.path.exists(f"{self.publisher_slug}/{self.game_slug}.json"):
print(f"Skipping Game {self.name}")
return
@ -48,6 +48,10 @@ class Game:
os.mkdir(f"{self.publisher_slug}/{self.game_slug}")
for d in self.downloads:
if platform is not None and d["traits"] and f"p_{platform}" not in d["traits"]:
print(f"Skipping {self.name} for platform {d['traits']}")
continue
file = d['filename'] or d['display_name'] or d['id']
path = f"{self.publisher_slug}/{self.game_slug}"
if os.path.exists(f"{path}/{file}"):

View file

@ -32,7 +32,7 @@ class Library:
break
page += 1
def download_library(self):
def download_library(self, platform=None):
with ThreadPoolExecutor(max_workers=self.jobs) as executor:
def dl(g): return g.download(self.login)
def dl(g): return g.download(self.login, platform)
executor.map(dl, self.games)