-
Notifications
You must be signed in to change notification settings - Fork 67
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
Feature innertube client fix #219
Open
alive4ever
wants to merge
21
commits into
user234683:master
Choose a base branch
from
alive4ever:feature-innertube-client-fix
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
e5f74b0
settings: add option to enable video download
alive4ever 2c83c72
misc: use fake useragent library
alive4ever c19ee02
settings: add innertube client selection
alive4ever c1346e5
util: update innertube client context
alive4ever e731ca9
player: disable loading of age_restricted content
alive4ever 7e45346
feature: add mweb client
alive4ever 3de2967
generate_release: avoid removing dist-info dirs
alive4ever 7c4acd2
util: more suggested fixes
alive4ever 1f51512
server: more fixes
alive4ever 5a78bfa
util: fix signature_timestamp function
alive4ever 96774a0
yt_data_extract: remove flpc import
alive4ever b63842c
requirements: remove flpc
alive4ever 92734fb
yt_data_extract: return error message if no n signature present
alive4ever 418511a
util: remove debugging messages
alive4ever c7e1cac
server: only send visitor data to specific domains
alive4ever f5e27d5
util: update ios client
alive4ever 5e2a156
update fake-useragent module
alive4ever d0c6db1
util: update player version
alive4ever 03cc5f9
yt_data_extract: fix signature decryption
alive4ever c2d15df
server: fix po_token use
alive4ever edff4a5
server: fix loading po_token_cache
alive4ever File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 |
---|---|---|
|
@@ -6,3 +6,5 @@ urllib3>=1.24.1 | |
defusedxml>=0.5.0 | ||
cachetools>=4.0.0 | ||
stem>=1.8.0 | ||
fake-useragent>=2.0.0 | ||
dukpy>=0.4.0 |
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 |
---|---|---|
|
@@ -20,7 +20,8 @@ | |
import re | ||
import sys | ||
import time | ||
|
||
import os | ||
import json | ||
|
||
|
||
|
||
|
@@ -50,11 +51,49 @@ def parse_range(range_header, content_length): | |
end_byte = int(end) | ||
return start_byte, end_byte | ||
|
||
innertube_client_id = settings.innertube_client_id | ||
innertube_client = util.innertube_client | ||
client = innertube_client[innertube_client_id] | ||
def proxy_site(env, start_response, video=False): | ||
client_params = util.INNERTUBE_CLIENTS[client] | ||
client_context = client_params['INNERTUBE_CONTEXT'] | ||
client_ua = client_context.get('userAgent') or util.mobile_user_agent | ||
send_headers = { | ||
'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; Win64; x64)', | ||
'User-Agent': client_ua, | ||
'Accept': '*/*', | ||
'Accept-language': 'en-US', | ||
'X-YouTube-Client-Name': client_params['INNERTUBE_CONTEXT_CLIENT_NAME'], | ||
'X-YouTube-Client-Version': client_context['client']['clientVersion'], | ||
} | ||
visitor_data_file = os.path.join(settings.data_dir,'visitorData.txt') | ||
visitor_data = None | ||
if not settings.use_po_token: | ||
if settings.use_visitor_data: | ||
if os.path.exists(visitor_data_file): | ||
try: | ||
with open(visitor_data_file, "r") as file: | ||
visitor_data = file.read() | ||
file.close() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Don't need There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Didn't know about that behavior before. Thanks for the hint. |
||
except OSError: | ||
print('An OS error prevents accessing visitorData.txt file') | ||
else: | ||
po_token_cache = os.path.join(settings.data_dir, 'po_token_cache.txt') | ||
if os.path.exists(po_token_cache): | ||
try: | ||
with open(po_token_cache, "r") as file: | ||
po_token_dict = json.loads(file.read()) | ||
visitor_data = po_token_dict.get('visitorData') or None | ||
file.close() | ||
except OSError: | ||
print('An OS error prevents accessing po_token_cache.txt') | ||
|
||
google_domains = [ 'youtube.com', 'youtube-nocookie.com', 'youtu.be', 'googlevideo.com', 'ytimg.com', 'ggpht.com', 'googleapis.com' ] | ||
for domain in google_domains: | ||
if env['SERVER_NAME'].endswith(domain): | ||
if visitor_data != None: | ||
send_headers['X-Goog-Visitor-Id'] = visitor_data | ||
break | ||
|
||
current_range_start = 0 | ||
range_end = None | ||
if 'HTTP_RANGE' in env: | ||
|
@@ -92,6 +131,8 @@ def proxy_site(env, start_response, video=False): | |
except AttributeError: | ||
pass | ||
if video: | ||
send_headers = (list(send_headers) | ||
+ [('origin', 'https://www.youtube.com')]) | ||
response_headers = (list(response_headers) | ||
+[('Access-Control-Allow-Origin', '*')]) | ||
|
||
|
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
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
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe change to
if not settings.use_po_token and settings.use_visitor_data:
? Having trouble understanding the intent of the if's and else's in this tree. If as written is intended, you don't want to nest if statements unnecessarily when you can use anand
insteadThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It didn't occur in my mind when I was modifying this to use
and
statement. Thanks for pointing out this better approach.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I really mean nested if statement instead of adding
settings.use_visitor_data
as additional condition for loading visitorData file.There was a wrong indentation at the next
else
statement.