i made this code to help anyone who wants to download or embed a video from a streamtape without having to go through their stupid site.
- Java (Jsoup)
- Python (requests and beautifulsoup)
private static String SteamtapeGetDlLink(String link) {
try {
if (link.contains("/e/"))
link = link.replace("/e/", "/v/");
Document doc = Jsoup.connect(link).get();
String htmlSource = doc.html();
Pattern norobotLinkPattern = Pattern.compile("document\\.getElementById\\('norobotlink'\\)\\.innerHTML = (.+);");
Matcher norobotLinkMatcher = norobotLinkPattern.matcher(htmlSource);
if (norobotLinkMatcher.find()) {
String norobotLinkContent = norobotLinkMatcher.group(1);
Pattern tokenPattern = Pattern.compile("token=([^&']+)");
Matcher tokenMatcher = tokenPattern.matcher(norobotLinkContent);
if (tokenMatcher.find()) {
String token = tokenMatcher.group(1);
Elements divElements = doc.select("div#ideoooolink[style=display:none;]");
if (!divElements.isEmpty()) {
String streamtape = ((Element)Objects.<Element>requireNonNull(divElements.first())).text();
String fullUrl = "https:/" + streamtape + "&token=" + token;
return fullUrl + "&dl=1s";
}
}
}
} catch (Exception exception) {}
return null;
}PYTHON CODE: ( Suggested by Davide Beatrici )
import re
import requests
from bs4 import BeautifulSoup
def steamtape_get_dl_link(link):
try:
if "/e/" in link:
link = link.replace("/e/", "/v/")
response = requests.get(link)
response.raise_for_status()
html_source = response.text
norobot_link_pattern = re.compile(r"document\.getElementById\('norobotlink'\)\.innerHTML = (.+?);")
norobot_link_matcher = norobot_link_pattern.search(html_source)
if norobot_link_matcher:
norobot_link_content = norobot_link_matcher.group(1)
token_pattern = re.compile(r"token=([^&']+)")
token_matcher = token_pattern.search(norobot_link_content)
if token_matcher:
token = token_matcher.group(1)
soup = BeautifulSoup(html_source, 'html.parser')
div_element = soup.select_one("div#ideoooolink[style='display:none;']")
if div_element:
streamtape = div_element.get_text()
full_url = f"https:/{streamtape}&token={token}"
return f"{full_url}&dl=1s"
except Exception as exception:
print(f"An error occurred: {exception}")
return NoneJAVASCRIPT CODE: ( Suggested by Pigamer37 )
function GetStreamTapeLink(url) {
const reqURL = url.replace("/e/", "/v/")
return fetch(reqURL).then((resp) => {
if ((!resp.ok) || resp.status !== 200) throw Error(`HTTP error! Status: ${resp.status}`)
if (resp === undefined) throw Error('Undefined response!')
return resp.text()
}).then((data) => {
const noRobotLinkPattern = /document\.getElementById\('norobotlink'\)\.innerHTML = (.+?);/g
const matches = noRobotLinkPattern.exec(data)
if (matches[1]) {
const tokenPattern = /token=([^&']+)/g
const tokenMatches = tokenPattern.exec(matches[1])
if (tokenMatches[1]) { //You can use cheerio if you want for this
const STPattern = /id\s*=\s*"ideoooolink"/g
const tagEnd = data.indexOf(">", STPattern.exec(data).index) + 1
const streamtape = data.substring(tagEnd, data.indexOf("<", tagEnd))
return `https:/${streamtape}&token=${tokenMatches[1]}&dl=1s`
} else console.log("No token")
} else console.log("No norobotlink")
})
}