well, the quick and dirty is just take the resulting URL string and do a "TheUrl?WithParams".Split("?")[0]
as if there is a ? (and should only be 1) it will take the first section, if no ? then it still will result the first section (the whole string).
If you provide the custom macro you're using to generate this though it would help us understand how you are getting the above and will be easier to help you out. There are many ways to generate a media url.