Skip to content

Commit

Permalink
Added new pattern to export asset_id regex for different url pattern (#…
Browse files Browse the repository at this point in the history
…2343)

* Added new pattern to export asset_id regex for different url pattern

* Changed exception type to be more appropriate
  • Loading branch information
joshuastegmaier authored Apr 16, 2024
1 parent 4452f64 commit c87b9f5
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions exporter/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,18 +68,23 @@ def get_original_asset_id(download_url):
"""
download_url = download_url.replace("https", "http")
if download_url.startswith("http://tile.loc.gov/"):
pattern = r"/service:([A-Za-z0-9:.\-\_]+)/|/master/([A-Za-z0-9/]+)([0-9.]+)"
pattern = (
r"/service:([A-Za-z0-9:.\-\_]+)/"
+ r"|/master/([A-Za-z0-9/]+)([0-9.]+)"
+ r"|/public:music:([A-Za-z0-9:.\-\_]+)/"
)
asset_id = re.search(pattern, download_url)
if not asset_id:
logger.error(
"Couldn't find a matching asset ID in download URL %s", download_url
)
raise AssertionError
raise ValueError(
f"Couldn't find a matching asset ID in download URL {download_url}"
)
else:
if asset_id.group(1):
matching_asset_id = asset_id.group(1)
else:
matching_asset_id = asset_id.group(2)
for matching_asset_id in asset_id.groups():
if matching_asset_id:
break
logger.debug(
"Found asset ID %s in download URL %s", matching_asset_id, download_url
)
Expand Down

0 comments on commit c87b9f5

Please sign in to comment.