text
stringlengths 0
93.6k
|
---|
f["name"] = field['name']
|
f["value"] = field['value']
|
f["inline"] = field['inline']
|
embed["fields"].append(f)
|
data["embeds"].append(dict(embed))
|
empty = all(not d for d in data["embeds"])
|
if empty and 'content' not in data:
|
print('You cant post an empty payload.')
|
if empty: data['embeds'] = []
|
return json.dumps(data, indent=4)
|
def post(self):
|
"""
|
Send the JSON formated object to the specified `self.url`.
|
"""
|
headers = {'Content-Type': 'application/json'}
|
result = requests.post(self.url, data=self.json, headers=headers, timeout=10, verify=False)
|
# <FILESEP>
|
import os
|
import json
|
import time
|
import sponsorblock as sb
|
from yt_dlp import YoutubeDL
|
class SBRemoteCache():
|
def __init__ (self, fn="vidcache.json", debug = False):
|
self.filename = fn
|
self.cache = {}
|
self.load_cache()
|
self.debug = debug
|
self.sbclient = sb.Client()
|
self.max_age = 43200
|
def search(self, arg):
|
if self.debug:
|
print (f"New search: Looking up YT data for video \"{arg}\" ")
|
ydl_opts = {
|
'quiet': True,
|
'noplaylist': True,
|
'default_search': 'ytsearch2',
|
'format': 'best',
|
}
|
with YoutubeDL(ydl_opts) as ydl:
|
try:
|
result = ydl.extract_info(arg, download=False)
|
if 'entries' in result and len(result['entries']) > 0:
|
return result['entries'][0]
|
else:
|
print("No results found.")
|
return None
|
except Exception as e:
|
print(f"An error occurred: {e}")
|
return None
|
def load_cache(self):
|
if os.path.exists(self.filename):
|
self.cache = json.load(open(self.filename))
|
else:
|
self.cache = {"titles": {}, "segments": {}, "fresh": {}}
|
self.save_cache()
|
if "fresh" not in self.cache.keys():
|
self.cache["fresh"] = {}
|
def save_cache(self):
|
json.dump(self.cache, open(self.filename, "w"))
|
def remove_id_from_fresh(self, id, defer_save=False):
|
nfresh = {}
|
ofresh = self.cache["fresh"]
|
fnd = False
|
for k in ofresh:
|
if id != k:
|
nfresh[id] = ofresh[id]
|
else:
|
fnd = True
|
if not defer_save:
|
self.save_cache()
|
return fnd
|
def remove_id_from_segments(self, id, defer_save=False):
|
sfnd = False
|
new_segments = {}
|
segments = self.cache["segments"]
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.