Skip to content

Commit

Permalink
Merge pull request #383 from aliparlakci/development
Browse files Browse the repository at this point in the history
# v2.1.1
## Changelog
  
- OAuth flow modified for Docker environment (#368)
- Fix Youtube downloader crash on links with no downloadable media (#377)
- Fix 404 errors with RedGifs links that were migrated from Gfycat (#374)
  • Loading branch information
aliparlakci committed May 16, 2021
2 parents 6f9430f + 739f97e commit aa750f9
Show file tree
Hide file tree
Showing 9 changed files with 42 additions and 10 deletions.
6 changes: 6 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,9 @@ jobs:
run: |
python setup.py sdist bdist_wheel
twine upload dist/*
- name: Upload coverage report
uses: actions/upload-artifact@v2
with:
name: dist
path: dist/
4 changes: 2 additions & 2 deletions bdfr/oauth2.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,8 @@ def retrieve_new_token(self) -> str:
def receive_connection() -> socket.socket:
server = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
server.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
server.bind(('localhost', 7634))
logger.log(9, 'Server listening on localhost:7634')
server.bind(('0.0.0.0', 7634))
logger.log(9, 'Server listening on 0.0.0.0:7634')

server.listen(1)
client = server.accept()[0]
Expand Down
1 change: 1 addition & 0 deletions bdfr/site_downloaders/gfycat.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ def _get_link(url: str) -> str:

response = Gfycat.retrieve_url(url)
if re.search(r'(redgifs|gifdeliverynetwork)', response.url):
url = url.lower() # Fixes error with old gfycat/redgifs links
return Redgifs._get_link(url)

soup = BeautifulSoup(response.text, 'html.parser')
Expand Down
9 changes: 7 additions & 2 deletions bdfr/site_downloaders/youtube.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import youtube_dl
from praw.models import Submission

from bdfr.exceptions import SiteDownloaderError
from bdfr.exceptions import (NotADownloadableLinkError, SiteDownloaderError)
from bdfr.resource import Resource
from bdfr.site_authenticator import SiteAuthenticator
from bdfr.site_downloaders.base_downloader import BaseDownloader
Expand Down Expand Up @@ -43,7 +43,12 @@ def _download_video(self, ytdl_options: dict) -> Resource:
except youtube_dl.DownloadError as e:
raise SiteDownloaderError(f'Youtube download failed: {e}')

downloaded_file = list(download_path.iterdir())[0]
downloaded_file = None
downloaded_files = list(download_path.iterdir())
if len(downloaded_files) > 0:
downloaded_file = downloaded_files[0]
else:
raise NotADownloadableLinkError(f"No media exists in the URL {self.post.url}")
extension = downloaded_file.suffix
with open(downloaded_file, 'rb') as file:
content = file.read()
Expand Down
7 changes: 5 additions & 2 deletions devscripts/configure.ps1
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
copy .\\bdfr\\default_config.cfg .\\test_config.cfg
echo "`nuser_token = $env:REDDIT_TOKEN" >> ./test_config.cfg
if (-not ([string]::IsNullOrEmpty($env:REDDIT_TOKEN)))
{
copy .\\bdfr\\default_config.cfg .\\test_config.cfg
echo "`nuser_token = $env:REDDIT_TOKEN" >> ./test_config.cfg
}
7 changes: 5 additions & 2 deletions devscripts/configure.sh
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
cp ./bdfr/default_config.cfg ./test_config.cfg
echo -e "\nuser_token = $REDDIT_TOKEN" >> ./test_config.cfg
if [ ! -z "$REDDIT_TOKEN" ]
then
cp ./bdfr/default_config.cfg ./test_config.cfg
echo -e "\nuser_token = $REDDIT_TOKEN" >> ./test_config.cfg
fi
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.1.0
version = 2.1.1
author = Ali Parlakci
author_email = [email protected]
maintainer = Serene Arc
Expand Down
1 change: 1 addition & 0 deletions tests/site_downloaders/test_gfycat.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
('https://gfycat.com/definitivecaninecrayfish', 'https://giant.gfycat.com/DefinitiveCanineCrayfish.mp4'),
('https://gfycat.com/dazzlingsilkyiguana', 'https://giant.gfycat.com/DazzlingSilkyIguana.mp4'),
('https://gfycat.com/webbedimpurebutterfly', 'https://thumbs2.redgifs.com/WebbedImpureButterfly.mp4'),
('https://gfycat.com/CornyLoathsomeHarrierhawk', 'https://thumbs2.redgifs.com/CornyLoathsomeHarrierhawk.mp4')
))
def test_get_link(test_url: str, expected_url: str):
result = Gfycat._get_link(test_url)
Expand Down
15 changes: 14 additions & 1 deletion tests/site_downloaders/test_youtube.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

import pytest

from bdfr.exceptions import NotADownloadableLinkError
from bdfr.resource import Resource
from bdfr.site_downloaders.youtube import Youtube

Expand All @@ -15,7 +16,7 @@
('https://www.youtube.com/watch?v=uSm2VDgRIUs', 'f70b704b4b78b9bb5cd032bfc26e4971'),
('https://www.youtube.com/watch?v=m-tKnjFwleU', '30314930d853afff8ebc7d8c36a5b833'),
))
def test_find_resources(test_url: str, expected_hash: str):
def test_find_resources_good(test_url: str, expected_hash: str):
test_submission = MagicMock()
test_submission.url = test_url
downloader = Youtube(test_submission)
Expand All @@ -24,3 +25,15 @@ def test_find_resources(test_url: str, expected_hash: str):
assert isinstance(resources[0], Resource)
resources[0].download(120)
assert resources[0].hash.hexdigest() == expected_hash


@pytest.mark.online
@pytest.mark.parametrize(('test_url'), (
('https://www.polygon.com/disney-plus/2020/5/14/21249881/gargoyles-animated-series-disney-plus-greg-weisman-interview-oj-simpson-goliath-chronicles'),
))
def test_find_resources_bad(test_url: str):
test_submission = MagicMock()
test_submission.url = test_url
downloader = Youtube(test_submission)
with pytest.raises(NotADownloadableLinkError):
downloader.find_resources()

0 comments on commit aa750f9

Please sign in to comment.