Youtube catcher

  • Welcome to skUnity!

    Welcome to skUnity! This is a forum where members of the Skript community can communicate and interact. Skript Resource Creators can post their Resources for all to see and use.

    If you haven't done so already, feel free to join our official Discord server to expand your level of interaction with the comminuty!

    Now, what are you waiting for? Join the community now!

aescraft

Well-Known Member
Mar 1, 2017
295
13
0
37
When someone posts a link to youtube, the skipt addon get the video name for broadcasts.
 
This is already possible. Heres some messy code I made for this. Requires skQuery, Reqn, TuSKe, skript-json and possibly some other stuff I'm forgetting.

code_language.skript:
function getYTID(u: text) :: objects:
  set {_r} to "(?:[?&]v=|\/embed\/|\/1\/|\/v\/|https:\/\/(?:www\.)?youtu\.be\/)([^&\n?##]+)"
  set {_g::*} to groups 1 of {_u} matched to {_r}
  set {_u::1} to {_g::1}
  set {_r} to "&list"
  replace all "§" in {_r} with "&"
  replace all "§" in {_u::1} with "&"
  if {_u::1} contains "%{_r}%":
    set {_s::*} to split {_u::1} at "%{_r}%"
    set {_u::1} to {_s::1}
  set {_u::2} to "https://www.googleapis.com/youtube/v3/videos?id=%{_u::1}%&key={@key}&part=snippet"
  replace all "§" in {_u::*} with "&"
  return {_u::*}
code_language.skript:
        if {_t::2} regex matches "^(https?\:\/\/)?(www\.)?(youtube\.com|youtu\.?be)\/.+$":
          set {_v::*} to getYTID({_t::2})
          send a request to "%{_v::2}%"
          set {_h} to last http response
          map json {_h}'s body to {_j::*}
          if {_j::pageInfo::resultsPerPage} is 0:
            set {_i} to true
          else:
            set {_i::1} to {_j::items::1::snippet::title}
            set {_i::2} to {_j::items::1::snippet::channeltitle}
            set {_i::3} to {_j::items::1::snippet::thumbnails::default::url}
            set {_i::4} to {_i}
where {_t::2} is a youtube URL
 
Last edited by a moderator:
This is already possible. Heres some messy code I made for this. Requires skQuery, Reqn, TuSKe, skript-json and possibly some other stuff I'm forgetting.

code_language.skript:
function getYTID(u: text) :: objects:
  set {_r} to "(?:[?&]v=|\/embed\/|\/1\/|\/v\/|https:\/\/(?:www\.)?youtu\.be\/)([^&\n?##]+)"
  set {_g::*} to groups 1 of {_u} matched to {_r}
  set {_u::1} to {_g::1}
  set {_r} to "&list"
  replace all "§" in {_r} with "&"
  replace all "§" in {_u::1} with "&"
  if {_u::1} contains "%{_r}%":
    set {_s::*} to split {_u::1} at "%{_r}%"
    set {_u::1} to {_s::1}
  set {_u::2} to "https://www.googleapis.com/youtube/v3/videos?id=%{_u::1}%&key={@key}&part=snippet"
  replace all "§" in {_u::*} with "&"
  return {_u::*}
code_language.skript:
        if {_t::2} regex matches "^(https?\:\/\/)?(www\.)?(youtube\.com|youtu\.?be)\/.+$":
          set {_v::*} to getYTID({_t::2})
          send a request to "%{_v::2}%"
          set {_h} to last http response
          map json {_h}'s body to {_j::*}
          if {_j::pageInfo::resultsPerPage} is 0:
            set {_i} to true
          else:
            set {_i::1} to {_j::items::1::snippet::title}
            set {_i::2} to {_j::items::1::snippet::channeltitle}
            set {_i::3} to {_j::items::1::snippet::thumbnails::default::url}
            set {_i::4} to {_i}
where {_t::2} is a youtube URL
Wow, can you describe the code for me? Some stuff there is new for me.
 
You can use the regex replace expression of TuSKe instead of that and you can get rid of skQuery.
I tried that, but I couldn't figure out the issue I was having with it, and neither could Tuke, so I just used skquery.

Wow, can you describe the code for me? Some stuff there is new for me.
I can't really explain it, but for the first function if you give it a youtube url, it will spit out both a list where the first value is the ID and the second is the URL to the api with the ID included. For the second one you send a request to google's api then map the json response to a list variable and then I just make it easy to remember by assigning the title, channel and thumbnail to a easy to use and remember list variable. To use these you need a youtube API key which is free but you'll have to either hardcore it in or use it as an option (i use the option "key" in that example)
 
Last edited by a moderator: