2021-05-02 21:48:25 +12:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
|
|
|
|
from unittest.mock import MagicMock
|
|
|
|
|
|
|
|
import pytest
|
|
|
|
|
2021-11-21 14:48:29 +13:00
|
|
|
from bdfr.exceptions import NotADownloadableLinkError
|
2021-05-02 21:48:25 +12:00
|
|
|
from bdfr.resource import Resource
|
2021-11-24 13:40:18 +13:00
|
|
|
from bdfr.site_downloaders.fallback_downloaders.ytdlp_fallback import YtdlpFallback
|
2021-05-02 21:48:25 +12:00
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.online
|
|
|
|
@pytest.mark.parametrize(('test_url', 'expected'), (
|
|
|
|
('https://www.reddit.com/r/specializedtools/comments/n2nw5m/bamboo_splitter/', True),
|
|
|
|
('https://www.youtube.com/watch?v=P19nvJOmqCc', True),
|
|
|
|
('https://www.example.com/test', False),
|
2021-11-21 14:48:29 +13:00
|
|
|
('https://milesmatrix.bandcamp.com/album/la-boum/', False),
|
2022-09-27 13:53:12 +13:00
|
|
|
('https://v.redd.it/54i8fvzev3u81', True),
|
2021-05-02 21:48:25 +12:00
|
|
|
))
|
|
|
|
def test_can_handle_link(test_url: str, expected: bool):
|
2021-11-24 13:40:18 +13:00
|
|
|
result = YtdlpFallback.can_handle_link(test_url)
|
2021-05-02 21:48:25 +12:00
|
|
|
assert result == expected
|
|
|
|
|
|
|
|
|
2021-11-21 14:48:29 +13:00
|
|
|
@pytest.mark.online
|
|
|
|
@pytest.mark.parametrize('test_url', (
|
|
|
|
'https://milesmatrix.bandcamp.com/album/la-boum/',
|
|
|
|
))
|
|
|
|
def test_info_extraction_bad(test_url: str):
|
|
|
|
with pytest.raises(NotADownloadableLinkError):
|
2021-11-24 13:40:18 +13:00
|
|
|
YtdlpFallback.get_video_attributes(test_url)
|
2021-11-21 14:48:29 +13:00
|
|
|
|
|
|
|
|
2021-05-02 21:48:25 +12:00
|
|
|
@pytest.mark.online
|
|
|
|
@pytest.mark.slow
|
|
|
|
@pytest.mark.parametrize(('test_url', 'expected_hash'), (
|
2021-10-02 15:11:53 +13:00
|
|
|
('https://streamable.com/dt46y', 'b7e465adaade5f2b6d8c2b4b7d0a2878'),
|
2021-05-02 21:48:25 +12:00
|
|
|
('https://streamable.com/t8sem', '49b2d1220c485455548f1edbc05d4ecf'),
|
2022-09-22 18:57:30 +12:00
|
|
|
('https://www.reddit.com/r/specializedtools/comments/n2nw5m/bamboo_splitter/', '03087ce64f88f438bad6849858c9b7f0'),
|
|
|
|
('https://v.redd.it/9z1dnk3xr5k61', '9ce39c8e46b6534a0b3f164a792d51c8'),
|
2021-05-02 21:48:25 +12:00
|
|
|
))
|
|
|
|
def test_find_resources(test_url: str, expected_hash: str):
|
|
|
|
test_submission = MagicMock()
|
|
|
|
test_submission.url = test_url
|
2021-11-24 13:40:18 +13:00
|
|
|
downloader = YtdlpFallback(test_submission)
|
2021-05-02 21:48:25 +12:00
|
|
|
resources = downloader.find_resources()
|
|
|
|
assert len(resources) == 1
|
|
|
|
assert isinstance(resources[0], Resource)
|
2021-10-02 15:11:53 +13:00
|
|
|
for res in resources:
|
|
|
|
res.download()
|
2021-05-02 21:48:25 +12:00
|
|
|
assert resources[0].hash.hexdigest() == expected_hash
|