Advertisement
Guest User

Boosty downloader

a guest
Apr 16th, 2023
7,210
3
Never
2
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.15 KB | None | 3 0
  1. # by gospodin@420blaze.it
  2. import requests
  3. import sys
  4. import os
  5. import subprocess
  6.  
  7. print(f"Введите ник:")
  8. try:
  9.     name = input()
  10. except Exception as err:
  11.     print(err)
  12.  
  13. cwd = os.getcwd()
  14. links_list = []
  15. media_album_payload = {"type": "all", "limit_by": "media", "offset": None}
  16. media_album_url = f"https://api.boosty.to/v1/blog/{name}/media_album/"
  17. headers = requests.utils.default_headers()
  18. headers.update(
  19.     {
  20.         "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/109.0.0.0 Safari/537.36"
  21.     }
  22. )
  23.  
  24.  
  25. # Create subdirectory
  26. try:
  27.     os.mkdir(name)
  28.     print("subfolder created")
  29. except Exception:
  30.     pass
  31.  
  32.  
  33. def get_media_album():
  34.     return requests.get(
  35.         media_album_url, params=media_album_payload, headers=headers
  36.     ).json()
  37.  
  38.  
  39. def get_media_album_offset(media_album):
  40.     is_last = media_album["extra"]["isLast"]
  41.     offset = media_album["extra"]["offset"]
  42.     if not is_last:
  43.         return offset
  44.     else:
  45.         return None
  46.  
  47.  
  48. def get_posts_from_album(media_album):
  49.     media_posts = media_album["data"]["mediaPosts"]
  50.     for media_post in media_posts:
  51.         for media in media_post["media"]:
  52.             if media["id"] != "00000000-0000-0000-0000-000000000000":
  53.                 if media["type"] == "image":
  54.                     yield get_image_link(media["id"])
  55.                 elif media["type"] == "ok_video":
  56.                     yield get_video_link(media["vid"])
  57.                 else:
  58.                     continue
  59.  
  60.  
  61. def get_image_link(id):
  62.     return "https://images.boosty.to/image/" + id
  63.  
  64.  
  65. def get_video_link(vid):
  66.     return "https://ok.ru/videoembed/" + vid
  67.  
  68.  
  69. def set_payload_offset(offset):
  70.     media_album_payload["offset"] = offset
  71.  
  72.  
  73. open(os.path.join(cwd, f"{name}/{name}.txt"), "w").close()
  74.  
  75. # fill list from generator
  76. while True:
  77.     media_album = get_media_album()
  78.     for i in get_posts_from_album(media_album):
  79.         links_list.append(i)
  80.  
  81.     next_offset = get_media_album_offset(media_album)
  82.     set_payload_offset(next_offset)
  83.     if next_offset == None:
  84.         break
  85.  
  86. # sort links
  87. links_list.sort()
  88.  
  89. # Separate images from videos
  90. video_links = [k for k in links_list if "videoembed" in k]
  91. images_links = [k for k in links_list if "images" in k]
  92.  
  93. with open(os.path.join(cwd, f"{name}/{name}.txt"), "a+") as file:
  94.     for i in links_list:
  95.         print(i)
  96.         file.write(i + "\n")
  97.  
  98. with open(os.path.join(cwd, f"{name}/{name}-video.txt"), "a+") as file:
  99.     for i in video_links:
  100.         print(i)
  101.         file.write(i + "\n")
  102.  
  103. # Download images
  104. for image_url in images_links:
  105.     print(f"download image {image_url}")
  106.     img_data = requests.get(image_url).content
  107.     image_name = image_url.split("/")[-1]
  108.     with open(os.path.join(cwd, f"{name}/{image_name}.jpg"), "wb") as handler:
  109.         handler.write(img_data)
  110.  
  111.  
  112. # Execute yt-dlp
  113. def exec_yt_dlp():
  114.     print("yt-dlp started")
  115.     filename = f"{name}-video.txt"
  116.     args = f"yt-dlp -a {cwd}/{name}/{filename} -P {cwd}/{name}"
  117.     subprocess.run(args, shell=True)
  118.  
  119.  
  120. try:
  121.     exec_yt_dlp()
  122. except Exception as err:
  123.     print(f"{name}")
  124.  
Advertisement
Comments
Add Comment
Please, Sign In to add comment
Advertisement