11import os
2+ import re
23import json
34import hashlib
45import logging
@@ -172,11 +173,23 @@ async def _fetch_download_url(self):
172173 self .download_url = self .url
173174 self .metrics .add ('download_url.orig_type' , 'wb_v1' )
174175 else :
175- self .metrics .add ('download_url.orig_type' , 'osf' )
176+ normalized_url = None
177+ if re .compile (r'^/[a-z0-9]{5}/[^/]*' , re .IGNORECASE ).match (path ):
178+ # In the past the OSF would redirect urls of the form https://osf.io/<file_guid>/ to
179+ # https://osf.io/download/<file_guid>/. It no longer does this, so MFR must detect
180+ # such urls and manually prepend /download/ to the path.
181+ self .metrics .add ('download_url.orig_type' , 'osf-preangular' )
182+ temp_url = furl .furl (self .url )
183+ temp_url .path .segments = ['download' ] + temp_url .path .segments
184+ normalized_url = temp_url .url
185+ else :
186+ self .metrics .add ('download_url.orig_type' , 'osf' )
187+ normalized_url = self .url
188+
176189 # make request to osf, don't follow, store waterbutler download url
177190 request = await self ._make_request (
178191 'GET' ,
179- self . url ,
192+ normalized_url ,
180193 allow_redirects = False ,
181194 headers = {
182195 'Content-Type' : 'application/json'
@@ -188,7 +201,7 @@ async def _fetch_download_url(self):
188201 if request .status != 302 :
189202 raise exceptions .MetadataError (
190203 request .reason ,
191- metadata_url = self . url ,
204+ metadata_url = normalized_url ,
192205 provider = self .NAME ,
193206 code = request .status ,
194207 )
0 commit comments