ytdl-org / youtube-dl

Command-line program to download videos from YouTube.com and other video sites
http://ytdl-org.github.io/youtube-dl/
The Unlicense
132.31k stars 10.03k forks source link

Add supervideo #22949

Closed fnicolo860 closed 5 years ago

fnicolo860 commented 5 years ago

Checklist

Example URLs

Description

Add supervideo.tv

remitamine commented 5 years ago

https://github.com/ytdl-org/youtube-dl#can-you-add-support-for-this-anime-video-site-or-site-which-shows-current-movies-for-free

fnicolo860 commented 5 years ago

I did not understand why they were not accepted

ballerburg9005 commented 4 months ago

You can use this selenium script to extract the m3u8 URL:

#!/bin/python
import sys
import random

if len(sys.argv) != 2:
    print("Usage: python script.py <url>")
    sys.exit(1)

my_user_agent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/92.0.4515.159 Safari/537.36"

from selenium import webdriver
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
from webdriver_manager.core.os_manager import ChromeType
from webdriver_manager.chrome import ChromeDriverManager
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.chrome.service import Service as ChromiumService
from selenium.webdriver.support import expected_conditions as EC
from selenium_stealth import stealth
import time
import json
from selenium.webdriver.common.by import By
import json

from selenium.webdriver import ActionChains
from selenium.webdriver.common.actions.action_builder import ActionBuilder
from selenium.webdriver.common.actions.mouse_button import MouseButton
from selenium.webdriver.common.by import By

desired_capabilities = DesiredCapabilities.CHROME
desired_capabilities["goog:loggingPrefs"] = {"performance": "ALL"}

options = webdriver.ChromeOptions()

options.add_argument("--no-sandbox")
options.add_argument("--headless")
options.add_argument('--disable-dev-shm-usage')
options.add_argument("start-maximized")
options.add_argument("--autoplay-policy=no-user-gesture-required")
options.add_argument("disable-infobars")
options.add_argument("--disable-extensions")
options.add_argument("--ignore-certificate-errors")
options.add_argument("--mute-audio")
options.add_argument("--disable-notifications")
options.add_argument("--disable-popup-blocking")
options.add_argument("--disable-web-security")
options.add_argument("--allow-running-insecure-content")
options.add_argument("--enable-logging")
options.add_argument("--log-level=3")
#options.add_argument(f'user-agent={desired_capabilities}')
options.add_argument('user-agent=Mozilla/'+str(random.randint(4, 5))+'.0 (X11; '+random.choice(["Linux", "Windows"])+' x86_64) AppleWebKit/'+str(random.randint(400, 626))+'.'+str(random.randint(5, 50))+' (KHTML, like Gecko) Chrome/'+str(random.randint(100, 126))+'.0.0.0 Safari/'+str(random.randint(500, 726))+'.'+str(random.randint(10, 40))+'')
#options.add_experimental_option("excludeSwitches", ["enable-automation"])
#options.add_experimental_option('useAutomationExtension', False) 

driver = webdriver.Chrome(service=ChromiumService(ChromeDriverManager(chrome_type=ChromeType.CHROMIUM).install()),
                           options=options)

stealth(driver,
        languages=["en-US", "en"],
        vendor="Google Inc.",
        platform="Win64",
        webgl_vendor="Intel Inc.",
        renderer="Intel Iris OpenGL Engine",
        fix_hairline=True,
        )

title = ""
def get_m3u8_urls(url): 
   driver.get(url)
#   driver.execute_script("window.scrollTo(0, 20000)")
#   WebDriverWait(driver, 10).until(EC.presence_of_element_located((By.TAG_NAME, 'title')))
   time.sleep(3)
#   driver.execute_script("window.scrollTo(0, 0)")

#   clickable = driver.find_elements(By.CSS_SELECTOR, ".download__top")
#   for e in clickable:
#       print("clicked on video ... "+str(e))
#       ActionChains(driver).click(e).perform()

   action = ActionChains(driver)
   action.move_by_offset(str(int(driver.get_window_size()['width'] / 2)), "100").click().perform()

   time.sleep(3)

   global title 
   title = driver.title
   logs = driver.get_log("performance")
   url_list = []

   for log in logs:
       network_log = json.loads(log["message"])["message"]
       if ("Network.response" in network_log["method"]
           or "Network.request" in network_log["method"]
           or "Network.webSocket" in network_log["method"]):
           if 'request' in network_log["params"]:
               if 'url' in network_log["params"]["request"]:
#                   print(network_log["params"]["request"]["url"])
                   if 'm3u8' in network_log["params"]["request"]["url"] or '.mp4' in network_log["params"]["request"]["url"]:
                       if "blob" not in network_log["params"]["request"]["url"]:
                           if '.m3u8' in network_log["params"]["request"]["url"]:
                               url_list.append( network_log["params"]["request"]["url"] )

   driver.close()
   return url_list

if __name__ == "__main__":

   url = sys.argv[1]
   url_list = get_m3u8_urls(url)
#   print(url_list)
   print(title)
   for u in url_list:
        print(u)

Bash command to paste URLs in (tries m3u8 as fallback):

DOWNLOAD=0; while read line; do DOWNLOAD="$(($DOWNLOAD+1))"; if ! youtube-dl "$line"; then echo "trying m3u8 extractor ..."; EXTRACT="$(m3u8_extractor.py "$line")"; youtube-dl --output "$DOWNLOAD---$(echo "$line" | sed "s#http[s]*://##g" | sed "s/[^a-zA-Z0-9_]/_/g")--$(echo "$EXTRACT" | head -n 1 | sed "s/[^a-zA-Z0-9_]/_/g").%(ext)s" "$(echo "$EXTRACT" | grep master.m3u8)"; fi;done

You have to fiddle a bit to make this script work, depending on whether or not you use Chromium as well and not Chrome etc. On Windows use MSYS2 to get bash etc., but might be a bit of a stretch.

Edit: I don't know why but at some times of the day the script works reliably, then it does not.