Advertisement
Guest User

List YouTube commenters

a guest
Apr 22nd, 2019
182
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.88 KB | None | 0 0
  1. import requests
  2.  
  3. # Coded by Noxturnix
  4. # https://noxt.cf/
  5. # https://github.com/Noxturnix
  6.  
  7. url = input("YouTube URL: ")
  8. filename = "commenters.txt"
  9. #filename = input("Save to: ")
  10.  
  11. session = requests.Session()
  12.  
  13. headers = {
  14.     "User-Agent": "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/73.0.3683.103 Safari/537.36",
  15.     "X-YouTube-Client-Name": "1",
  16.     "X-YouTube-Client-Version": "2.20190420"
  17. }
  18.  
  19. resp = session.get(url, headers=headers)
  20. xsrf_token = resp.text.split("XSRF_TOKEN\":\"")[1].split("\"")[0]
  21. ctoken = resp.text.split("\"nextContinuationData\":{\"continuation\":\"")[1].split("\"")[0]
  22. itct = resp.text.split("\"{}\",\"clickTrackingParams\":\"".format(ctoken))[1].split("\"")[0]
  23.  
  24. commenters = []
  25.  
  26. while True:
  27.     print("Scrolling. please wait...")
  28.     params = {
  29.         "action_get_comments": "1",
  30.         "pbj": "1",
  31.         "ctoken": ctoken,
  32.         "continuation": ctoken,
  33.         "itct": itct
  34.     }
  35.     data = {
  36.         "session_token": xsrf_token
  37.     }
  38.     resp = session.post("https://www.youtube.com/comment_service_ajax", params=params, headers=headers, data=data)
  39.     jsonResp = resp.json()
  40.     doBreak = False
  41.     if "continuations" in jsonResp["response"]["continuationContents"]["itemSectionContinuation"]:
  42.         ctoken = jsonResp["response"]["continuationContents"]["itemSectionContinuation"]["continuations"][0]["nextContinuationData"]["continuation"]
  43.     else:
  44.         doBreak = True
  45.  
  46.     if "contents" in jsonResp["response"]["continuationContents"]["itemSectionContinuation"]:
  47.         for content in jsonResp["response"]["continuationContents"]["itemSectionContinuation"]["contents"]:
  48.             commenters.append(content["commentThreadRenderer"]["comment"]["commentRenderer"]["authorText"]["simpleText"])
  49.  
  50.     if doBreak:
  51.         break
  52.  
  53. commenters = list(set(commenters))
  54.  
  55. open(filename, "w").write("\n".join(commenters).strip())
  56. print("Saved {} name(s) (removed duplicates) to {}".format(len(commenters), filename))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement