Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

videoPlayer streamUrl 버그 수정 #16

Merged
merged 1 commit into from
Sep 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions lib-videoplayer/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ chaquopy {
defaultConfig {
pip {
install("pytube")
install("mock")
}
}
}
Expand All @@ -70,6 +71,4 @@ dependencies {
// exoplayer
implementation(libs.media3.exoplayer)
implementation(libs.media3.ui)


}
46 changes: 38 additions & 8 deletions lib-videoplayer/src/main/python/youtube_stream_url.py
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