fmt_streams = get_fmt_stream_list(page_data)
video_url = self.choose_best_fmt_stream_url(fmt_streams)
- # The "itag" parameter makes the 403 happen.
- video_url.gsub!(/itag=\d+&/, '')
+ # A duplicated "itag" parameter results in a 403.
+ itag_regex = /&itag=\d+/
+ matches = video_url.scan(itag_regex)
+
+ if matches.length > 1
+ # Get rid of the first occurrence.
+ video_url.sub!(itag_regex, '')
+ end
end
return video_url