Last active 1587394359

A rom downloader for the no-intro rom collection on internet archive

Alyssa Smith revised this gist 1587430358. Go to revision

1 file changed, 1 insertion

romdl.py

@@ -1,4 +1,5 @@
1 1 # pip3 install curses-menu xmltodict requests bs4
2 + # supports openemu automatic import on macos
2 3 # python 3.7 yo
3 4 from cursesmenu import CursesMenu
4 5 from cursesmenu.items import SubmenuItem, FunctionItem

Alyssa Smith revised this gist 1587430337. Go to revision

1 file changed, 13 insertions, 19 deletions

romdl.py

@@ -8,43 +8,37 @@ from bs4 import BeautifulSoup as Soup
8 8 from sys import stderr
9 9 import os
10 10 from urllib.parse import urlparse, unquote
11 + from getpass import getuser
12 + from subprocess import Popen
11 13
12 14 system_data = xmltodict.parse(requests.get("https://ia801407.us.archive.org/23/items/no-intro-rom-sets/no-intro-rom-sets_files.xml").text)
13 15 archive_path = "https://ia801407.us.archive.org/view_archive.php?archive=/23/items/no-intro-rom-sets/"
14 16
17 + # openemu support
18 + directory = os.path.join("/Users", getuser(), "Library", "Application Support", "OpenEmu", "Game Library", "roms", "Automatically Import")
19 + if not os.path.exists(directory):
20 + directory = ""
21 +
15 22 def download_file(url):
16 23 if url[0] != "h":
17 24 url = "https:" + url
18 25 r = requests.get(url, stream=True)
19 26 if r.status_code == 200:
20 - with open(os.path.basename(unquote(urlparse(url).path)), "wb") as f:
27 + with open(os.path.join(directory, os.path.basename(unquote(urlparse(url).path))), "wb") as f:
21 28 for chunk in r:
22 29 print("*")
23 30 f.write(chunk)
24 31
25 - def search_submenu(filelist):
26 - " doesn't work "
27 - term = input("Enter search term")
28 - results = []
29 - for row in filelist.findAll("tr")[1:]:
30 - dest_fn = row.find("td")
31 - if ".zip" in dest_fn.text:
32 - if term.lower() in dest_fn.text.split(".zip")[0].lower():
33 - results += (dest_fn.text.split(".zip")[0], dest_fn.find("a")["href"])
34 - search_menu = CursesMenu("Search", "")
35 - for title, url in results:
36 - item = FunctionItem(title, download_file, [url])
37 - search_menu.append_item(item)
38 - search_menu.show()
39 -
40 32 def generate_submenu(filename):
41 33 filelist = Soup(requests.get(archive_path + filename).text, "html.parser").find("table", {"class": "archext"})
42 34 system_menu = CursesMenu(filename, "Select a file to download")
43 - # system_menu.append_item(FunctionItem("Search...", search_submenu, [filelist]))
44 35 for row in filelist.findAll("tr")[1:]:
45 36 dest_fn = row.find("td")
46 37 if ".zip" in dest_fn.text:
47 - item = FunctionItem(dest_fn.text.split(".zip")[0], download_file, [dest_fn.find("a")["href"]])
38 + display_fn = dest_fn.text.split(".zip")[0]
39 + if "/" in display_fn:
40 + display_fn = display_fn.split("/",1)[1]
41 + item = FunctionItem(display_fn, download_file, [dest_fn.find("a")["href"]])
48 42 system_menu.append_item(item)
49 43 system_menu.show()
50 44
@@ -52,7 +46,7 @@ def main():
52 46 systems_menu = CursesMenu("System Menu", "Select the system to browse roms")
53 47 for system in system_data["files"]["file"]:
54 48 if system["@name"][-4:] == ".zip":
55 - item = FunctionItem(system["@name"], generate_submenu, [system["@name"]])
49 + item = FunctionItem(system["@name"], generate_submenu, [system["@name"]], should_exit=True)
56 50 systems_menu.append_item(item)
57 51 systems_menu.show()
58 52

Alyssa Smith revised this gist 1586863437. Go to revision

1 file changed, 1 insertion

romdl.py

@@ -23,6 +23,7 @@ def download_file(url):
23 23 f.write(chunk)
24 24
25 25 def search_submenu(filelist):
26 + " doesn't work "
26 27 term = input("Enter search term")
27 28 results = []
28 29 for row in filelist.findAll("tr")[1:]:

Alyssa Smith revised this gist 1586863372. Go to revision

1 file changed, 2 insertions

romdl.py

@@ -1,3 +1,5 @@
1 + # pip3 install curses-menu xmltodict requests bs4
2 + # python 3.7 yo
1 3 from cursesmenu import CursesMenu
2 4 from cursesmenu.items import SubmenuItem, FunctionItem
3 5 import requests

Alyssa Smith revised this gist 1586863333. Go to revision

1 file changed, 57 insertions

romdl.py(file created)

@@ -0,0 +1,57 @@
1 + from cursesmenu import CursesMenu
2 + from cursesmenu.items import SubmenuItem, FunctionItem
3 + import requests
4 + import xmltodict
5 + from bs4 import BeautifulSoup as Soup
6 + from sys import stderr
7 + import os
8 + from urllib.parse import urlparse, unquote
9 +
10 + system_data = xmltodict.parse(requests.get("https://ia801407.us.archive.org/23/items/no-intro-rom-sets/no-intro-rom-sets_files.xml").text)
11 + archive_path = "https://ia801407.us.archive.org/view_archive.php?archive=/23/items/no-intro-rom-sets/"
12 +
13 + def download_file(url):
14 + if url[0] != "h":
15 + url = "https:" + url
16 + r = requests.get(url, stream=True)
17 + if r.status_code == 200:
18 + with open(os.path.basename(unquote(urlparse(url).path)), "wb") as f:
19 + for chunk in r:
20 + print("*")
21 + f.write(chunk)
22 +
23 + def search_submenu(filelist):
24 + term = input("Enter search term")
25 + results = []
26 + for row in filelist.findAll("tr")[1:]:
27 + dest_fn = row.find("td")
28 + if ".zip" in dest_fn.text:
29 + if term.lower() in dest_fn.text.split(".zip")[0].lower():
30 + results += (dest_fn.text.split(".zip")[0], dest_fn.find("a")["href"])
31 + search_menu = CursesMenu("Search", "")
32 + for title, url in results:
33 + item = FunctionItem(title, download_file, [url])
34 + search_menu.append_item(item)
35 + search_menu.show()
36 +
37 + def generate_submenu(filename):
38 + filelist = Soup(requests.get(archive_path + filename).text, "html.parser").find("table", {"class": "archext"})
39 + system_menu = CursesMenu(filename, "Select a file to download")
40 + # system_menu.append_item(FunctionItem("Search...", search_submenu, [filelist]))
41 + for row in filelist.findAll("tr")[1:]:
42 + dest_fn = row.find("td")
43 + if ".zip" in dest_fn.text:
44 + item = FunctionItem(dest_fn.text.split(".zip")[0], download_file, [dest_fn.find("a")["href"]])
45 + system_menu.append_item(item)
46 + system_menu.show()
47 +
48 + def main():
49 + systems_menu = CursesMenu("System Menu", "Select the system to browse roms")
50 + for system in system_data["files"]["file"]:
51 + if system["@name"][-4:] == ".zip":
52 + item = FunctionItem(system["@name"], generate_submenu, [system["@name"]])
53 + systems_menu.append_item(item)
54 + systems_menu.show()
55 +
56 + if __name__ == "__main__":
57 + main()
Newer Older