5 Commits

Author SHA1 Message Date
0dc1747178 update version 0.2.16 2024-04-21 13:16:18 +08:00
8577164785 update client params 2024-04-21 13:14:08 +08:00
8af98968dd Refactoring code and reuse INNERTUBE_CLIENTS 2024-04-21 13:13:19 +08:00
8f00cbcdd6 update
update android_music client
2024-04-21 11:21:35 +08:00
af75551bc2 update
update android client
2024-04-21 11:18:42 +08:00
3 changed files with 114 additions and 118 deletions

View File

@@ -431,12 +431,9 @@ class RateLimitedQueue(gevent.queue.Queue):
gevent.queue.Queue.__init__(self) gevent.queue.Queue.__init__(self)
def get(self): def get(self):
self.lock.acquire() # blocks if another greenlet currently has the lock with self.lock: # blocks if another greenlet currently has the lock
if self.count_since_last_wait >= self.subsequent_bursts and self.surpassed_initial: if ((self.count_since_last_wait >= self.subsequent_bursts and self.surpassed_initial) or
gevent.sleep(self.waiting_period) (self.count_since_last_wait >= self.initial_burst and not self.surpassed_initial)):
self.count_since_last_wait = 0
elif self.count_since_last_wait >= self.initial_burst and not self.surpassed_initial:
self.surpassed_initial = True self.surpassed_initial = True
gevent.sleep(self.waiting_period) gevent.sleep(self.waiting_period)
self.count_since_last_wait = 0 self.count_since_last_wait = 0
@@ -456,8 +453,6 @@ class RateLimitedQueue(gevent.queue.Queue):
self.currently_empty = False self.currently_empty = False
self.lock.release()
return item return item
@@ -667,25 +662,6 @@ def to_valid_filename(name):
# https://github.com/yt-dlp/yt-dlp/blob/master/yt_dlp/extractor/youtube.py#L72 # https://github.com/yt-dlp/yt-dlp/blob/master/yt_dlp/extractor/youtube.py#L72
INNERTUBE_CLIENTS = { INNERTUBE_CLIENTS = {
'android_music': {
'INNERTUBE_API_KEY': 'AIzaSyAOghZGza2MQSZkY_zfZ370N-PUdXEo8AI',
'INNERTUBE_CONTEXT': {
'client': {
'hl': 'en',
'gl': 'US',
'clientName': 'ANDROID_MUSIC',
'clientVersion': '6.44.54',
'osName': 'Android',
'osVersion': '14',
'androidSdkVersion': 34,
'platform': 'MOBILE',
'userAgent': 'com.google.android.apps.youtube.music/6.44.54 (Linux; U; Android 14; US) gzip'
}
},
'INNERTUBE_CONTEXT_CLIENT_NAME': 21,
'REQUIRE_JS_PLAYER': False
},
'android': { 'android': {
'INNERTUBE_API_KEY': 'AIzaSyA8eiZmM1FaDVjRy-df2KTyQ_vz_yYM39w', 'INNERTUBE_API_KEY': 'AIzaSyA8eiZmM1FaDVjRy-df2KTyQ_vz_yYM39w',
'INNERTUBE_CONTEXT': { 'INNERTUBE_CONTEXT': {
@@ -693,12 +669,12 @@ INNERTUBE_CLIENTS = {
'hl': 'en', 'hl': 'en',
'gl': 'US', 'gl': 'US',
'clientName': 'ANDROID', 'clientName': 'ANDROID',
'clientVersion': '19.12.36', 'clientVersion': '19.15.35',
'osName': 'Android', 'osName': 'Android',
'osVersion': '14', 'osVersion': '14',
'androidSdkVersion': 34, 'androidSdkVersion': 34,
'platform': 'MOBILE', 'platform': 'MOBILE',
'userAgent': 'com.google.android.youtube/19.13.36 (Linux; U; Android 14; en_US; Google Pixel 6 Pro) gzip' 'userAgent': 'com.google.android.youtube/19.15.35 (Linux; U; Android 14; en_US; Google Pixel 6 Pro) gzip'
} }
}, },
'INNERTUBE_CONTEXT_CLIENT_NAME': 3, 'INNERTUBE_CONTEXT_CLIENT_NAME': 3,
@@ -721,6 +697,25 @@ INNERTUBE_CLIENTS = {
'REQUIRE_JS_PLAYER': False 'REQUIRE_JS_PLAYER': False
}, },
'android_music': {
'INNERTUBE_API_KEY': 'AIzaSyAOghZGza2MQSZkY_zfZ370N-PUdXEo8AI',
'INNERTUBE_CONTEXT': {
'client': {
'hl': 'en',
'gl': 'US',
'clientName': 'ANDROID_MUSIC',
'clientVersion': '6.48.51',
'osName': 'Android',
'osVersion': '14',
'androidSdkVersion': 34,
'platform': 'MOBILE',
'userAgent': 'com.google.android.apps.youtube.music/6.48.51 (Linux; U; Android 14; US) gzip'
}
},
'INNERTUBE_CONTEXT_CLIENT_NAME': 21,
'REQUIRE_JS_PLAYER': False
},
# This client can access age restricted videos (unless the uploader has disabled the 'allow embedding' option) # This client can access age restricted videos (unless the uploader has disabled the 'allow embedding' option)
# See: https://github.com/zerodytrash/YouTube-Internal-Clients # See: https://github.com/zerodytrash/YouTube-Internal-Clients
'tv_embedded': { 'tv_embedded': {

View File

@@ -1,3 +1,3 @@
from __future__ import unicode_literals from __future__ import unicode_literals
__version__ = '0.2.15' __version__ = '0.2.16'

View File

@@ -2,6 +2,7 @@ import youtube
from youtube import yt_app from youtube import yt_app
from youtube import util, comments, local_playlist, yt_data_extract from youtube import util, comments, local_playlist, yt_data_extract
from youtube.util import time_utc_isoformat from youtube.util import time_utc_isoformat
from youtube.util import INNERTUBE_CLIENTS
import settings import settings
from flask import request from flask import request
@@ -343,7 +344,7 @@ def _add_to_error(info, key, additional_message):
def fetch_player_response(client, video_id): def fetch_player_response(client, video_id):
return util.call_youtube_api(client, 'player', { return util.call_youtube_api(client, 'player', {
'videoId': video_id, 'videoId': video_id,
'params': 'CgIIAQ==', 'params': 'CgIIAdgDAQ==',
}) })
@@ -369,10 +370,10 @@ def fetch_watch_page_info(video_id, playlist_id, index):
return yt_data_extract.extract_watch_info_from_html(watch_page) return yt_data_extract.extract_watch_info_from_html(watch_page)
def extract_info(video_id, use_invidious, playlist_id=None, index=None): def extract_info(video_id, use_invidious, playlist_id=None, index=None):
for client in INNERTUBE_CLIENTS:
tasks = ( tasks = (
# Get video metadata from here
gevent.spawn(fetch_watch_page_info, video_id, playlist_id, index), gevent.spawn(fetch_watch_page_info, video_id, playlist_id, index),
gevent.spawn(fetch_player_response, 'android', video_id) gevent.spawn(fetch_player_response, client, video_id) # Use client from INNERTUBE_CLIENTS
) )
gevent.joinall(tasks) gevent.joinall(tasks)
util.check_gevent_exceptions(*tasks) util.check_gevent_exceptions(*tasks)