parsed_submission.py
1 import requests 2 3 4 class ParsedSubmission: 5 def __init__(self, success: bool, url: str, artist: str = '', featuring_artist: str = '', track_title: str = ''): 6 self.success = success 7 self.artist = artist 8 self.featuring_artist = featuring_artist 9 self.track_title = track_title 10 self.url = url 11 self.final_url = '' 12 13 def get_final_url(self): 14 # we already did the work once, just return the result 15 if self.final_url != '': 16 return self.final_url 17 18 # Follow URL to the end location in case of URL shorteners 19 session = requests.Session() # so connections are recycled 20 resp = session.head(self.url, allow_redirects=True) 21 self.final_url = resp.url 22 return self.final_url