You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

59 lines
1.3KB

  1. import sys
  2. import os
  3. import glob
  4. import json
  5. import re
  6. import requests
  7. # Load existing dataset
  8. mg_filename = "ModularGrid-VCVLibrary.json"
  9. with open(mg_filename) as f:
  10. mg = json.load(f)
  11. # Iterate plugins
  12. for manifest_filename in glob.glob('manifests/*.json'):
  13. with open(manifest_filename) as f:
  14. plugin = json.load(f)
  15. plugin_slug = plugin['slug']
  16. # Iterate modules in plugin
  17. for module in plugin.get('modules', []):
  18. module_slug = module['slug']
  19. mg_url = module.get('modularGridUrl')
  20. if not mg_url:
  21. continue
  22. if [x for x in mg if x.get('mgUrl') == mg_url]:
  23. continue
  24. mg_data = {}
  25. mg_data['pluginSlug'] = plugin_slug
  26. mg_data['moduleSlug'] = module_slug
  27. mg_data['vcvUrl'] = f"https://library.vcvrack.com/{plugin_slug}/{module_slug}"
  28. mg_data['mgUrl'] = mg_url
  29. mg.append(mg_data)
  30. print(mg_data)
  31. # Iterate dataset
  32. for mg_data in mg:
  33. if mg_data.get('mgModuleId'):
  34. continue
  35. # Scrape ModularGrid website for ID
  36. mg_url = mg_data['mgUrl']
  37. r = requests.get(mg_url)
  38. m = re.search(r'data-module-id = "(\d+)"', r.text)
  39. mg_id = m.group(1)
  40. if not mg_id:
  41. print(f"No ModularGrid ID found for {plugin_slug} {module_slug}")
  42. continue
  43. mg_id = int(mg_id)
  44. mg_data['mgModuleId'] = mg_id
  45. print(mg_data)
  46. with open(mg_filename, 'w') as f:
  47. json.dump(mg, f, indent=2)