Advertisement
load-net

СКАЧАТЬ С ЮТУБ

Nov 27th, 2024 (edited)
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 15.03 KB | None | 0 0
  1.  
  2.  
  3.  
  4. import os.path
  5. import time
  6.  
  7. import requests
  8. from tqdm import tqdm
  9.  
  10.  
  11. def playlist_item(url):
  12. headers = {
  13. 'authority': 'api.youtubemultidownloader.com',
  14. 'sec-ch-ua': '" Not A;Brand";v="99", "Chromium";v="98", "Yandex";v="22"',
  15. 'accept': 'application/json, text/javascript, */*; q=0.01',
  16. 'dnt': '1',
  17. 'sec-ch-ua-mobile': '?0',
  18. 'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) '
  19. 'Chrome/98.0.4758.141 YaBrowser/22.3.3.852 Yowser/2.5 Safari/537.36',
  20. 'sec-ch-ua-platform': '"Windows"',
  21. 'origin': 'https://youtubemultidownloader.net',
  22. 'sec-fetch-site': 'cross-site',
  23. 'sec-fetch-mode': 'cors',
  24. 'sec-fetch-dest': 'empty',
  25. 'referer': 'https://youtubemultidownloader.net/',
  26. 'accept-language': 'ru,en;q=0.9,uk;q=0.8',
  27. }
  28.  
  29. params = {
  30. 'url': url,
  31. 'nextPageToken': '',
  32. }
  33.  
  34. response = requests.get('https://api.youtubemultidownloader.com/playlist', params=params, headers=headers).json()
  35. list_items = []
  36. for item in range(0, len(response['items'])):
  37. list_items.append(response['items'][item]['id'])
  38. return list_items
  39.  
  40.  
  41. def get_channel_name(vid_id):
  42. headers = {
  43. 'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) '
  44. 'Chrome/98.0.4758.141 Safari/537.36',
  45. 'accept': '*/*',
  46. }
  47.  
  48. params = {
  49. 'key': 'AIzaSyAO_FJ2SlqU8Q4STEHLGCilw_Y9_11qcW8',
  50. 'prettyPrint': 'false',
  51. }
  52.  
  53. json_data = {
  54. 'videoId': vid_id,
  55. 'context': {
  56. 'client': {
  57. 'hl': 'ru',
  58. 'gl': 'RU',
  59. 'remoteHost': '31.173.242.98',
  60. 'deviceMake': '',
  61. 'deviceModel': '',
  62. 'visitorData': 'CgtrdUNhZ3U2VGNEOCiDndSTBg%3D%3D',
  63. 'userAgent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) '
  64. 'Chrome/98.0.4758.141 Safari/537.36,gzip(gfe)',
  65. 'clientName': 'WEB',
  66. 'clientVersion': '2.20220502.01.00',
  67. 'osName': 'Windows',
  68. 'osVersion': '10.0',
  69. 'originalUrl': 'https://www.youtube.com/watch?v=4MPWVKFaLD8',
  70. 'platform': 'DESKTOP',
  71. 'clientFormFactor': 'UNKNOWN_FORM_FACTOR',
  72. 'configInfo': {
  73. 'appInstallData': 'CIOd1JMGELiLrgUQmN79EhCUj64FEOqQrgUQw_KtBRCY6q0FELfLrQUQ8IKuBRC7ka4FENSDrgUQ6JCu'
  74. 'BRCw7q0FEK_yrQUQgub9EhCR-PwSENi-rQU%3D',
  75. },
  76. 'userInterfaceTheme': 'USER_INTERFACE_THEME_DARK',
  77. 'timeZone': 'Asia/Omsk',
  78. 'browserName': 'Chrome',
  79. 'browserVersion': '98.0.4758.141',
  80. 'screenWidthPoints': 1137,
  81. 'screenHeightPoints': 870,
  82. 'screenPixelDensity': 1,
  83. 'screenDensityFloat': 1,
  84. 'utcOffsetMinutes': 360,
  85. 'connectionType': 'CONN_CELLULAR_4G',
  86. 'memoryTotalKbytes': '8000000',
  87. 'mainAppWebInfo': {
  88. 'graftUrl': 'https://www.youtube.com/watch?v=4MPWVKFaLD8',
  89. 'webDisplayMode': 'WEB_DISPLAY_MODE_BROWSER',
  90. 'isWebNativeShareAvailable': True,
  91. },
  92. 'playerType': 'UNIPLAYER',
  93. 'tvAppInfo': {
  94. 'livingRoomAppMode': 'LIVING_ROOM_APP_MODE_UNSPECIFIED',
  95. },
  96. 'clientScreen': 'WATCH_FULL_SCREEN',
  97. },
  98. 'user': {
  99. 'lockedSafetyMode': False,
  100. },
  101. 'request': {
  102. 'useSsl': True,
  103. 'internalExperimentFlags': [],
  104. 'consistencyTokenJars': [],
  105. },
  106. 'adSignalsInfo': {
  107. 'params': [
  108. {
  109. 'key': 'dt',
  110. 'value': '1651838604229',
  111. },
  112. {
  113. 'key': 'flash',
  114. 'value': '0',
  115. },
  116. {
  117. 'key': 'frm',
  118. 'value': '0',
  119. },
  120. {
  121. 'key': 'u_tz',
  122. 'value': '360',
  123. },
  124. {
  125. 'key': 'u_his',
  126. 'value': '5',
  127. },
  128. {
  129. 'key': 'u_h',
  130. 'value': '1080',
  131. },
  132. {
  133. 'key': 'u_w',
  134. 'value': '1920',
  135. },
  136. {
  137. 'key': 'u_ah',
  138. 'value': '1032',
  139. },
  140. {
  141. 'key': 'u_aw',
  142. 'value': '1920',
  143. },
  144. {
  145. 'key': 'u_cd',
  146. 'value': '24',
  147. },
  148. {
  149. 'key': 'bc',
  150. 'value': '31',
  151. },
  152. {
  153. 'key': 'bih',
  154. 'value': '870',
  155. },
  156. {
  157. 'key': 'biw',
  158. 'value': '1121',
  159. },
  160. {
  161. 'key': 'brdim',
  162. 'value': '43,12,43,12,1920,0,1708,991,1137,870',
  163. },
  164. {
  165. 'key': 'vis',
  166. 'value': '1',
  167. },
  168. {
  169. 'key': 'wgl',
  170. 'value': 'true',
  171. },
  172. {
  173. 'key': 'ca_type',
  174. 'value': 'image',
  175. },
  176. ],
  177. },
  178. },
  179. 'playbackContext': {
  180. 'contentPlaybackContext': {
  181. 'html5Preference': 'HTML5_PREF_WANTS',
  182. 'lactMilliseconds': '2979',
  183. 'referer': 'https://www.youtube.com/watch?v=4MPWVKFaLD8',
  184. 'signatureTimestamp': 19117,
  185. 'autonavState': 'STATE_OFF',
  186. 'autoCaptionsDefaultOn': False,
  187. 'mdxContext': {},
  188. 'playerWidthPixels': 647,
  189. 'playerHeightPixels': 364,
  190. },
  191. },
  192. 'cpn': 'pwy4NMkpT8PY63hl',
  193. 'captionParams': {
  194. 'deviceCaptionsOn': True,
  195. },
  196. 'attestationRequest': {
  197. 'omitBotguardData': True,
  198. },
  199. }
  200.  
  201. print('\n[+] Получаю название канала...')
  202. channel_name = str(requests.post('https://www.youtube.com/youtubei/v1/player', params=params, headers=headers,
  203. json=json_data).json()['videoDetails']['author'])
  204.  
  205. for m in ["?", '"', "/", ":", "#", "|", ",", " ?", "?!", "?!", "? ", " / ", " | "]:
  206. channel_name = channel_name.replace(m, " ")
  207. print(f'[+] Название канала получено: "{channel_name}"')
  208. return channel_name
  209.  
  210.  
  211. def get_video_download(vid_id, channel_name):
  212. headers = {
  213. 'authority': 'downloader.freemake.com',
  214. 'sec-ch-ua': '" Not A;Brand";v="99", "Chromium";v="98", "Yandex";v="22"',
  215. 'dnt': '1',
  216. 'x-cf-country': 'RU',
  217. 'sec-ch-ua-mobile': '?0',
  218. 'x-user-platform': 'Win32',
  219. 'accept': 'application/json, text/javascript, */*; q=0.01',
  220. 'x-user-browser': 'YaBrowser',
  221. 'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) '
  222. 'Chrome/98.0.4758.141 YaBrowser/22.3.3.852 Yowser/2.5 Safari/537.36',
  223. 'x-analytics-header': 'UA-18256617-1',
  224. 'x-request-attempt': '1',
  225. 'x-user-id': '94119398-e27a-3e13-be17-bbe7fbc25874',
  226. 'sec-ch-ua-platform': '"Windows"',
  227. 'origin': 'https://www.freemake.com',
  228. 'sec-fetch-site': 'same-site',
  229. 'sec-fetch-mode': 'cors',
  230. 'sec-fetch-dest': 'empty',
  231. 'referer': 'https://www.freemake.com/ru/free_video_downloader/',
  232. 'accept-language': 'ru,en;q=0.9,uk;q=0.8',
  233. }
  234.  
  235. print(f'[+] Получаю название и ссылку на видео...')
  236. response = requests.get(f'https://downloader.freemake.com/api/videoinfo/{vid_id}', headers=headers).json()
  237. if response['qualities'][0]['qualityInfo']['itag'] == 22:
  238. video_title = str(response['metaInfo']['title'])
  239. for m in ["?", '"', "'", "/", ":", "#", "|", ",", " | "]:
  240. video_title = video_title.replace(m, "")
  241. url = response['qualities'][0]['url']
  242. print(f'[+] Название и ссылка получены. Начинаю загрузку: "{video_title}"...')
  243. if not os.path.isdir(f'{channel_name}'):
  244. os.mkdir(f'{channel_name}')
  245. print(f'[+] Создаю папку для сохранения видео...\n')
  246. else:
  247. print(f'[+] Папка для сохранения существует...\n')
  248. req = requests.get(url=url, headers=headers, stream=True)
  249. total = int(req.headers.get('content-length', 0))
  250. with open(f'{os.path.join(channel_name, f"{video_title}.mp4")}', 'wb') as file, tqdm(
  251. desc=f"{video_title[0:int(len(video_title) / 2)]}...",
  252. total=total,
  253. unit='iB',
  254. unit_scale=True,
  255. unit_divisor=1024,
  256. ) as bar:
  257. for data in req.iter_content(chunk_size=1024):
  258. size = file.write(data)
  259. bar.update(size)
  260. print(f'\n[+] Видео сохранено в папку: "{channel_name}".\n[+] Загрузка завершена.\n')
  261. else:
  262. user_change = input('\n[+] Нет видео в качестве 720р...\n[+] Загрузить в доступном качестве?:\n'
  263. '\t[1]: Да\n\t[2]: Нет\n\t>>> ')
  264. if user_change == "1":
  265. video_title = str(response['metaInfo']['title'])
  266. for m in ["?", '"', "'", "/", ":", "#", "|", ",", " | "]:
  267. video_title = video_title.replace(m, "")
  268. url = response['qualities'][0]['url']
  269. print(f'[+] Название и ссылка получены. Начинаю загрузку: "{video_title}"...')
  270. if not os.path.isdir(f'{channel_name}'):
  271. os.mkdir(f'{channel_name}')
  272. print(f'[+] Создаю папку для сохранения видео...\n')
  273. else:
  274. print(f'[+] Папка для сохранения существует...\n')
  275. req = requests.get(url=url, headers=headers, stream=True)
  276. total = int(req.headers.get('content-length', 0))
  277. with open(f'{os.path.join(channel_name, f"{video_title}.mp4")}', 'wb') as file, tqdm(
  278. desc=f"{video_title[0:int(len(video_title) / 2)]}...",
  279. total=total,
  280. unit='iB',
  281. unit_scale=True,
  282. unit_divisor=1024,
  283. ) as bar:
  284. for data in req.iter_content(chunk_size=1024):
  285. size = file.write(data)
  286. bar.update(size)
  287. print(f'\n[+] Видео сохранено в папку: "{channel_name}".\n[+] Загрузка завершена.\n')
  288. elif user_change == "2":
  289. main()
  290. return
  291. else:
  292. print('[-] Вы ввели чушь. Закрываю программу...')
  293. exit(0)
  294.  
  295.  
  296. def get_target_path(user_input):
  297. if user_input == "1":
  298. vid_id = input('\t[+] Введите ссылку на видео\n\t[+] Для выхода в меню введите: ex\n\t>>> ')
  299. if vid_id == 'ex':
  300. main()
  301. return
  302. while not "https://www.youtube.com" in vid_id:
  303. vid_id = input('\t[+] Введите ссылку на видео\n\t[+] Для выхода в меню введите: ex\n\t>>> ')
  304. if vid_id == 'ex':
  305. main()
  306. return
  307. if '&list' in vid_id:
  308. vid_id = vid_id.split("&")[0].split("=")[-1]
  309. else:
  310. vid_id = vid_id.split("=")[-1]
  311. channel_name = get_channel_name(vid_id)
  312. get_video_download(vid_id, channel_name)
  313. main()
  314. elif user_input == "2":
  315. while not os.path.isfile(user_path := input("\t[+] Введите путь к списку\n\t[+] Для выхода в меню введите: ex\n"
  316. "\t>>> ").replace('"', '')):
  317. if user_path == 'ex':
  318. main()
  319. return
  320. print(f"\n\t[+] Список {user_path} не найден\n")
  321. with open(f'{user_path}', 'r', encoding='utf-8') as file:
  322. video_list = file.readlines()
  323. for video in video_list:
  324. if '&list' in video:
  325. vid_id = video.split("&")[0].split("=")[-1]
  326. else:
  327. vid_id = video.split("=")[-1].strip()
  328. if video.strip() == "":
  329. continue
  330. else:
  331. channel_name = get_channel_name(vid_id)
  332. get_video_download(vid_id, channel_name)
  333. main()
  334. elif user_input == "3":
  335. vid_id = input('\t[+] Введите ссылку на плейлист\n\t[+] Для выхода в меню введите: ex\n\t>>> ')
  336. if vid_id == 'ex':
  337. main()
  338. return
  339. while not "https://www.youtube.com/playlist" in vid_id:
  340. vid_id = input('\t[+] Введите ссылку на плейлист\n\t[+] Для выхода в меню введите: ex\n\t>>> ')
  341. if vid_id == 'ex':
  342. main()
  343. return
  344. list_items = playlist_item(vid_id)
  345. print(f'[+] Видео в плейлисте: {len(list_items)}\n[+] Загружаю плейлист...')
  346. for item in list_items:
  347. channel_name = get_channel_name(item)
  348. time.sleep(0.3)
  349. get_video_download(item, channel_name)
  350. time.sleep(0.3)
  351. main()
  352. elif user_input == "4":
  353. exit(0)
  354. else:
  355. main()
  356.  
  357.  
  358. def main():
  359. get_target_path(input(f'\n[+] Выберите варианты загрузки:\n\t[1] Загрузить видео\n'
  360. f'\t[2] Загрузить видео из списка\n\t[3] Загрузить плейлист\n\t[4] Выход\n\t>>> '))
  361.  
  362.  
  363. if __name__ == "__main__":
  364. main()
  365.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement