Skip to content

Commit

Permalink
Merge pull request #522 from aliparlakci/development
Browse files Browse the repository at this point in the history
v2.4.1
  • Loading branch information
aliparlakci authored Sep 14, 2021
2 parents afe3b71 + 01923fd commit 2d6e25d
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 19 deletions.
6 changes: 5 additions & 1 deletion bdfr/site_downloaders/imgur.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,11 @@ def find_resources(self, authenticator: Optional[SiteAuthenticator] = None) -> l
return out

def _compute_image_url(self, image: dict) -> Resource:
image_url = 'https://i.imgur.com/' + image['hash'] + self._validate_extension(image['ext'])
ext = self._validate_extension(image['ext'])
if image.get('prefer_video', False):
ext = '.mp4'

image_url = 'https://i.imgur.com/' + image['hash'] + ext
return Resource(self.post, image_url, Resource.retry_download(image_url))

@staticmethod
Expand Down
8 changes: 7 additions & 1 deletion bdfr/site_downloaders/vidble.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,20 @@ def __init__(self, post: Submission):
super().__init__(post)

def find_resources(self, authenticator: Optional[SiteAuthenticator] = None) -> list[Resource]:
res = self.get_links(self.post.url)
try:
res = self.get_links(self.post.url)
except AttributeError:
raise SiteDownloaderError(f'Could not read page at {self.post.url}')
if not res:
raise SiteDownloaderError(rf'No resources found at {self.post.url}')
res = [Resource(self.post, r, Resource.retry_download(r)) for r in res]
return res

@staticmethod
def get_links(url: str) -> set[str]:
if not re.search(r'vidble.com/(show/|album/|watch\?v)', url):
url = re.sub(r'/(\w*?)$', r'/show/\1', url)

page = requests.get(url)
soup = bs4.BeautifulSoup(page.text, 'html.parser')
content_div = soup.find('div', attrs={'id': 'ContentPlaceHolder1_divContent'})
Expand Down
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ description_file = README.md
description_content_type = text/markdown
home_page = https://github.com/aliparlakci/bulk-downloader-for-reddit
keywords = reddit, download, archive
version = 2.4.0
version = 2.4.1
author = Ali Parlakci
author_email = [email protected]
maintainer = Serene Arc
Expand Down
10 changes: 9 additions & 1 deletion tests/site_downloaders/test_imgur.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ def test_imgur_extension_validation_bad(test_extension: str):
),
(
'https://imgur.com/gallery/IjJJdlC',
('7227d4312a9779b74302724a0cfa9081',),
('740b006cf9ec9d6f734b6e8f5130bdab',),
),
(
'https://imgur.com/a/dcc84Gt',
Expand Down Expand Up @@ -142,6 +142,14 @@ def test_imgur_extension_validation_bad(test_extension: str):
'https://imgur.com/ubYwpbk.GIFV',
('d4a774aac1667783f9ed3a1bd02fac0c',),
),
(
'https://i.imgur.com/j1CNCZY.gifv',
('58e7e6d972058c18b7ecde910ca147e3',),
),
(
'https://i.imgur.com/uTvtQsw.gifv',
('46c86533aa60fc0e09f2a758513e3ac2',),
),
))
def test_find_resources(test_url: str, expected_hashes: list[str]):
mock_download = Mock()
Expand Down
36 changes: 21 additions & 15 deletions tests/site_downloaders/test_vidble.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,28 +33,34 @@ def test_change_med_url(test_url: str, expected: str):
('https://vidble.com/watch?v=0q4nWakqM6kzQWxlePD8N62Dsflev0N9', {
'https://www.vidble.com/0q4nWakqM6kzQWxlePD8N62Dsflev0N9.mp4',
}),
('https://www.vidble.com/pHuwWkOcEb', {
'https://www.vidble.com/pHuwWkOcEb.jpg',
}),
))
def test_get_links(test_url: str, expected: set[str]):
results = Vidble.get_links(test_url)
assert results == expected


@pytest.mark.parametrize(('test_url', 'expected_hashes'), (
('https://www.vidble.com/show/UxsvAssYe5', {
'0ef2f8e0e0b45936d2fb3e6fbdf67e28',
}),
('https://vidble.com/show/RDFbznUvcN', {
'c2dd30a71e32369c50eed86f86efff58',
}),
('https://vidble.com/album/h0jTLs6B', {
'3b3cba02e01c91f9858a95240b942c71',
'dd6ecf5fc9e936f9fb614eb6a0537f99',
'b31a942cd8cdda218ed547bbc04c3a27',
'6f77c570b451eef4222804bd52267481',
}),
('https://vidble.com/watch?v=0q4nWakqM6kzQWxlePD8N62Dsflev0N9', {
'cebe9d5f24dba3b0443e5097f160ca83',
}),
('https://www.vidble.com/show/UxsvAssYe5', {
'0ef2f8e0e0b45936d2fb3e6fbdf67e28',
}),
('https://vidble.com/show/RDFbznUvcN', {
'c2dd30a71e32369c50eed86f86efff58',
}),
('https://vidble.com/album/h0jTLs6B', {
'3b3cba02e01c91f9858a95240b942c71',
'dd6ecf5fc9e936f9fb614eb6a0537f99',
'b31a942cd8cdda218ed547bbc04c3a27',
'6f77c570b451eef4222804bd52267481',
}),
('https://vidble.com/watch?v=0q4nWakqM6kzQWxlePD8N62Dsflev0N9', {
'cebe9d5f24dba3b0443e5097f160ca83',
}),
('https://www.vidble.com/pHuwWkOcEb', {
'585f486dd0b2f23a57bddbd5bf185bc7',
}),
))
def test_find_resources(test_url: str, expected_hashes: set[str]):
mock_download = Mock()
Expand Down

0 comments on commit 2d6e25d

Please sign in to comment.