aboutsummaryrefslogtreecommitdiff
path: root/importer/downloader.py
blob: 290c9e20d7951ca2518d114a10e4a4bb57b2ae87 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
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 provider(self):
        return self.Provider(url=self.url, reddit=self.reddit)