Skip to content

Commit

Permalink
Fixed #42
Browse files Browse the repository at this point in the history
  • Loading branch information
elmoiv committed Jun 20, 2024
1 parent 92b93f8 commit 1ebaa8f
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 4 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
### v2.0.5 - 20-06-2024:
* [#42](https://github.com/elmoiv/redvid/pull/35) Fixed maximum and minimum video qualities not fetched.
### v2.0.4 - 04-03-2024:
* [#39](https://github.com/elmoiv/redvid/issues/39) Fixed audio not downloaded due to new Reddit patches.
### v2.0.3 - 27-11-2023:
* [#35](https://github.com/elmoiv/redvid/pull/35) Fixed random audio track given to videos with no audio track.
* Temp cleaning is now true by default. Use `-nc` or `--noclean` to save temp files.
Expand Down
2 changes: 1 addition & 1 deletion redvid/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@
__url__ = 'https://github.com/elmoiv/redvid'
__description__ = 'Smart downloader for Reddit hosted videos'
__license__ = 'GPL-v3.0'
__version__ = '2.0.4'
__version__ = '2.0.5'
5 changes: 4 additions & 1 deletion redvid/redvid.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,11 @@ def scrape(self):
self.r_url + 'DASHPlaylist.mpd',
_proxies=self.proxies
)

max_min_qualities = getMaxMinQualities(self.page, self.r_url)

# v1.0.8: Fix new Reddit mechanism
VQS, AQS = mpdParse(mpd.text)
VQS, AQS = mpdParse(mpd.text, custom_video_qualities=max_min_qualities)

if [VQS, AQS] == [0, 0]:
raise BaseException('Qualities not found!')
Expand Down
14 changes: 12 additions & 2 deletions redvid/tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,11 @@ def getSizes(u, h, p, vs):
)
return sizes

def getMaxMinQualities(page, vredd_url):
regex = rf'{vredd_url}(DASH_)(\d+)(\.mp4)'
Match = re.findall(regex, page.text)
return Match

# v1.1.1: if 'vcf.redd.it' in <BASEURL>
# we extract DASH quality names and store them in
# the same form of original re.findall result
Expand All @@ -69,7 +74,7 @@ def vcfRemover(BaseUrls, rgx):
)
return list(convertToReTags)

def mpdParse(mpd):
def mpdParse(mpd, custom_video_qualities=[]):
# v2.0.1: Fix for new reddit mechanism
tags = r'<BaseURL>(DASH_)(?!vtt)(.*?)(\.mp4)?</BaseURL>'
tags_a = r'<BaseURL>(audio)(\.mp4)?</BaseURL>'
Expand All @@ -83,7 +88,12 @@ def mpdParse(mpd):
audio_tags = [tag for tag in re_tags if 'audio' in j(tag).lower()]
video_tags = list(set(re_tags) - set(audio_tags))
tag_aud = audio_tags[-1] if audio_tags else None


# v2.0.5: Adding max and min qualities
for quality in custom_video_qualities:
if quality not in video_tags:
video_tags.append(quality)

if not re_tags:
return 0, 0

Expand Down

0 comments on commit 1ebaa8f

Please sign in to comment.