Created
January 30, 2025 17:26
-
-
Save anarcie/9db61173f58923a9fba2e22f8e5924df to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import requests | |
import json | |
import sys | |
import datetime | |
import pytz | |
import os | |
import glob | |
import subprocess | |
iw_url = "https://api.banned.video/graphql" | |
iw_querystring = {"Apollographql-Client-Name":"banned-web"} | |
iw_playlist = "5d81058ce2ea200013c01580" | |
iw_limit = 10 | |
iw_offset = 0 | |
iw_downloadLocation = "/media/septenary/streams/infowars/infowars_" | |
iw_pDownloadedLocations = [ | |
'/media/septenary/streams/infowars/*/*.mp4', | |
'/media/septenary/streams/infowars/*.mp4' | |
] | |
iw_payloads = { | |
'full-video-playlist': "{\"query\":\"query GetPlaylistVideos($id: String!, $limit: Float, $offset: Float) {\\n getPlaylist(id: $id) {\\n _id\\n videos(limit: $limit, offset: $offset) {\\n ...DisplayVideoFields\\n __typename\\n }\\n __typename\\n }\\n}\\n\\nfragment DisplayVideoFields on Video {\\n _id\\n title\\n summary\\n playCount\\n likeCount\\n angerCount\\n largeImage\\n embedUrl\\n published\\n videoDuration\\n channel {\\n _id\\n title\\n avatar\\n __typename\\n }\\n createdAt\\n __typename\\n}\\n\\n\",\"operationName\":\"GetPlaylistVideos\",\"variables\":\"{\\n \\\"id\\\": \\\"|ID|\\\",\\n \\\"limit\\\": " + str(iw_limit) + ",\\n \\\"offset\\\": " + str(iw_offset) + "\\n}\"}", | |
'video-lookup': "{\"query\":\"query GetVideo($id: String!) {\\n getVideo(id: $id) {\\n ...DisplayVideoFields\\n streamUrl\\n directUrl\\n liked\\n disliked\\n audio\\n unlisted\\n live\\n tags {\\n _id\\n name\\n __typename\\n }\\n sale {\\n _id\\n text\\n textSale\\n description\\n url\\n videoUpload {\\n cloudflareVideoUID\\n __typename\\n }\\n __typename\\n }\\n __typename\\n }\\n}\\n\\nfragment DisplayVideoFields on Video {\\n _id\\n title\\n summary\\n playCount\\n likeCount\\n angerCount\\n largeImage\\n embedUrl\\n published\\n videoDuration\\n channel {\\n _id\\n title\\n avatar\\n __typename\\n }\\n createdAt\\n __typename\\n}\\n\",\"operationName\":\"GetVideo\",\"variables\":\"{\\n \\\"id\\\": \\\"|ID|\\\"\\n}\"}" | |
} | |
iw_headers = { | |
#"cookie": "__cf_bm=rTKMiXBTH8Ey2c5eeSKHltzo5THW8WUmYUgh_dsecI4-1718041949-1.0.1.1-UGklVdUDFaMWz8TmL7ZLrdjSwZwLTwGcZSiJzTBVVwf3LxcL9G0Mnh0XhSzV1ZJaX5X8yo4JtZYyJpLpIPMDyA", | |
"User-Agent": "insomnia/9.2.0", | |
"Content-Type": "application/json" | |
} | |
def alreadyDownloaded(pFilenames): | |
folderGlob = sorted(glob.glob('/media/septenary/streams/infowars/*/*.mp4') + glob.glob('/media/septenary/streams/infowars/*.mp4')) | |
jFilenames = [os.path.basename(x) for x in folderGlob] | |
for pFilename in pFilenames: | |
jPFilename = os.path.basename(pFilename) | |
if jPFilename in jFilenames: | |
print(f" Already Downloaded ({pFilename})") | |
return True | |
else: | |
print(f" Not Found: {pFilename}") | |
return False | |
def downloadFile(vidObj): | |
print("\n Checking For Previous Downloads") | |
for idx,x in enumerate(vidObj['episodeNames']): | |
print(f" Filename V{idx+1}: {x}") | |
if alreadyDownloaded(vidObj['episodeNames']) is False: | |
outFile = vidObj['episodeNameV2'] | |
fileUrl = vidObj['directUrl'] | |
print(f"\n Downloading: {fileUrl}\n Destination: {outFile}\n") | |
subprocess.call(("axel", "-n 5", "-a", "-o", outFile, fileUrl)) | |
def sendRequest(payload): | |
response = requests.request("POST", iw_url, data=payload, headers=iw_headers, params=iw_querystring) | |
return response.json() | |
def getVideo(vid): | |
jsonObj = sendRequest(iw_payloads['video-lookup'].replace("|ID|", vid)) | |
if jsonObj['data'] is not None: | |
jsonObj = jsonObj['data']['getVideo'] | |
# Create filename based on the created time, convert from UTC to MST | |
local = datetime.datetime.fromisoformat(jsonObj['createdAt']).replace(tzinfo=datetime.timezone.utc).astimezone() | |
local_formatted = local.strftime('%Y-%m-%d-%I-%M') | |
# New filenaming, minus 6 hours as Alex doesnt upload videos till 11PM and | |
# will mess up episode naming | |
localV2 = local - datetime.timedelta(hours=6, minutes=0) | |
localV2_formatted = localV2.strftime('%Y-%m-%d-%I-%M') | |
iw_episode_name = "/media/septenary/streams/infowars/infowars_" | |
iw_episode_nameV1 = iw_episode_name + local_formatted + ".mp4" | |
iw_episode_nameV2 = iw_episode_name + localV2_formatted + ".mp4" | |
episodeNames = [iw_episode_nameV2, iw_episode_nameV1] | |
return {'title': jsonObj['title'], | |
'desc' : jsonObj['summary'], | |
'createdAt': jsonObj['createdAt'], | |
'directUrl': jsonObj['directUrl'], | |
'localTime':local_formatted, | |
'localTimeV2': localV2_formatted, | |
'episodeNameV1' : iw_episode_nameV1, | |
'episodeNameV2' : iw_episode_nameV2, | |
'episodeNames': episodeNames | |
} | |
return None | |
def getAllEpisodes(): | |
jsonObj = sendRequest(iw_payloads['full-video-playlist'].replace("|ID|", iw_playlist)) | |
jsonObj = jsonObj['data']['getPlaylist']['videos'] | |
print(f"\nProcessing playlist: {iw_playlist}") | |
for video in jsonObj: | |
print(f"\nProcessing Video: {video['_id']} Created @ {video['createdAt']}\n Title: {video['title'][:50]}\n Desc:{video['summary'][:50]}") | |
videoData = getVideo(video['_id']) | |
if videoData is not None: | |
downloadFile(videoData) | |
else: | |
print(" No Video Data Found") | |
print("\nFinished Processing.\n") | |
getAllEpisodes() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment