Guest User

nice code(i'm cry)

a guest
Jan 8th, 2021
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 68.00 KB | None | 0 0
  1. import requests
  2. import json
  3. import re
  4. import time
  5. import sys
  6. import base64
  7. import datetime
  8. import os
  9.  
  10. from bs4 import BeautifulSoup as bs
  11. from itertools import chain, starmap
  12. import requests as beg
  13. from bs4 import BeautifulSoup as sidenie
  14.  
  15.  
  16. # NET_TO_COOKIE
  17. def net_to_cookie(filename, service):
  18. cookies = {}
  19. try:
  20. with open(filename, 'r', encoding='utf-8') as fp:
  21. for line in fp:
  22. try:
  23. if not re.match(r'^\#', line) and service in line:
  24. lineFields = line.strip().split('\t')
  25. cookies[lineFields[5]] = lineFields[6]
  26. except Exception as err:
  27. continue
  28. except UnicodeDecodeError:
  29. with open(filename, 'r') as fp:
  30. for line in fp:
  31. try:
  32. if not re.match(r'^\#', line) and service in line:
  33. lineFields = line.strip().split('\t')
  34. cookies[lineFields[5]] = lineFields[6]
  35. except Exception as err:
  36. continue
  37. return cookies
  38.  
  39.  
  40. def get_json_settings_from_file(file_name):
  41. try:
  42. settings_data = work_with_file(file_name, read_mode='read')
  43. settings_data = json.loads(settings_data)
  44. return settings_data
  45. except json.decoder.JSONDecodeError:
  46. print('не удалось считать файл settings.json\n' \
  47. 'просмотрите пример указаный в описании\n' \
  48. 'или же указана неправильная кодировка файла, необходимая кодировка utf-8')
  49. input()
  50. sys.exit()
  51. except Exception as e:
  52. print(f'ошибка {e} при загрузке файла settings.json')
  53. input()
  54. sys.exit()
  55.  
  56.  
  57. def get_json_data_from_file(data, key_, int_=False):
  58. try:
  59. if int_:
  60. return int(data[key_])
  61. else:
  62. return data[key_]
  63. except ValueError:
  64. print(f'ошибка при считывании числа c поля {key_}')
  65. input()
  66. sys.exit()
  67. except Exception as e:
  68. print(f'ошибка {e} при считывании поля {key_}')
  69. input()
  70. sys.exit()
  71.  
  72.  
  73. def work_with_file(file_name, mode='r', write_data=None, encoding='utf-8', read_mode='read'):
  74. with open(file_name, mode=mode, encoding=encoding) as f:
  75. if mode == 'w' or mode == 'a':
  76. f.write(write_data)
  77. elif mode == 'r':
  78. if read_mode == 'read':
  79. data = f.read()
  80. elif read_mode == 'readlines':
  81. data = [data.replace('\n', '') for data in f.readlines()]
  82. else:
  83. raise Exception(f'invalid read_mode {read_mode}')
  84.  
  85. return data
  86.  
  87.  
  88. def all_accounts(cookies):
  89. r = requests.get('https://www.youtube.com/channel_switcher?next=%2Faccount&feature=settings', cookies=cookies)
  90.  
  91. # with open("all_accounts.txt", "w", encoding="utf-8") as f:
  92. # f.write(r.text)
  93.  
  94. soup = bs(r.text, 'html.parser')
  95.  
  96. res = []
  97. all_channel_urls = soup.find_all('div', attrs={'class':'highlight'})
  98. for i in all_channel_urls:
  99. res.append(i.find('a', attrs={'class':'yt-uix-button yt-uix-sessionlink yt-uix-button-default yt-uix-button-size-default'}).get('href'))
  100.  
  101. return res
  102.  
  103. # COOKIES_TO_HEADER
  104. def cookies_to_header(cookies, mode='dict'):
  105. levi = ''
  106. for key, value in cookies.items():
  107. levi += f'{key}={value}; '
  108. headers = {
  109. 'Cookie':levi[0:-1]
  110. }
  111. if mode == 'dict':
  112. return headers
  113. return levi
  114.  
  115.  
  116. # FORMAT_JSON
  117. def format_json(dictionary):
  118. """ Структурироване JSON данных для улучшения поиска """
  119.  
  120. def unpack(parent_key, parent_value):
  121. """ Рекурсивное распаковывание JSON данных """
  122. if isinstance(parent_value, dict):
  123. for key, value in parent_value.items():
  124. temp1 = parent_key + '_' + key
  125. yield temp1, value
  126. elif isinstance(parent_value, list):
  127. i = 0
  128. for value in parent_value:
  129. temp2 = parent_key + '_' + str(i)
  130. i += 1
  131. yield temp2, value
  132. else:
  133. yield parent_key, parent_value
  134.  
  135. while "True":
  136. dictionary = dict(chain.from_iterable(
  137. starmap(unpack, dictionary.items())))
  138. if not any(isinstance(value, dict) for value in dictionary.values()) and \
  139. not any(isinstance(value, list) for value in dictionary.values()):
  140. break
  141.  
  142. return dictionary
  143.  
  144.  
  145. # GET_CHANNEL_ID
  146. def get_channel_id(session, my_cookies, headers):
  147. r = session.get('https://studio.youtube.com/', cookies = my_cookies, headers=headers)
  148. r = session.get('https://studio.youtube.com/channel/?approve_browser_access=1', cookies = my_cookies, headers=headers)
  149.  
  150. # with open("get_channel_id.txt", "w", encoding="utf-8") as f:
  151. # f.write(r.text)
  152.  
  153. channelId = r.text.split('"channelId":"')[1].split('"')[0]
  154. ide = r.text.split('"DATASYNC_ID":"')[1].split('"')[0]
  155. api_key = r.text.split('"INNERTUBE_API_KEY":"')[1].split('"')[0]
  156.  
  157. start = " window.chunkedPrefetchResolvers['id-0'].resolve("
  158. end = ");"
  159.  
  160. try:
  161. html = r.text.split(start)[1].split(end)[0]
  162. json_data = json.loads(html)
  163. formatted_json_data = format_json(json_data)
  164. except Exception as e:
  165. return
  166.  
  167. return formatted_json_data, channelId, ide, api_key
  168.  
  169.  
  170. def check_all_account(links, my_cookies):
  171. all_accs = ''
  172. dict2 = my_cookies
  173. accounts = {}
  174. counter = 1
  175. for i in links:
  176. session = requests.Session()
  177. # print(i) # links
  178. r = session.get(f"https://www.youtube.com{i}", cookies=dict2)
  179.  
  180. dict3 = session.cookies.get_dict()
  181. dict2.update(dict3)
  182. resss = dict2
  183. headers = cookies_to_header(resss)
  184. try:
  185. formatted_json_data, channelId, ide, api_key = get_channel_id(session, resss, headers)
  186.  
  187. title = formatted_json_data['title']
  188. accounts[counter] = [dict2, session, title, ide, channelId, api_key]
  189.  
  190. subscribers = formatted_json_data['metric_subscriberCount']
  191. timeunic = formatted_json_data['timeCreatedSeconds']
  192. timeunic = datetime.datetime.fromtimestamp(int(timeunic)).strftime('%Y-%m-%d')
  193. monetized = formatted_json_data['isMonetized']
  194. verified = formatted_json_data['isNameVerified']
  195. all_accs += f'account №{counter}, subs:{subscribers}, monetized: {monetized}, verified: {verified}, created: {timeunic}, name: {title}\n'
  196. counter += 1
  197. except Exception:
  198. continue
  199.  
  200. return accounts, all_accs
  201.  
  202.  
  203. def choose_account(accounts, selected_acc):
  204. try:
  205. cook = accounts[selected_acc][0]
  206. session = accounts[selected_acc][1]
  207. title = accounts[selected_acc][2]
  208. ide = accounts[selected_acc][3]
  209. channelId = accounts[selected_acc][4]
  210. api_key = accounts[selected_acc][5]
  211. return cook, session, title, ide, channelId, api_key
  212. except Exception as e:
  213. print('3', e)
  214. print('выбран неверный аккаунт')
  215.  
  216.  
  217. def get_header(session, channelId, my_cookies):
  218. try:
  219.  
  220. headers = cookies_to_header(my_cookies)
  221. r = session.get(f'https://studio.youtube.com/channel/{channelId}/livestreaming', cookies = my_cookies, headers=headers)
  222. r = session.get('https://studio.youtube.com/channel/?approve_browser_access=1', cookies = my_cookies, headers=headers)
  223.  
  224. if '<title>YouTube</title>' in r.text:
  225. print('не удалось войти в studio youtube')
  226. return
  227.  
  228. unix_time = get_unix_time()
  229.  
  230. headers = {}
  231.  
  232. headers['referer'] = f'https://studio.youtube.com/channel/{channelId}/livestreaming'
  233.  
  234. try:
  235. authorization = get_hash(f'{unix_time} {my_cookies.get("SAPISID")} https://studio.youtube.com')
  236. authorization = f'SAPISIDHASH {unix_time}_{authorization}'
  237. headers['authorization'] = authorization
  238. # headers['authorization'] = "SAPISIDHASH 1609150969_b144ab3586c89ff900cd783d66ca5d5fa63db8a0"
  239. except Exception as e:
  240. print(e)
  241. cookies = net_to_cookie("cookies.txt", "google")
  242.  
  243. try:
  244. sapicid = cookies["SAPISID"]
  245. authorization = get_hash(f'{unix_time} {sapicid} https://studio.youtube.com')
  246. authorization = f'SAPISIDHASH {unix_time}_{authorization}'
  247. headers['authorization'] = authorization
  248. except Exception as e:
  249. print(e)
  250. return "нету SAPISID"
  251. # print(e)
  252. # return
  253.  
  254. my_header_cookies = cookies_to_header(my_cookies)
  255. headers['Cookie'] = my_header_cookies['Cookie']
  256.  
  257. headers['x-goog-authuser'] = '0'
  258.  
  259. goog_visitor_id = r.text.split('"visitorData":"')[1].split('"')[0]
  260. headers['x-goog-visitor-id'] = goog_visitor_id
  261.  
  262. youtube_client_version = r.text.split('"INNERTUBE_CONTEXT_CLIENT_VERSION":"')[1].split('"')[0]
  263. headers['x-youtube-client-version'] = youtube_client_version
  264.  
  265. youtube_page_label = r.text.split('"productVersion":"')[1].split('"')[0]
  266. headers['x-youtube-page-label'] = youtube_page_label
  267.  
  268. headers['x-origin'] = 'https://studio.youtube.com'
  269.  
  270. headers['user-agent'] = 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/85.0.4183.121 Safari/537.36'
  271. except Exception as e:
  272. # print('1', e)
  273. return
  274.  
  275. return headers
  276.  
  277. # GET_UNIX_TIME
  278. def get_unix_time():
  279. return int(time.time())
  280.  
  281. # GET_HASH
  282. def get_hash(text):
  283. data = {'textToHash':text,
  284. 'hash-algorithm-used':'sha1'}
  285. r = requests.post('http://www.sha1-online.com/', data = data)
  286. soup = bs(r.text, 'html.parser')
  287. result = soup.find('span', attrs={'id':'result-sha1'})
  288. return result.text
  289.  
  290. def get_ide_for_update(ide):
  291. ide = ide.split('||')
  292. if len(ide) == 2 and ide[1] == '':
  293. user = ""
  294. elif len(ide) == 2 and ide[1] != '':
  295. user = ide[0]
  296. else:
  297. input('Ошибка при создании стрима')
  298. sys.exit()
  299. return user
  300.  
  301. def main_change(session, videoId, image, tags, category, ChannelId, Title, Description, headers, api_key, my_cookies, ide):
  302. user = get_ide_for_update(ide)
  303. with open(image, "rb") as image_file:
  304. encoded_string = base64.b64encode(image_file.read()).decode()
  305.  
  306. if user:
  307. data = {"encryptedVideoId":videoId,"videoReadMask":{"channelId":True,"license":True,"publishing":{"all":True},"tags":{"all":True},"videoTrailers":{"all":True},"premiere":{"all":True},"gameTitle":{"all":True},"privacy":True,"titleFormattedString":{"all":True},"defaultCommentSortOrder":True,"livestream":{"all":True},"thumbnailEditorState":{"all":True},"description":True,"downloadUrl":True,"unlistedExpired":True,"videoPrechecks":{"all":True},"videoAdvertiserSpecificAgeGates":{"all":True},"visibility":{"all":True},"liveChat":{"all":True},"crowdsourcingEnabled":True,"thumbnailDetails":{"all":True},"selfCertification":{"all":True},"paidProductPlacement":True,"statusDetails":{"all":True},"origin":True,"sponsorsOnly":{"all":True},"videoStreamUrl":True,"ownedClaimDetails":{"all":True},"videoEditorProject":{"all":True},"originalFilename":True,"commentsDisabledInternally":True,"inlineEditProcessingStatus":True,"commentFilter":True,"location":{"all":True},"uncaptionedReason":True,"permissions":{"all":True},"descriptionFormattedString":{"all":True},"videoResolutions":{"all":True},"audienceRestriction":{"all":True},"responseStatus":{"all":True},"viewCountIsHidden":True,"audioLanguage":{"all":True},"allowComments":True,"allowEmbed":True,"status":True,"allowRatings":True,"videoDurationMs":True,"allRestrictions":{"all":True},"timePublishedSeconds":True,"metadataLanguage":{"all":True},"claimDetails":{"all":True},"features":{"all":True},"watchUrl":True,"timeCreatedSeconds":True,"dateRecorded":{"all":True},"videoId":True,"title":True,"category":True,"lengthSeconds":True,"draftStatus":True,"music":{"all":True},"scheduledPublishingDetails":{"all":True}},"title":{"newTitle":Title,"shouldSegment":True},"description":{"newDescription":Description,"shouldSegment":True},"videoStill":{"operation":"UPLOAD_CUSTOM_THUMBNAIL","image":{"dataUri":f"data:image/jpeg;base64,{encoded_string}"}},"tags":{"newTags":tags},"category":{"newCategoryId":category},"context":{"client":{"clientName":62,"clientVersion":"1.20201021.02.01-canary_control","hl":"ru","gl":"RU","experimentsToken":""},"request":{"returnLogEntry":True,"internalExperimentFlags":[{"key":"force_live_chat_merchandise_upsell","value":"False"},{"key":"force_route_delete_playlist_to_outertube","value":"False"}],"sessionInfo":{"token":"AbX5usaBxohyRP8Fvdefz5dZBGpfZelYW0jCPR9UPesyDalZ3-IIeVUl6NJ3hDIcS5kIYiAYXtG4MrSWTX_H84rufEd8ww=="}},"user":{"onBehalfOfUser":user,"delegationContext":{"externalChannelId":ChannelId,"roleType":{"channelRoleType":"CREATOR_CHANNEL_ROLE_TYPE_OWNER"}},"serializedDelegationContext":"EhhVQ212VzRKN3FrUi1BUFMwdW50YkttLVEqAggI"},"clientScreenNonce":"MC44NTU5MDg5Njg1ODQ5Nzc3"},"delegationContext":{"externalChannelId":ChannelId,"roleType":{"channelRoleType":"CREATOR_CHANNEL_ROLE_TYPE_OWNER"}}}
  308. else:
  309. data = {"encryptedVideoId":videoId,"videoReadMask":{"channelId":True,"license":True,"publishing":{"all":True},"tags":{"all":True},"videoTrailers":{"all":True},"premiere":{"all":True},"gameTitle":{"all":True},"privacy":True,"titleFormattedString":{"all":True},"defaultCommentSortOrder":True,"livestream":{"all":True},"thumbnailEditorState":{"all":True},"description":True,"downloadUrl":True,"unlistedExpired":True,"videoPrechecks":{"all":True},"videoAdvertiserSpecificAgeGates":{"all":True},"visibility":{"all":True},"liveChat":{"all":True},"crowdsourcingEnabled":True,"thumbnailDetails":{"all":True},"selfCertification":{"all":True},"paidProductPlacement":True,"statusDetails":{"all":True},"origin":True,"sponsorsOnly":{"all":True},"videoStreamUrl":True,"ownedClaimDetails":{"all":True},"videoEditorProject":{"all":True},"originalFilename":True,"commentsDisabledInternally":True,"inlineEditProcessingStatus":True,"commentFilter":True,"location":{"all":True},"uncaptionedReason":True,"permissions":{"all":True},"descriptionFormattedString":{"all":True},"videoResolutions":{"all":True},"audienceRestriction":{"all":True},"responseStatus":{"all":True},"viewCountIsHidden":True,"audioLanguage":{"all":True},"allowComments":True,"allowEmbed":True,"status":True,"allowRatings":True,"videoDurationMs":True,"allRestrictions":{"all":True},"timePublishedSeconds":True,"metadataLanguage":{"all":True},"claimDetails":{"all":True},"features":{"all":True},"watchUrl":True,"timeCreatedSeconds":True,"dateRecorded":{"all":True},"videoId":True,"title":True,"category":True,"lengthSeconds":True,"draftStatus":True,"music":{"all":True},"scheduledPublishingDetails":{"all":True}},"title":{"newTitle":Title,"shouldSegment":True},"description":{"newDescription":Description,"shouldSegment":True},"videoStill":{"operation":"UPLOAD_CUSTOM_THUMBNAIL","image":{"dataUri":f"data:image/jpeg;base64,{encoded_string}"}},"tags":{"newTags":tags},"category":{"newCategoryId":category},"context":{"client":{"clientName":62,"clientVersion":"1.20201021.02.01-canary_control","hl":"ru","gl":"RU","experimentsToken":""},"request":{"returnLogEntry":True,"internalExperimentFlags":[{"key":"force_live_chat_merchandise_upsell","value":"False"},{"key":"force_route_delete_playlist_to_outertube","value":"False"}],"sessionInfo":{"token":"AbX5usaBxohyRP8Fvdefz5dZBGpfZelYW0jCPR9UPesyDalZ3-IIeVUl6NJ3hDIcS5kIYiAYXtG4MrSWTX_H84rufEd8ww=="}},"user":{"delegationContext":{"externalChannelId":ChannelId,"roleType":{"channelRoleType":"CREATOR_CHANNEL_ROLE_TYPE_OWNER"}},"serializedDelegationContext":"EhhVQ212VzRKN3FrUi1BUFMwdW50YkttLVEqAggI"},"clientScreenNonce":"MC44NTU5MDg5Njg1ODQ5Nzc3"},"delegationContext":{"externalChannelId":ChannelId,"roleType":{"channelRoleType":"CREATOR_CHANNEL_ROLE_TYPE_OWNER"}}}
  310.  
  311.  
  312. r = session.post(f'https://studio.youtube.com/youtubei/v1/video_manager/metadata_update?alt=json&key={api_key}',
  313. json=data,
  314. headers=headers,
  315. cookies=my_cookies)
  316.  
  317. # print(bs(r.text).text)
  318. # 1/0
  319.  
  320.  
  321. with open("main_change.txt", "w", encoding="utf-8") as f:
  322. f.write(r.text)
  323.  
  324. if '"resultCode": "UPDATE_SUCCESS"' in r.text:
  325. return 'OK'
  326. else:
  327. return 'Ошибка изменения стрима'
  328.  
  329.  
  330. def check_likes(session, ChannelId, VideoId, api_key, headers, my_cookies, ide, likess):
  331. user = get_ide_for_update(ide)
  332.  
  333. if likess:
  334. if user:
  335. data = {"encryptedVideoId":VideoId,"videoReadMask":{"permissions":{"all":True},"description":True,"videoDurationMs":True,"origin":True,"thumbnailDetails":{"all":True},"category":True,"uncaptionedReason":True,"allowComments":True,"livestream":{"all":True},"descriptionFormattedString":{"all":True},"publishing":{"all":True},"draftStatus":True,"features":{"all":True},"tags":{"all":True},"crowdsourcingEnabled":True,"downloadUrl":True,"metadataLanguage":{"all":True},"inlineEditProcessingStatus":True,"allowRatings":True,"license":True,"channelId":True,"viewCountIsHidden":True,"defaultCommentSortOrder":True,"lengthSeconds":True,"thumbnailEditorState":{"all":True},"premiere":{"all":True},"unlistedExpired":True,"videoTrailers":{"all":True},"commentsDisabledInternally":True,"allowEmbed":True,"audioLanguage":{"all":True},"dateRecorded":{"all":True},"commentFilter":True,"liveChat":{"all":True},"videoResolutions":{"all":True},"claimDetails":{"all":True},"selfCertification":{"all":True},"paidProductPlacement":True,"audienceRestriction":{"all":True},"visibility":{"all":True},"videoId":True,"privacy":True,"timePublishedSeconds":True,"videoAdvertiserSpecificAgeGates":{"all":True},"titleFormattedString":{"all":True},"videoPrechecks":{"all":True},"responseStatus":{"all":True},"location":{"all":True},"music":{"all":True},"allRestrictions":{"all":True},"sponsorsOnly":{"all":True},"status":True,"videoStreamUrl":True,"scheduledPublishingDetails":{"all":True},"gameTitle":{"all":True},"watchUrl":True,"timeCreatedSeconds":True,"videoEditorProject":{"all":True},"title":True,"originalFilename":True,"ownedClaimDetails":{"all":True},"statusDetails":{"all":True}},"commentOptions":{"newAllowComments":True,"newAllowCommentsMode":"AUTOMATED_COMMENTS","newCanViewRatings":True,"newDefaultSortOrder":"MDE_COMMENT_SORT_ORDER_TOP"},"context":{"client":{"clientName":62,"clientVersion":"1.20201102.01.01","hl":"ru","gl":"RU","experimentsToken":""},"request":{"returnLogEntry":True,"internalExperimentFlags":[{"key":"force_route_delete_playlist_to_outertube","value":"False"},{"key":"force_live_chat_merchandise_upsell","value":"False"}],"sessionInfo":{"token":"AbX5usaBxohyRP8Fvdefz5dZBGpfZelYW0jCPR9UPesyDalZ3-IIeVUl6NJ3hDIcS5kIYiAYXtG4MrSWTX_H84rufEd8ww=="}},"user":{"onBehalfOfUser":user,"delegationContext":{"roleType":{"channelRoleType":"CREATOR_CHANNEL_ROLE_TYPE_OWNER"},"externalChannelId":ChannelId},"serializedDelegationContext":"EhhVQ2Q5QTh1azRreXVUMkYyQ29JOGg1clEqAggI"},"clientScreenNonce":"MC4yMjgwMzczNTM4ODQyMDMzMg.."},"delegationContext":{"roleType":{"channelRoleType":"CREATOR_CHANNEL_ROLE_TYPE_OWNER"},"externalChannelId":ChannelId}}
  336. else:
  337. data = {"encryptedVideoId":VideoId,"videoReadMask":{"dateRecorded":{"all":True},"selfCertification":{"all":True},"titleFormattedString":{"all":True},"status":True,"permissions":{"all":True},"timeCreatedSeconds":True,"videoTrailers":{"all":True},"metadataLanguage":{"all":True},"audienceRestriction":{"all":True},"commentsDisabledInternally":True,"videoEditorProject":{"all":True},"livestream":{"all":True},"allRestrictions":{"all":True},"videoStreamUrl":True,"license":True,"description":True,"allowEmbed":True,"crowdsourcingEnabled":True,"responseStatus":{"all":True},"draftStatus":True,"videoPrechecks":{"all":True},"thumbnailEditorState":{"all":True},"viewCountIsHidden":True,"videoAdvertiserSpecificAgeGates":{"all":True},"features":{"all":True},"videoResolutions":{"all":True},"thumbnailDetails":{"all":True},"statusDetails":{"all":True},"watchUrl":True,"timePublishedSeconds":True,"premiere":{"all":True},"videoDurationMs":True,"descriptionFormattedString":{"all":True},"lengthSeconds":True,"publishing":{"all":True},"uncaptionedReason":True,"claimDetails":{"all":True},"origin":True,"scheduledPublishingDetails":{"all":True},"videoId":True,"liveChat":{"all":True},"unlistedExpired":True,"paidProductPlacement":True,"location":{"all":True},"commentFilter":True,"visibility":{"all":True},"music":{"all":True},"channelId":True,"originalFilename":True,"tags":{"all":True},"allowComments":True,"allowRatings":True,"defaultCommentSortOrder":True,"downloadUrl":True,"title":True,"ownedClaimDetails":{"all":True},"sponsorsOnly":{"all":True},"privacy":True,"inlineEditProcessingStatus":True,"audioLanguage":{"all":True},"gameTitle":{"all":True},"category":True},"commentOptions":{"newAllowComments":True,"newAllowCommentsMode":"AUTOMATED_COMMENTS","newCanViewRatings":True,"newDefaultSortOrder":"MDE_COMMENT_SORT_ORDER_TOP"},"context":{"client":{"clientName":62,"clientVersion":"1.20201102.01.01-canary_control","hl":"ru","gl":"RU","experimentsToken":""},"request":{"returnLogEntry":True,"internalExperimentFlags":[{"key":"force_route_delete_playlist_to_outertube","value":"false"},{"key":"force_live_chat_merchandise_upsell","value":"false"}],"sessionInfo":{"token":"AbX5usaBxohyRP8Fvdefz5dZBGpfZelYW0jCPR9UPesyDalZ3-IIeVUl6NJ3hDIcS5kIYiAYXtG4MrSWTX_H84rufEd8ww=="}},"user":{"delegationContext":{"roleType":{"channelRoleType":"CREATOR_CHANNEL_ROLE_TYPE_OWNER"},"externalChannelId":ChannelId},"serializedDelegationContext":"EhhVQ212VzRKN3FrUi1BUFMwdW50YkttLVEqAggI"},"clientScreenNonce":"MC43MDA2OTUxNjQ3OTk2MTEx"},"delegationContext":{"roleType":{"channelRoleType":"CREATOR_CHANNEL_ROLE_TYPE_OWNER"},"externalChannelId":ChannelId}}
  338. r = session.post(f'https://studio.youtube.com/youtubei/v1/video_manager/metadata_update?alt=json&key={api_key}',
  339. json=data, headers=headers, cookies=my_cookies)
  340.  
  341. # with open("check_likes.txt", "w", encoding="utf-8") as f:
  342. # f.write(r.text)
  343.  
  344. if '"resultCode": "UPDATE_SUCCESS"' in r.text:
  345. return 'лайки включены'
  346. else:
  347. return 'не удалось включить лайки'
  348. else:
  349. if user:
  350. data = {"encryptedVideoId":VideoId,"videoReadMask":{"title":True,"originalFilename":True,"premiere":{"all":True},"allowEmbed":True,"responseStatus":{"all":True},"scheduledPublishingDetails":{"all":True},"permissions":{"all":True},"timeCreatedSeconds":True,"titleFormattedString":{"all":True},"tags":{"all":True},"crowdsourcingEnabled":True,"uncaptionedReason":True,"allowComments":True,"commentFilter":True,"privacy":True,"videoDurationMs":True,"status":True,"commentsDisabledInternally":True,"livestream":{"all":True},"license":True,"videoId":True,"metadataLanguage":{"all":True},"publishing":{"all":True},"videoTrailers":{"all":True},"videoEditorProject":{"all":True},"dateRecorded":{"all":True},"thumbnailDetails":{"all":True},"lengthSeconds":True,"videoStreamUrl":True,"statusDetails":{"all":True},"watchUrl":True,"location":{"all":True},"audioLanguage":{"all":True},"features":{"all":True},"timePublishedSeconds":True,"sponsorsOnly":{"all":True},"origin":True,"ownedClaimDetails":{"all":True},"claimDetails":{"all":True},"allRestrictions":{"all":True},"descriptionFormattedString":{"all":True},"videoPrechecks":{"all":True},"draftStatus":True,"videoResolutions":{"all":True},"allowRatings":True,"music":{"all":True},"thumbnailEditorState":{"all":True},"paidProductPlacement":True,"videoAdvertiserSpecificAgeGates":{"all":True},"gameTitle":{"all":True},"unlistedExpired":True,"inlineEditProcessingStatus":True,"defaultCommentSortOrder":True,"downloadUrl":True,"liveChat":{"all":True},"channelId":True,"category":True,"audienceRestriction":{"all":True},"visibility":{"all":True},"viewCountIsHidden":True,"description":True},"commentOptions":{"newAllowComments":True,"newAllowCommentsMode":"AUTOMATED_COMMENTS","newCanViewRatings":False,"newDefaultSortOrder":"MDE_COMMENT_SORT_ORDER_TOP"},"context":{"client":{"clientName":62,"clientVersion":"1.20201014.02.00","hl":"ru","gl":"RU","experimentsToken":""},"request":{"returnLogEntry":True,"internalExperimentFlags":[{"key":"force_live_chat_merchandise_upsell","value":"False"},{"key":"force_route_delete_playlist_to_outertube","value":"False"}],"sessionInfo":{"token":"AbX5usaBxohyRP8Fvdefz5dZBGpfZelYW0jCPR9UPesyDalZ3-IIeVUl6NJ3hDIcS5kIYiAYXtG4MrSWTX_H84rufEd8ww=="}},"user":{"onBehalfOfUser":user,"delegationContext":{"roleType":{"channelRoleType":"CREATOR_CHANNEL_ROLE_TYPE_OWNER"},"externalChannelId":ChannelId},"serializedDelegationContext":"EhhVQ2Q5QTh1azRreXVUMkYyQ29JOGg1clEqAggI"},"clientScreenNonce":"MC40MTY4MjkxODEwNzc4NTEz"},"delegationContext":{"roleType":{"channelRoleType":"CREATOR_CHANNEL_ROLE_TYPE_OWNER"},"externalChannelId":ChannelId}}
  351. else:
  352. data = {"encryptedVideoId":VideoId,"videoReadMask":{"lengthSeconds":True,"channelId":True,"commentFilter":True,"draftStatus":True,"privacy":True,"thumbnailDetails":{"all":True},"watchUrl":True,"ownedClaimDetails":{"all":True},"publishing":{"all":True},"title":True,"allowComments":True,"originalFilename":True,"category":True,"features":{"all":True},"inlineEditProcessingStatus":True,"tags":{"all":True},"paidProductPlacement":True,"videoAdvertiserSpecificAgeGates":{"all":True},"license":True,"location":{"all":True},"visibility":{"all":True},"metadataLanguage":{"all":True},"audioLanguage":{"all":True},"status":True,"videoPrechecks":{"all":True},"videoResolutions":{"all":True},"responseStatus":{"all":True},"uncaptionedReason":True,"downloadUrl":True,"videoId":True,"timeCreatedSeconds":True,"permissions":{"all":True},"gameTitle":{"all":True},"livestream":{"all":True},"music":{"all":True},"crowdsourcingEnabled":True,"timePublishedSeconds":True,"unlistedExpired":True,"viewCountIsHidden":True,"premiere":{"all":True},"commentsDisabledInternally":True,"dateRecorded":{"all":True},"defaultCommentSortOrder":True,"origin":True,"sponsorsOnly":{"all":True},"thumbnailEditorState":{"all":True},"description":True,"allowRatings":True,"videoDurationMs":True,"audienceRestriction":{"all":True},"videoStreamUrl":True,"allRestrictions":{"all":True},"videoTrailers":{"all":True},"claimDetails":{"all":True},"statusDetails":{"all":True},"titleFormattedString":{"all":True},"descriptionFormattedString":{"all":True},"videoEditorProject":{"all":True},"liveChat":{"all":True},"scheduledPublishingDetails":{"all":True},"allowEmbed":True},"commentOptions":{"newAllowComments":True,"newAllowCommentsMode":"AUTOMATED_COMMENTS","newCanViewRatings":False,"newDefaultSortOrder":"MDE_COMMENT_SORT_ORDER_TOP"},"liveChat":{"newLiveChatSettings":{"liveChatEnabled":False},"newLiveChatSettingsMask":{"liveChatEnabled":True}},"context":{"client":{"clientName":62,"clientVersion":"1.20201014.02.00","hl":"ru","gl":"RU","experimentsToken":""},"request":{"returnLogEntry":True,"internalExperimentFlags":[{"key":"force_route_delete_playlist_to_outertube","value":"False"},{"key":"force_live_chat_merchandise_upsell","value":"False"}],"sessionInfo":{"token":"AbX5usaBxohyRP8Fvdefz5dZBGpfZelYW0jCPR9UPesyDalZ3-IIeVUl6NJ3hDIcS5kIYiAYXtG4MrSWTX_H84rufEd8ww=="}},"user":{"delegationContext":{"externalChannelId":ChannelId,"roleType":{"channelRoleType":"CREATOR_CHANNEL_ROLE_TYPE_OWNER"}},"serializedDelegationContext":"EhhVQ212VzRKN3FrUi1BUFMwdW50YkttLVEqAggI"},"clientScreenNonce":"MC4zMjA1MTc3MTYwNTgxNTY5Mw.."},"delegationContext":{"externalChannelId":ChannelId,"roleType":{"channelRoleType":"CREATOR_CHANNEL_ROLE_TYPE_OWNER"}}}
  353. r = session.post(f'https://studio.youtube.com/youtubei/v1/video_manager/metadata_update?alt=json&key={api_key}',
  354. json=data, headers=headers, cookies=my_cookies)
  355.  
  356. if '"resultCode": "UPDATE_SUCCESS"' in r.text:
  357. return 'лайки отключены'
  358. else:
  359. return 'не удалось отключить лайки'
  360.  
  361.  
  362.  
  363. def check_chat(session, ChannelId, VideoId, api_key, headers, my_cookies, ide, chatt):
  364. user = get_ide_for_update(ide)
  365.  
  366. if chatt:
  367. if user:
  368. data = {"encryptedVideoId":VideoId,"videoReadMask":{"permissions":{"all":True},"description":True,"videoDurationMs":True,"origin":True,"thumbnailDetails":{"all":True},"category":True,"uncaptionedReason":True,"allowComments":True,"livestream":{"all":True},"descriptionFormattedString":{"all":True},"publishing":{"all":True},"draftStatus":True,"features":{"all":True},"tags":{"all":True},"crowdsourcingEnabled":True,"downloadUrl":True,"metadataLanguage":{"all":True},"inlineEditProcessingStatus":True,"allowRatings":True,"license":True,"channelId":True,"viewCountIsHidden":True,"defaultCommentSortOrder":True,"lengthSeconds":True,"thumbnailEditorState":{"all":True},"premiere":{"all":True},"unlistedExpired":True,"videoTrailers":{"all":True},"commentsDisabledInternally":True,"allowEmbed":True,"audioLanguage":{"all":True},"dateRecorded":{"all":True},"commentFilter":True,"liveChat":{"all":True},"videoResolutions":{"all":True},"claimDetails":{"all":True},"selfCertification":{"all":True},"paidProductPlacement":True,"audienceRestriction":{"all":True},"visibility":{"all":True},"videoId":True,"privacy":True,"timePublishedSeconds":True,"videoAdvertiserSpecificAgeGates":{"all":True},"titleFormattedString":{"all":True},"videoPrechecks":{"all":True},"responseStatus":{"all":True},"location":{"all":True},"music":{"all":True},"allRestrictions":{"all":True},"sponsorsOnly":{"all":True},"status":True,"videoStreamUrl":True,"scheduledPublishingDetails":{"all":True},"gameTitle":{"all":True},"watchUrl":True,"timeCreatedSeconds":True,"videoEditorProject":{"all":True},"title":True,"originalFilename":True,"ownedClaimDetails":{"all":True},"statusDetails":{"all":True}},"liveChat":{"newLiveChatSettings":{"liveChatEnabled":True},"newLiveChatSettingsMask":{"liveChatEnabled":True}},"context":{"client":{"clientName":62,"clientVersion":"1.20201102.01.01","hl":"ru","gl":"RU","experimentsToken":""},"request":{"returnLogEntry":True,"internalExperimentFlags":[{"key":"force_route_delete_playlist_to_outertube","value":"False"},{"key":"force_live_chat_merchandise_upsell","value":"False"}],"sessionInfo":{"token":"AbX5usaBxohyRP8Fvdefz5dZBGpfZelYW0jCPR9UPesyDalZ3-IIeVUl6NJ3hDIcS5kIYiAYXtG4MrSWTX_H84rufEd8ww=="}},"user":{"onBehalfOfUser":user,"delegationContext":{"roleType":{"channelRoleType":"CREATOR_CHANNEL_ROLE_TYPE_OWNER"},"externalChannelId":ChannelId},"serializedDelegationContext":"EhhVQ2Q5QTh1azRreXVUMkYyQ29JOGg1clEqAggI"},"clientScreenNonce":"MC4yMjgwMzczNTM4ODQyMDMzMg.."},"delegationContext":{"roleType":{"channelRoleType":"CREATOR_CHANNEL_ROLE_TYPE_OWNER"},"externalChannelId":ChannelId}}
  369. else:
  370. data = {"encryptedVideoId":VideoId,"videoReadMask":{"dateRecorded":{"all":True},"selfCertification":{"all":True},"titleFormattedString":{"all":True},"status":True,"permissions":{"all":True},"timeCreatedSeconds":True,"videoTrailers":{"all":True},"metadataLanguage":{"all":True},"audienceRestriction":{"all":True},"commentsDisabledInternally":True,"videoEditorProject":{"all":True},"livestream":{"all":True},"allRestrictions":{"all":True},"videoStreamUrl":True,"license":True,"description":True,"allowEmbed":True,"crowdsourcingEnabled":True,"responseStatus":{"all":True},"draftStatus":True,"videoPrechecks":{"all":True},"thumbnailEditorState":{"all":True},"viewCountIsHidden":True,"videoAdvertiserSpecificAgeGates":{"all":True},"features":{"all":True},"videoResolutions":{"all":True},"thumbnailDetails":{"all":True},"statusDetails":{"all":True},"watchUrl":True,"timePublishedSeconds":True,"premiere":{"all":True},"videoDurationMs":True,"descriptionFormattedString":{"all":True},"lengthSeconds":True,"publishing":{"all":True},"uncaptionedReason":True,"claimDetails":{"all":True},"origin":True,"scheduledPublishingDetails":{"all":True},"videoId":True,"liveChat":{"all":True},"unlistedExpired":True,"paidProductPlacement":True,"location":{"all":True},"commentFilter":True,"visibility":{"all":True},"music":{"all":True},"channelId":True,"originalFilename":True,"tags":{"all":True},"allowComments":True,"allowRatings":True,"defaultCommentSortOrder":True,"downloadUrl":True,"title":True,"ownedClaimDetails":{"all":True},"sponsorsOnly":{"all":True},"privacy":True,"inlineEditProcessingStatus":True,"audioLanguage":{"all":True},"gameTitle":{"all":True},"category":True},"liveChat":{"newLiveChatSettings":{"liveChatEnabled":True},"newLiveChatSettingsMask":{"liveChatEnabled":True}},"context":{"client":{"clientName":62,"clientVersion":"1.20201102.01.01-canary_control","hl":"ru","gl":"RU","experimentsToken":""},"request":{"returnLogEntry":True,"internalExperimentFlags":[{"key":"force_route_delete_playlist_to_outertube","value":"false"},{"key":"force_live_chat_merchandise_upsell","value":"false"}],"sessionInfo":{"token":"AbX5usaBxohyRP8Fvdefz5dZBGpfZelYW0jCPR9UPesyDalZ3-IIeVUl6NJ3hDIcS5kIYiAYXtG4MrSWTX_H84rufEd8ww=="}},"user":{"delegationContext":{"roleType":{"channelRoleType":"CREATOR_CHANNEL_ROLE_TYPE_OWNER"},"externalChannelId":ChannelId},"serializedDelegationContext":"EhhVQ212VzRKN3FrUi1BUFMwdW50YkttLVEqAggI"},"clientScreenNonce":"MC43MDA2OTUxNjQ3OTk2MTEx"},"delegationContext":{"roleType":{"channelRoleType":"CREATOR_CHANNEL_ROLE_TYPE_OWNER"},"externalChannelId":ChannelId}}
  371.  
  372. r = session.post(f'https://studio.youtube.com/youtubei/v1/video_manager/metadata_update?alt=json&key={api_key}',
  373. json=data, headers=headers, cookies=my_cookies)
  374.  
  375. # with open("check_chat.txt", "w", encoding="utf-8") as f:
  376. # f.write(r.text)
  377.  
  378. if '"resultCode": "UPDATE_SUCCESS"' in r.text:
  379. return 'чат включен'
  380. else:
  381. return 'не удалось включить чат'
  382. else:
  383. if user:
  384. data = {"context":{"client":{"clientName":62,"clientVersion":"1.20201014.02.00","hl":"ru","gl":"RU","experimentIds":[],"experimentsToken":"","time_zone":"Asia/Yekaterinburg"},"capabilities":{},"request":{"internalExperimentFlags":[{"key":"force_route_delete_playlist_to_outertube","value":"False"},{"key":"force_live_chat_merchandise_upsell","value":"False"}]},"user":{"onBehalfOfUser":user}},"encryptedVideoId":VideoId,"liveChat":{"newLiveChatSettings":{"liveChatEnabled":False},"newLiveChatSettingsMask":{"liveChatEnabled":True}}}
  385. else:
  386. data = {"context":{"client":{"clientName":62,"clientVersion":"1.20201009.02.00","hl":"ru","gl":"RU","experimentIds":[],"experimentsToken":"","time_zone":"Asia/Yekaterinburg"},"capabilities":{},"request":{"internalExperimentFlags":[{"key":"force_live_chat_merchandise_upsell","value":"False"},{"key":"force_route_delete_playlist_to_outertube","value":"False"}]}},"encryptedVideoId":VideoId,"liveChat":{"newLiveChatSettings":{"liveChatEnabled":False},"newLiveChatSettingsMask":{"liveChatEnabled":True}}}
  387. r = session.post(f'https://studio.youtube.com/youtubei/v1/video_manager/metadata_update?alt=json&key={api_key}',
  388. json=data, headers=headers, cookies=my_cookies)
  389.  
  390. if '"resultCode": "UPDATE_SUCCESS"' in r.text:
  391. return 'чат отключен'
  392. else:
  393. return 'не удалось отключить чат'
  394.  
  395.  
  396. def do_public(session, ChannelId, VideoId, api_key, headers, my_cookies, ide):
  397. user = get_ide_for_update(ide)
  398.  
  399. if user:
  400. data = {"encryptedVideoId":VideoId,"videoReadMask":{"ownedClaimDetails":{"all":True},"location":{"all":True},"music":{"all":True},"videoDurationMs":True,"uncaptionedReason":True,"premiere":{"all":True},"allRestrictions":{"all":True},"dateRecorded":{"all":True},"metadataLanguage":{"all":True},"origin":True,"tags":{"all":True},"videoAdvertiserSpecificAgeGates":{"all":True},"responseStatus":{"all":True},"timeCreatedSeconds":True,"description":True,"videoPrechecks":{"all":True},"downloadUrl":True,"unlistedExpired":True,"features":{"all":True},"commentsDisabledInternally":True,"visibility":{"all":True},"statusDetails":{"all":True},"allowEmbed":True,"status":True,"category":True,"privacy":True,"publishing":{"all":True},"claimDetails":{"all":True},"videoStreamUrl":True,"videoTrailers":{"all":True},"videoId":True,"lengthSeconds":True,"liveChat":{"all":True},"descriptionFormattedString":{"all":True},"watchUrl":True,"channelId":True,"timePublishedSeconds":True,"paidProductPlacement":True,"thumbnailDetails":{"all":True},"defaultCommentSortOrder":True,"livestream":{"all":True},"audienceRestriction":{"all":True},"videoEditorProject":{"all":True},"inlineEditProcessingStatus":True,"gameTitle":{"all":True},"originalFilename":True,"allowRatings":True,"scheduledPublishingDetails":{"all":True},"audioLanguage":{"all":True},"titleFormattedString":{"all":True},"crowdsourcingEnabled":True,"title":True,"license":True,"selfCertification":{"all":True},"videoResolutions":{"all":True},"commentFilter":True,"sponsorsOnly":{"all":True},"thumbnailEditorState":{"all":True},"viewCountIsHidden":True,"allowComments":True,"permissions":{"all":True},"draftStatus":True},"privacyState":{"newPrivacy":"PUBLIC"},"context":{"client":{"clientName":62,"clientVersion":"1.20201102.01.01","hl":"ru","gl":"RU","experimentsToken":""},"request":{"returnLogEntry":True,"internalExperimentFlags":[{"key":"force_route_delete_playlist_to_outertube","value":"False"},{"key":"force_live_chat_merchandise_upsell","value":"False"}],"sessionInfo":{"token":"AbX5usaBxohyRP8Fvdefz5dZBGpfZelYW0jCPR9UPesyDalZ3-IIeVUl6NJ3hDIcS5kIYiAYXtG4MrSWTX_H84rufEd8ww=="}},"user":{"onBehalfOfUser":user,"delegationContext":{"externalChannelId":ChannelId,"roleType":{"channelRoleType":"CREATOR_CHANNEL_ROLE_TYPE_OWNER"}},"serializedDelegationContext":"EhhVQ2Q5QTh1azRreXVUMkYyQ29JOGg1clEqAggI"},"clientScreenNonce":"MC4xMjUzNTQwODUwNTg3OTA0Mg.."},"delegationContext":{"externalChannelId":ChannelId,"roleType":{"channelRoleType":"CREATOR_CHANNEL_ROLE_TYPE_OWNER"}}}
  401. else:
  402. data = {"encryptedVideoId":VideoId,"videoReadMask":{"description":True,"privacy":True,"videoPrechecks":{"all":True},"audienceRestriction":{"all":True},"audioLanguage":{"all":True},"lengthSeconds":True,"thumbnailDetails":{"all":True},"titleFormattedString":{"all":True},"videoResolutions":{"all":True},"thumbnailEditorState":{"all":True},"music":{"all":True},"allowEmbed":True,"videoEditorProject":{"all":True},"origin":True,"premiere":{"all":True},"videoTrailers":{"all":True},"videoId":True,"sponsorsOnly":{"all":True},"scheduledPublishingDetails":{"all":True},"uncaptionedReason":True,"gameTitle":{"all":True},"inlineEditProcessingStatus":True,"publishing":{"all":True},"originalFilename":True,"claimDetails":{"all":True},"viewCountIsHidden":True,"timeCreatedSeconds":True,"permissions":{"all":True},"timePublishedSeconds":True,"descriptionFormattedString":{"all":True},"ownedClaimDetails":{"all":True},"visibility":{"all":True},"status":True,"defaultCommentSortOrder":True,"videoAdvertiserSpecificAgeGates":{"all":True},"liveChat":{"all":True},"watchUrl":True,"commentsDisabledInternally":True,"metadataLanguage":{"all":True},"allowRatings":True,"crowdsourcingEnabled":True,"selfCertification":{"all":True},"allRestrictions":{"all":True},"license":True,"statusDetails":{"all":True},"category":True,"downloadUrl":True,"location":{"all":True},"videoDurationMs":True,"commentFilter":True,"features":{"all":True},"tags":{"all":True},"dateRecorded":{"all":True},"title":True,"allowComments":True,"paidProductPlacement":True,"livestream":{"all":True},"videoStreamUrl":True,"draftStatus":True,"responseStatus":{"all":True},"unlistedExpired":True,"channelId":True},"privacyState":{"newPrivacy":"PUBLIC"},"context":{"client":{"clientName":62,"clientVersion":"1.20201102.01.01","hl":"ru","gl":"RU","experimentsToken":""},"request":{"returnLogEntry":True,"internalExperimentFlags":[{"key":"force_route_delete_playlist_to_outertube","value":"False"},{"key":"force_live_chat_merchandise_upsell","value":"False"}],"sessionInfo":{"token":"AbX5usaBxohyRP8Fvdefz5dZBGpfZelYW0jCPR9UPesyDalZ3-IIeVUl6NJ3hDIcS5kIYiAYXtG4MrSWTX_H84rufEd8ww=="}},"user":{"delegationContext":{"externalChannelId":ChannelId,"roleType":{"channelRoleType":"CREATOR_CHANNEL_ROLE_TYPE_OWNER"}},"serializedDelegationContext":"EhhVQ212VzRKN3FrUi1BUFMwdW50YkttLVEqAggI"},"clientScreenNonce":"MC40Njk1MTQzODkxNDQxMDg5"},"delegationContext":{"externalChannelId":ChannelId,"roleType":{"channelRoleType":"CREATOR_CHANNEL_ROLE_TYPE_OWNER"}}}
  403.  
  404. r = session.post(f'https://studio.youtube.com/youtubei/v1/video_manager/metadata_update?alt=json&key={api_key}',
  405. json=data, headers=headers, cookies=my_cookies)
  406.  
  407. # with open("do_public.txt", "w", encoding="utf-8") as f:
  408. # f.write(r.text)
  409.  
  410. if '"resultCode": "UPDATE_SUCCESS"' in r.text:
  411. return 'паблик включен'
  412. else:
  413. return 'паблик не включился'
  414.  
  415.  
  416. def enable_moneytezation(session, api_key, videoID, headers, my_cookies, ide):
  417. user = get_ide_for_update(ide)
  418. if user:
  419. data = {"context":{"client":{"clientName":62,"clientVersion":"1.20201007.02.00","hl":"id","gl":"RU","experimentIds":[],"experimentsToken":"","time_zone":"Asia/Yekaterinburg"},"capabilities":{},"request":{"internalExperimentFlags":[{"key":"force_live_chat_merchandise_upsell","value":"False"},{"key":"force_route_delete_playlist_to_outertube","value":"False"}]},"user":{"onBehalfOfUser":user}},"encryptedVideoId":videoID,"monetizationSettings":{"newMonetizeWithAds":True}}
  420. else:
  421. data = {"context":{"client":{"clientName":62,"clientVersion":"1.20201007.02.00","hl":"id","gl":"RU","experimentIds":[],"experimentsToken":"","time_zone":"Asia/Yekaterinburg"},"capabilities":{},"request":{"internalExperimentFlags":[{"key":"force_live_chat_merchandise_upsell","value":"False"},{"key":"force_route_delete_playlist_to_outertube","value":"False"}]}},"encryptedVideoId":videoID,"monetizationSettings":{"newMonetizeWithAds":True}}
  422. r = session.post(f'https://studio.youtube.com/youtubei/v1/video_manager/metadata_update?alt=json&key={api_key}',
  423. headers=headers, cookies=my_cookies, json=data)
  424.  
  425. # with open("enable_moneytezation.txt", "w", encoding="utf-8") as f:
  426. # f.write(r.text)
  427.  
  428. if '"resultCode": "UPDATE_SUCCESS"' in r.text:
  429. return 'монетизация включена'
  430. else:
  431. return 'монетизация не включена'
  432.  
  433.  
  434. def disable_video(session, api_key, videoID, headers, my_cookies, ide):
  435. user = get_ide_for_update(ide)
  436. if user:
  437. data = {"context":{"client":{"clientName":62,"clientVersion":"1.20201007.02.00","hl":"id","gl":"RU","experimentIds":[],"experimentsToken":"","time_zone":"Asia/Yekaterinburg"},"capabilities":{},"request":{"internalExperimentFlags":[{"key":"force_live_chat_merchandise_upsell","value":"False"},{"key":"force_route_delete_playlist_to_outertube","value":"False"}]},"user":{"onBehalfOfUser":user}},"encryptedVideoId":videoID, "liveStreamDvr":{"newEnableDvr":False}}
  438. else:
  439. data = {"context":{"client":{"clientName":62,"clientVersion":"1.20201007.02.00","hl":"id","gl":"RU","experimentIds":[],"experimentsToken":"","time_zone":"Asia/Yekaterinburg"},"capabilities":{},"request":{"internalExperimentFlags":[{"key":"force_live_chat_merchandise_upsell","value":"False"},{"key":"force_route_delete_playlist_to_outertube","value":"False"}]}},"encryptedVideoId":videoID, "liveStreamDvr":{"newEnableDvr":False}}
  440.  
  441.  
  442. r = session.post(f'https://studio.youtube.com/youtubei/v1/video_manager/metadata_update?alt=json&key={api_key}',
  443. headers=headers, cookies=my_cookies, json=data)
  444.  
  445. # with open("enable_moneytezation.txt", "w", encoding="utf-8") as f:
  446. # f.write(r.text)
  447.  
  448. if '"resultCode": "UPDATE_SUCCESS"' in r.text:
  449. return 'Видеорекордер отключен'
  450. else:
  451. return 'Видеорекордер не отключен'
  452.  
  453.  
  454. def change_first_name_and_last_name(session, api_key, channelId, headers, ide,
  455. first_name, last_name, past_name, my_cookies):
  456. user = get_ide_for_update(ide)
  457. if user:
  458. past_name = f"{first_name} {last_name}"
  459. data = {"externalChannelId":channelId,"titleUpdate":{"brandTitle":{"original":past_name,"originalLanguage":"","messages":[]}},"context":{"client":{"clientName":62,"clientVersion":"1.20201104.01.00","hl":"ru","gl":"RU","experimentsToken":""},"request":{"returnLogEntry":True,"internalExperimentFlags":[{"key":"force_route_delete_playlist_to_outertube","value":"false"},{"key":"force_live_chat_merchandise_upsell","value":"false"}],"sessionInfo":{"token":"AbX5usaBxohyRP8Fvdefz5dZBGpfZelYW0jCPR9UPesyDalZ3-IIeVUl6NJ3hDIcS5kIYiAYXtG4MrSWTX_H84rufEd8ww=="}},"user":{"onBehalfOfUser":user,"delegationContext":{"roleType":{"channelRoleType":"CREATOR_CHANNEL_ROLE_TYPE_OWNER"},"externalChannelId":channelId},"serializedDelegationContext":"EhhVQ2Q5QTh1azRreXVUMkYyQ29JOGg1clEqAggI"},"clientScreenNonce":"MC42NTU0MDA5MzE0MTk2MTc."}}
  460. else:
  461. data = {"externalChannelId":channelId,"titleUpdate":{"personalTitle":{"givenName":first_name,"familyName":last_name,"translations":{"original":past_name,"originalLanguage":"","messages":[]}}},"context":{"client":{"clientName":62,"clientVersion":"1.20201104.01.00","hl":"ru","gl":"RU","experimentsToken":""},"request":{"returnLogEntry":True,"internalExperimentFlags":[{"key":"force_live_chat_merchandise_upsell","value":"false"},{"key":"force_route_delete_playlist_to_outertube","value":"false"}],"sessionInfo":{"token":"AbX5usaBxohyRP8Fvdefz5dZBGpfZelYW0jCPR9UPesyDalZ3-IIeVUl6NJ3hDIcS5kIYiAYXtG4MrSWTX_H84rufEd8ww=="}},"user":{"delegationContext":{"roleType":{"channelRoleType":"CREATOR_CHANNEL_ROLE_TYPE_OWNER"},"externalChannelId":channelId},"serializedDelegationContext":"EhhVQ212VzRKN3FrUi1BUFMwdW50YkttLVEqAggI"},"clientScreenNonce":"MC41OTQwNTMzODc1NjcxMTcy"}}
  462. url = f'https://studio.youtube.com/youtubei/v1/channel_edit/update_channel_page_settings?alt=json&key={api_key}'
  463. r = session.post(url, headers=headers, cookies=my_cookies, json=data)
  464. # with open('change_first_name_and_last_name.txt', 'w', encoding='utf-8') as f:
  465. # f.write(r.text)
  466. return 'название канала изменено'
  467.  
  468.  
  469.  
  470. def change_country(session, api_key, headers, ide, channelId, my_cookies):
  471. user = get_ide_for_update(ide)
  472. if user:
  473. data = {"channelId":channelId,"commentsSettingsRequest":{},"studioSettingsRequest":{},"uploadDefaultsRequest":{},"asrFilteringRequest":{},"context":{"client":{"clientName":62,"clientVersion":"1.20201104.01.00","hl":"ru","gl":"RU","experimentsToken":""},"request":{"returnLogEntry":True,"internalExperimentFlags":[{"key":"force_route_delete_playlist_to_outertube","value":"false"},{"key":"force_live_chat_merchandise_upsell","value":"false"}],"sessionInfo":{"token":"AbX5usaBxohyRP8Fvdefz5dZBGpfZelYW0jCPR9UPesyDalZ3-IIeVUl6NJ3hDIcS5kIYiAYXtG4MrSWTX_H84rufEd8ww=="}},"user":{"onBehalfOfUser":user,"delegationContext":{"roleType":{"channelRoleType":"CREATOR_CHANNEL_ROLE_TYPE_OWNER"},"externalChannelId":channelId},"serializedDelegationContext":"EhhVQ2Q5QTh1azRreXVUMkYyQ29JOGg1clEqAggI"},"clientScreenNonce":"MC42NTU0MDA5MzE0MTk2MTc."},"channelReadMask":{"settings":{"all":True},"channelVisibility":True,"crosswalkStatus":{"all":True},"features":{"all":True},"title":True,"channelId":True,"permissions":{"all":True},"isOfficialArtistChannel":True,"isMonetized":True,"contracts":{"all":True},"isNameVerified":True,"sponsorships":{"all":True},"thumbnailDetails":{"all":True},"isPartner":True,"timeCreatedSeconds":True,"metric":{"all":True}}}
  474. else:
  475. data = {"channelId":channelId,"commentsSettingsRequest":{},"studioSettingsRequest":{},"uploadDefaultsRequest":{},"asrFilteringRequest":{},"context":{"client":{"clientName":62,"clientVersion":"1.20201104.01.00","hl":"ru","gl":"RU","experimentsToken":""},"request":{"returnLogEntry":True,"internalExperimentFlags":[{"key":"force_route_delete_playlist_to_outertube","value":"false"},{"key":"force_live_chat_merchandise_upsell","value":"false"}],"sessionInfo":{"token":"AbX5usaBxohyRP8Fvdefz5dZBGpfZelYW0jCPR9UPesyDalZ3-IIeVUl6NJ3hDIcS5kIYiAYXtG4MrSWTX_H84rufEd8ww=="}},"user":{"delegationContext":{"roleType":{"channelRoleType":"CREATOR_CHANNEL_ROLE_TYPE_OWNER"},"externalChannelId":channelId},"serializedDelegationContext":"EhhVQ212VzRKN3FrUi1BUFMwdW50YkttLVEqAggI"},"clientScreenNonce":"MC45Mjg4ODQ4ODMxNjcyNjk2"},"channelReadMask":{"settings":{"all":True},"channelVisibility":True,"crosswalkStatus":{"all":True},"features":{"all":True},"title":True,"channelId":True,"permissions":{"all":True},"isOfficialArtistChannel":True,"isMonetized":True,"contracts":{"all":True},"timeCreatedSeconds":True,"thumbnailDetails":{"all":True},"metric":{"all":True},"isPartner":True,"sponsorships":{"all":True},"isNameVerified":True}}
  476. url = f'https://studio.youtube.com/youtubei/v1/creator/update_creator_channel?alt=json&key={api_key}'
  477. r = session.post(url, headers=headers, cookies=my_cookies, json=data)
  478. # with open('change_country.txt', 'w', encoding='utf-8') as f:
  479. # f.write(r.text)
  480. if '"statusCode": "CREATOR_ENTITY_STATUS_OK"' in r.text:
  481. return 'сменил страну успешно'
  482. else:
  483. return 'не удалось изменить страну канала'
  484.  
  485.  
  486. def get_my_cookie():
  487. with open("cookies.json", encoding="utf-8") as f:
  488. data = json.loads(f.read())
  489.  
  490. my_dict = {}
  491. for i in data:
  492. my_dict[i["name"]] = i["value"]
  493. return my_dict
  494.  
  495.  
  496. def main1():
  497. try:
  498. my_cookies = get_my_cookie()
  499. # my_cookies = net_to_cookie('cookies.txt', 'youtube') # -> ввести название файла
  500. links = all_accounts(my_cookies)
  501. accounts, all_accs = check_all_account(links, my_cookies)
  502.  
  503. return accounts, all_accs
  504. except Exception as e:
  505. return 'error', e
  506.  
  507.  
  508. def main2(videoId, description, settings_file, image, selected_acc, accounts, folder):
  509. # try:
  510. settings_data = get_json_settings_from_file(file_name=settings_file)
  511. title = get_json_data_from_file(settings_data, key_='title')
  512. tags = get_json_data_from_file(settings_data, key_='tags').split(',')
  513. hide_s = get_json_data_from_file(settings_data, key_='hide_sub_count')
  514. tags = [tag.strip() for tag in tags]
  515. category = get_json_data_from_file(settings_data, key_='category', int_=True)
  516. description = work_with_file(file_name=description)
  517.  
  518. first_name = get_json_data_from_file(settings_data, key_='first_name')
  519. last_name = get_json_data_from_file(settings_data, key_='last_name')
  520.  
  521. likess = get_json_data_from_file(settings_data, key_='likes')
  522. chatt = get_json_data_from_file(settings_data, key_='chat')
  523. change_country_status = get_json_data_from_file(settings_data, key_='change_country')
  524.  
  525. cook, session, title_of_account, ide, channelId, api_key = choose_account(accounts, selected_acc)
  526. my_cookies = cook
  527.  
  528. headers = get_header(session, channelId, my_cookies)
  529. if headers != "нету SAPISID":
  530. res_main_change = main_change(session, videoId, image, tags, category, channelId, title, description, headers, api_key, my_cookies, ide)
  531. res_check_likes = check_likes(session, channelId, videoId, api_key, headers, my_cookies, ide, likess)
  532. res_check_chat = check_chat(session, channelId, videoId, api_key, headers, my_cookies, ide, chatt)
  533. res_do_public = do_public(session, channelId, videoId, api_key, headers, my_cookies, ide)
  534. res_enable_moneytezation = enable_moneytezation(session, api_key, videoId, headers, my_cookies, ide)
  535. res_vid = disable_video(session, api_key, videoId, headers, my_cookies, ide)
  536. res_baner = change_banner(session, api_key, videoId, headers, my_cookies, ide, folder, channelId)
  537. hide_videoss = hide_videos(session, api_key, videoId, headers, my_cookies, ide, folder, channelId)
  538. hide_likes = hide_videos(session, api_key, videoId, headers, my_cookies, ide, folder, channelId)
  539. hide_subss = hide_subs(session, api_key, videoId, headers, my_cookies, ide, folder, channelId, hide_s)
  540.  
  541. if first_name and last_name:
  542. res_change_channel_name = change_first_name_and_last_name(session, api_key, channelId, headers, ide,
  543. first_name, last_name, title_of_account, my_cookies)
  544. else:
  545. res_change_channel_name = 'название канала не изменено'
  546.  
  547. if change_country_status:
  548. res_change_country = change_country(session, api_key, headers, ide, channelId, my_cookies)
  549. else:
  550. res_change_country = 'страна канала не изменена'
  551.  
  552. return res_main_change, res_check_likes, res_check_chat, res_do_public, res_enable_moneytezation, res_change_channel_name, res_change_country, res_vid, res_baner, hide_videoss, hide_subss
  553. else:
  554. return headers
  555. # except Exception as e:
  556. # return 'error', e, e, e, e, e, e
  557.  
  558. if __name__ == "__main__":
  559. pass
  560.  
  561.  
  562.  
  563. def change_banner(session, api_key, videoID, headers, my_cookies, ide, folder, channelId):
  564. try:
  565. file = folder+r'\banner.jpg'
  566.  
  567. f = open(file, 'rb')
  568. files = {'files': f.read()}
  569. size = str(os.path.getsize(file))
  570.  
  571. s = requests.Session()
  572. # print(size, f.seek(0, os.SEEK_END), f)
  573.  
  574. hedr1 = {**headers,
  575. "authority": "www.youtube.com",
  576. "content-length": "0",
  577. "pragma": "no-cache",
  578. "x-goog-upload-protocol": "resumable",
  579. "x-goog-upload-header-content-length": size,
  580. "x-goog-upload-command": "start",
  581. "cache-control": "no-cache",
  582. "content-type": "application/x-www-form-urlencoded;charset=utf-8",
  583. "x-youtube-channelid": channelId,
  584. "accept": "*/*",
  585. "origin": "https://studio.youtube.com",
  586. "sec-fetch-site": "same-site",
  587. "sec-fetch-mode": "cors",
  588. "sec-fetch-dest": "empty",
  589. }
  590. r = session.post('https://www.youtube.com/channel_image_upload/banner', headers=hedr1, cookies=my_cookies)
  591. # print(r.status_code)
  592. upload_id = r.headers['X-GUploader-UploadID']
  593. # print(r.text, r.status_code)
  594.  
  595. hedr0 = {**headers,
  596. "authority": "www.youtube.com",
  597. "pragma": "no-cache",
  598. "cache-control": "no-cache",
  599. "accept": "*/*",
  600. "access-control-request-method": "POST",
  601. "access-control-request-headers": "x-goog-upload-command,x-goog-upload-header-content-length,x-goog-upload-protocol,x-youtube-channelid",
  602. "origin": "https://studio.youtube.com",
  603. "sec-fetch-mode": "cors",
  604. "x-youtube-channelid": channelId,
  605. "content-length": size,
  606. "sec-fetch-site": "same-site",
  607. "sec-fetch-dest": "empty",
  608. }
  609. r = session.post('https://www.youtube.com/channel_image_upload/banner', headers=hedr0, files=files, cookies=my_cookies)
  610. enc_id = r.text.split('":"')[1][:-2]
  611. # print(r.status_code)
  612. # print(enc_id, r.text)
  613.  
  614. hedr3 = {**headers,
  615. "authority": "studio.youtube.com",
  616. "pragma": "no-cache",
  617. "cache-control": "no-cache",
  618. # "x-youtube-delegation-context": "EhhVQ1RBeTBpdTdCa1A0VG1EQldyX1FicUEqAggI",
  619. "x-origin": "https://studio.youtube.com",
  620. "x-youtube-page-label": "youtube.studio.web_20201126_00_RC00",
  621. # "authorization": "SAPISIDHASH 1606641880_51401528104105e18d99cf7b7888f113487cadea",
  622. "content-type": "application/json",
  623. # "x-youtube-page-cl": "344383706",
  624. # "x-youtube-utc-offset": "120",
  625. # "x-youtube-client-name": "62",
  626. "user-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/85.0.4183.121 Safari/537.36",
  627. "x-youtube-client-version": "1.20201126.00.00",
  628. # "x-goog-authuser": "0",
  629. "x-youtube-time-zone": "Europe/Kiev",
  630. # "x-goog-visitor-id": "CgtUOWNtaV9WZDhlWSiy0Y3-BQ%3D%3D",
  631. # "x-youtube-ad-signals": "dt=1606641843311&flash=0&frm&u_tz=120&u_his=16&u_java&u_h=1080&u_w=1920&u_ah=1050&u_aw=1920&u_cd=24&u_nplug=3&u_nmime=4&bc=31&bih=949&biw=1879&brdim=0%2C0%2C0%2C0%2C1920%2C0%2C1920%2C1050%2C1879%2C949&vis=1&wgl=true&ca_type=image",
  632. "accept": "*/*",
  633. "origin": "https://studio.youtube.com",
  634. "sec-fetch-site": "same-origin",
  635. "sec-fetch-mode": "cors",
  636. "sec-fetch-dest": "empty",
  637. "referer": "https://studio.youtube.com/channel/"+channelId+"/editing/images",
  638. "accept-language": "ru-RU,ru;q=0.9,en-US;q=0.8,en;q=0.7",
  639. # "cookie": "VISITOR_INFO1_LIVE=T9cmi_Vd8eY; CONSENT=YES+UA.ru+20160721-10-0; NID=204=aWYUNUOZsYDVG2rzr5-dcQIpYcesP3w1yGshNPhD_q-6ikS0_w5Do4Xutc_AIQdwb6znAnmU8DbKfY5QdC6qYIjufExBGQ-QSHtvdRhsFo2Y6cwA32QDTm6uebri32OMajpPr31lwvgScOSh0gr9oHTlpBzBQ1p2IOK6T25IAjE; _gcl_au=1.1.1456209250.1605128410; PREF=al=ru&volume=100&f6=400&repeat=NONE&library_tab_browse_id=FEmusic_liked_videos&f5=30000; s_gl=da921031436d82404d81691fe6112514cwIAAABVQQ==; YSC=w7Z7j7AptvI; SID=4AeCiRucdL2D3rzsU-hcZ-ndWDqLaaTFmf8yST2qyMmbdAb-6JTyTjxyL4RpRgR88r_S4g.; __Secure-3PSID=4AeCiRucdL2D3rzsU-hcZ-ndWDqLaaTFmf8yST2qyMmbdAb-LbZOK9ae5BVZw76sOzwT1w.; HSID=AeOs9T5yObz0pgg8h; SSID=Ag0r4JKE0ilvxSEQ7; APISID=Q1yTix7v4T7RYpKq/ArTsC5md03ZFOX9n1; SAPISID=9bbTuSgHuvdc0a-r/AyLBLTJoekDEmlTdo; __Secure-3PAPISID=9bbTuSgHuvdc0a-r/AyLBLTJoekDEmlTdo; LOGIN_INFO=AFmmF2swRAIgcJ8RiezCgXJX8nveCTBhl8FL0niEJ--S-uY7pzkvJEMCIHWqdJNPivb1Uti9CO88WwB0dxKDuKaDpIa5onpLZhp9:QUQ3MjNmeVZOUlBBdU5JTHBsTzM5TXBQX2k0NlN1NlpLZy0zWTN2cFYyOWlrT3kzUFZjdWdTV21oeUVRV1Buc3hsanFvMzFPSVhwNHVIdHAtSVNSTHB6bmtVU2VfQ3FGQlI5QThXRkRYS0FHR3JJTmNrZjg5RzlyVDNrbzBSMl9BOU1tdjhwcU80T3hVYi1mYmR2LTR1WGRTd2JxRF9mNDkyRDNvWGEzdTlKUWJDc2gxaDR1SWZz; SIDCC=AJi4QfENDX1jR8g4lNLqxgoAzsty3t7kLsleCpATmD7mghO54VBKsm9B7o-HlGGul_z3DWyxPQ; __Secure-3PSIDCC=AJi4QfGkUfgImtgzXYMEwWDOnIlrF23Ox3DXP2GHaOV0eq_xtlM_QBQZkT_VCLTcGjbtnKLe2w",
  640. }
  641. # print(hedr3)
  642. # print(r.status_code, )
  643.  
  644. # data = {"externalChannelId":channelId,}
  645.  
  646. # user = get_ide_for_update(ide)
  647. user = get_ide_for_update(ide)
  648.  
  649. data = {
  650. "externalChannelId": channelId,
  651. "bannerImageUpdate":
  652. {
  653. "encryptedBlobId": enc_id,
  654. },
  655. "context":
  656. {
  657. "client":
  658. {
  659. "clientName": 62,
  660. "clientVersion": "1.20201126.00.00",
  661. "hl": "ru",
  662. "gl": "UA",
  663. "experimentsToken": "",
  664. "utcOffsetMinutes": 120
  665. },
  666. "request":
  667. {
  668. "returnLogEntry": True,
  669. "sessionInfo":
  670. {
  671. "token": "AbX5usaBxohyRP8Fvdefz5dZBGpfZelYW0jCPR9UPesyDalZ3-IIeVUl6NJ3hDIcS5kIYiAYXtG4MrSWTX_H84rufEd8ww=="
  672.  
  673. }
  674. },
  675. "user":
  676. {
  677. "delegationContext":
  678. {
  679. "externalChannelId": channelId,
  680. "roleType":
  681. {
  682. "channelRoleType": "CREATOR_CHANNEL_ROLE_TYPE_OWNER"
  683. }
  684. },
  685. "serializedDelegationContext": "EhhVQ1RBeTBpdTdCa1A0VG1EQldyX1FicUffgI11"
  686. },
  687. "clientScreenNonce": "MC44NDIxMTM5MTQ3MzEwNff211"
  688. }
  689. }
  690.  
  691. r = session.post('https://studio.youtube.com/youtubei/v1/channel_edit/update_channel_page_settings?alt=json&key='+api_key, headers=hedr3, cookies=my_cookies, json=data)
  692. # print(r.text)
  693. print(r.status_code)
  694. # print(r.text)
  695.  
  696. return 'шапка канала изменена'
  697. except:
  698. return 'шапка канала не изменена'
  699.  
  700.  
  701. def hide_videos(session, api_key, videoID, headers, my_cookies, ide, folder, channelId):
  702. data = {
  703. "channelId": channelId,
  704. "videoUpdate":
  705. {
  706. "privacyState":
  707. {
  708. "privacy": "VIDEO_UPDATE_PRIVACY_SETTING_PRIVATE"
  709. }
  710. },
  711. "filter":
  712. {
  713. "and":
  714. {
  715. "operands": [
  716. {
  717. "channelIdIs":
  718. {
  719. "value": channelId
  720. }
  721. }]
  722. }
  723. },
  724. "context":
  725. {
  726. "client":
  727. {
  728. "clientName": 62,
  729. "clientVersion": "1.20201126.00.00",
  730. "hl": "ru",
  731. "gl": "UA",
  732. "experimentsToken": "",
  733. "utcOffsetMinutes": 120
  734. },
  735. "request":
  736. {
  737. "returnLogEntry": True,
  738. "internalExperimentFlags": [
  739. {
  740. "key": "force_route_delete_playlist_to_outertube",
  741. "value": "false"
  742. },
  743. {
  744. "key": "force_live_chat_merchandise_upsell",
  745. "value": "false"
  746. }],
  747. "sessionInfo":
  748. {
  749. "token": "AbX5usaBxohyRP8Fvdefz5dZBGpfZelYW0jCPR9UPesyDalZ3-IIeVUl6NJ3hDIcS5kIYiAYXtG4MrSWTX_H84rufEd8ww=="
  750. }
  751. },
  752. "user":
  753. {
  754. "delegationContext":
  755. {
  756. "roleType":
  757. {
  758. "channelRoleType": "CREATOR_CHANNEL_ROLE_TYPE_OWNER"
  759. },
  760. "externalChannelId": channelId
  761. },
  762. "serializedDelegationContext": "EhhVQ1RBeTBpdTdCa1A0VG1EQldyX1FicUEqAggI"
  763. },
  764. "clientScreenNonce": "MC44NDIxMTM5MTQ3MzEwNjA2"
  765. }
  766. }
  767.  
  768. # headers = {
  769. # **headers,
  770. # # "x-youtube-delegation-context": "EhhVQ1RBeTBpdTdCa1A0VG1EQldyX1FicUEqAggI",
  771. # "authorization": "SAPISIDHASH 1608500878_9ee5114b93921c950fc01974471b4bb722ff88e1",
  772. # }
  773. r = session.post(f'https://studio.youtube.com/youtubei/v1/creator/enqueue_creator_bulk_action?alt=json&key={api_key}',
  774. headers=headers, cookies=my_cookies, json=data)
  775.  
  776. # with open("enable_moneytezation.txt", "w", encoding="utf-8") as f:
  777. # f.write(r.text)
  778. print(r.text, r.status_code)
  779. if r.status_code == 200:
  780. return 'Все видео скрыты'
  781. else:
  782. return 'Видео не скрыты'
  783.  
  784.  
  785. def hide_subs(session, api_key, videoID, headers, my_cookies, ide, folder, channelId, hide_s):
  786. if hide_s:
  787. to_do = True
  788. else:
  789. to_do = False
  790. data = {
  791. "channelId": channelId,
  792. "coreSettingsRequest":
  793. {
  794. "hideSubscriberCount": to_do
  795. },
  796. "context":
  797. {
  798. "client":
  799. {
  800. "clientName": 62,
  801. "clientVersion": "1.20201126.00.00",
  802. "hl": "ru",
  803. "gl": "UA",
  804. "experimentsToken": "AbX5usaXVfeCnPijP6YY8BPXPVU-c8JOuqiBqHkf_Hve98xZjO4rDlLaLicnZy51XZ7xMgCQYU6BdtoHZvnVEiiYmCkIhQ==",
  805. "utcOffsetMinutes": 120
  806. },
  807. "request":
  808. {
  809. "returnLogEntry": True,
  810. "internalExperimentFlags": [
  811. {
  812. "key": "force_live_chat_merchandise_upsell",
  813. "value": "false"
  814. },
  815. {
  816. "key": "force_route_delete_playlist_to_outertube",
  817. "value": "false"
  818. }],
  819. "sessionInfo":
  820. {
  821. "token": "AbX5usaBxohyRP8Fvdefz5dZBGpfZelYW0jCPR9UPesyDalZ3-IIeVUl6NJ3hDIcS5kIYiAYXtG4MrSWTX_H84rufEd8ww=="
  822. }
  823. },
  824. "user":
  825. {
  826. "delegationContext":
  827. {
  828. "externalChannelId": channelId,
  829. "roleType":
  830. {
  831. "channelRoleType": "CREATOR_CHANNEL_ROLE_TYPE_OWNER"
  832. }
  833. },
  834. "serializedDelegationContext": "EhhVQ1RBeTBpdTdCa1A0VG1EQldyX1FicUEqAggI"
  835. },
  836. "clientScreenNonce": "MC44NDIxMTM5MTQ3MzEwNjA2"
  837. }
  838. }
  839. r = session.post(f'https://studio.youtube.com/youtubei/v1/creator/update_creator_channel?alt=json&key={api_key}', headers=headers, cookies=my_cookies, json=data)
  840.  
  841. # with open("enable_moneytezation.txt", "w", encoding="utf-8") as f:
  842. # f.write(r.text)
  843. # print(r.text, r.status_code)
  844. if r.status_code == 200:
  845. return 'Кол-во подписчиков скрыто' if to_do else 'Кол-во подписчиков отображается'
  846. else:
  847. return 'Кол-во подписчиков ошибка'
  848.  
  849.  
  850. def get_new_sapid(session, client, token, auth, channel_id):
  851.  
  852. data = {
  853. "channelId": channelId,
  854. "coreSettingsRequest":
  855. {
  856. "hideSubscriberCount": to_do
  857. },
  858. "commentsSettingsRequest":
  859. {},
  860. "studioSettingsRequest":
  861. {},
  862. "uploadDefaultsRequest":
  863. {},
  864. "asrFilteringRequest":
  865. {},
  866. "context":
  867. {
  868. "client":
  869. {
  870. "clientName": 62,
  871. "clientVersion": "1.20201126.00.00",
  872. "hl": "ru",
  873. "gl": "UA",
  874. "experimentsToken": "AbX5usaXVfeCnPijP6YY8BPXPVU-c8JOuqiBqHkf_Hve98xZjO4rDlLaLicnZy51XZ7xMgCQYU6BdtoHZvnVEiiYmCkIhQ==",
  875. "utcOffsetMinutes": 120
  876. },
  877. "request":
  878. {
  879. "returnLogEntry": True,
  880. "internalExperimentFlags": [
  881. {
  882. "key": "force_live_chat_merchandise_upsell",
  883. "value": "false"
  884. },
  885. {
  886. "key": "force_route_delete_playlist_to_outertube",
  887. "value": "false"
  888. }],
  889. "sessionInfo":
  890. {
  891. "token": "AbX5usaBxohyRP8Fvdefz5dZBGpfZelYW0jCPR9UPesyDalZ3-IIeVUl6NJ3hDIcS5kIYiAYXtG4MrSWTX_H84rufEd8ww=="
  892. }
  893. },
  894. "user":
  895. {
  896. "delegationContext":
  897. {
  898. "externalChannelId": channelId,
  899. "roleType":
  900. {
  901. "channelRoleType": "CREATOR_CHANNEL_ROLE_TYPE_OWNER"
  902. }
  903. },
  904. "serializedDelegationContext": "EhhVQ1RBeTBpdTdCa1A0VG1EQldyX1FicUEqAggI"
  905. },
  906. "clientScreenNonce": "MC44NDIxMTM5MTQ3MzEwNjA2"
  907. },
  908. "channelReadMask":
  909. {
  910. "settings":
  911. {
  912. "all": True
  913. },
  914. "channelVisibility": True,
  915. "crosswalkStatus":
  916. {
  917. "all": True
  918. },
  919. "features":
  920. {
  921. "all": True
  922. },
  923. "title": True,
  924. "channelId": True,
  925. "permissions":
  926. {
  927. "all": True
  928. },
  929. "isOfficialArtistChannel": True,
  930. "isMonetized": True,
  931. "contracts":
  932. {
  933. "all": True
  934. },
  935. "isNameVerified": True,
  936. "isPartner": True,
  937. "metric":
  938. {
  939. "all": True
  940. },
  941. "thumbnailDetails":
  942. {
  943. "all": True
  944. },
  945. "sponsorships":
  946. {
  947. "all": True
  948. },
  949. "timeCreatedSeconds": True
  950. }
  951. }
  952.  
  953. r = session.post(f'https://studio.youtube.com/youtubei/v1/creator/update_creator_channel?alt=json&key={api_key}', headers=headers, cookies=my_cookies, json=data)
  954. return r.text, r.code
Add Comment
Please, Sign In to add comment