-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #16 from jhg3410/fix/videoplayer
videoPlayer streamUrl 버그 수정
- Loading branch information
Showing
2 changed files
with
39 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,44 @@ | ||
import re | ||
import mock | ||
from pytube import YouTube | ||
from pytube.cipher import get_throttling_function_code | ||
|
||
def getVideoStreamUrl(videoId): | ||
# YouTube URL | ||
youtube_url = "https://www.youtube.com/watch?v=" + videoId | ||
with mock.patch('pytube.cipher.get_throttling_plan', patched_throttling_plan): | ||
# YouTube URL | ||
youtube_url = "https://www.youtube.com/watch?v=" + videoId | ||
|
||
# Create a YouTube object | ||
youtube = YouTube(youtube_url) | ||
# Create a YouTube object | ||
youtube = YouTube(youtube_url) | ||
|
||
# Get the best stream (video) available | ||
video_stream = youtube.streams.get_highest_resolution() | ||
# Get the best stream (video) available | ||
video_stream = youtube.streams.get_highest_resolution() | ||
|
||
# Get the video URL | ||
return video_stream.url | ||
|
||
|
||
def patched_throttling_plan(js: str): | ||
"""Patch throttling plan, from https://github.com/pytube/pytube/issues/1498""" | ||
raw_code = get_throttling_function_code(js) | ||
|
||
transform_start = r"try{" | ||
plan_regex = re.compile(transform_start) | ||
match = plan_regex.search(raw_code) | ||
|
||
#transform_plan_raw = find_object_from_startpoint(raw_code, match.span()[1] - 1) | ||
transform_plan_raw = js | ||
|
||
# Steps are either c[x](c[y]) or c[x](c[y],c[z]) | ||
step_start = r"c\[(\d+)\]\(c\[(\d+)\](,c(\[(\d+)\]))?\)" | ||
step_regex = re.compile(step_start) | ||
matches = step_regex.findall(transform_plan_raw) | ||
transform_steps = [] | ||
for match in matches: | ||
if match[4] != '': | ||
transform_steps.append((match[0],match[1],match[4])) | ||
else: | ||
transform_steps.append((match[0],match[1])) | ||
|
||
return transform_steps | ||
|
||
# Get the video URL | ||
return video_stream.url |