import re from praw import Reddit from importer.providers import GReddit, Gfycat, IReddit, Imgur, RedGifs, VReddit, YoutubeDlProviderBase, \ RawImageProviderBase, Youtube class Downloader: providers = [GReddit, Gfycat, IReddit, Imgur, RedGifs, VReddit, Youtube, RawImageProviderBase, YoutubeDlProviderBase] def __init__(self, url: str, reddit: Reddit): self.Provider = next(filter(lambda x: re.match(x.regex, url), self.providers)) self.url = url self.reddit = reddit def download(self): with self.Provider(url=self.url, reddit=self.reddit) as provider: provider.download() self.paths = provider.paths self.downloaded = provider.downloaded