diff options
| author | Samantaz Fox <coding@samantaz.fr> | 2021-06-25 17:53:07 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-06-25 17:53:07 +0200 |
| commit | 135ae11c201d12ee2fa1e1035976026570dfd96b (patch) | |
| tree | 87408145741a3e9076524eae7535c5730a5158ec /src | |
| parent | ce68d09d2653df27afea6d26d03838ce78b053cb (diff) | |
| parent | 50267a6dd60d8bb95c477e33e4824f8b19bc6424 (diff) | |
| download | invidious-135ae11c201d12ee2fa1e1035976026570dfd96b.tar.gz invidious-135ae11c201d12ee2fa1e1035976026570dfd96b.tar.bz2 invidious-135ae11c201d12ee2fa1e1035976026570dfd96b.zip | |
Merge pull request #2195 from B0pol/trending
Use youtubei API for trending
Diffstat (limited to 'src')
| -rw-r--r-- | src/invidious/helpers/youtube_api.cr | 10 | ||||
| -rw-r--r-- | src/invidious/trending.cr | 30 |
2 files changed, 15 insertions, 25 deletions
diff --git a/src/invidious/helpers/youtube_api.cr b/src/invidious/helpers/youtube_api.cr index e27d4088..734fddcd 100644 --- a/src/invidious/helpers/youtube_api.cr +++ b/src/invidious/helpers/youtube_api.cr @@ -25,12 +25,14 @@ end #################################################################### # request_youtube_api_browse(continuation) -# request_youtube_api_browse(browse_id, params) +# request_youtube_api_browse(browse_id, params, region) # # Requests the youtubei/v1/browse endpoint with the required headers -# and POST data in order to get a JSON reply in english US that can +# and POST data in order to get a JSON reply in english that can # be easily parsed. # +# The region can be provided, default is US. +# # The requested data can either be: # # - A continuation token (ctoken). Depending on this token's @@ -49,11 +51,11 @@ def request_youtube_api_browse(continuation : String) return _youtube_api_post_json("/youtubei/v1/browse", data) end -def request_youtube_api_browse(browse_id : String, params : String) +def request_youtube_api_browse(browse_id : String, params : String, region : String = "US") # JSON Request data, required by the API data = { "browseId" => browse_id, - "context" => make_youtube_api_context("US"), + "context" => make_youtube_api_context(region), } # Append the additionnal parameters if those were provided diff --git a/src/invidious/trending.cr b/src/invidious/trending.cr index 910a99d8..2ab1e7ba 100644 --- a/src/invidious/trending.cr +++ b/src/invidious/trending.cr @@ -2,31 +2,19 @@ def fetch_trending(trending_type, region, locale) region ||= "US" region = region.upcase - trending = "" plid = nil - if trending_type && trending_type != "Default" - if trending_type == "Music" - trending_type = 1 - elsif trending_type == "Gaming" - trending_type = 2 - elsif trending_type == "Movies" - trending_type = 3 - end - - response = YT_POOL.client &.get("/feed/trending?gl=#{region}&hl=en").body - - initial_data = extract_initial_data(response) - url = initial_data["contents"]["twoColumnBrowseResultsRenderer"]["tabs"][trending_type]["tabRenderer"]["endpoint"]["commandMetadata"]["webCommandMetadata"]["url"] - url = "#{url}&gl=#{region}&hl=en" - - trending = YT_POOL.client &.get(url).body - plid = extract_plid(url) - else - trending = YT_POOL.client &.get("/feed/trending?gl=#{region}&hl=en").body + if trending_type == "Music" + params = "4gINGgt5dG1hX2NoYXJ0cw%3D%3D" + elsif trending_type == "Gaming" + params = "4gIcGhpnYW1pbmdfY29ycHVzX21vc3RfcG9wdWxhcg%3D%3D" + elsif trending_type == "Movies" + params = "4gIKGgh0cmFpbGVycw%3D%3D" + else # Default + params = "" end - initial_data = extract_initial_data(trending) + initial_data = request_youtube_api_browse("FEtrending", params: params, region: region) trending = extract_videos(initial_data) return {trending, plid} |
