mirror of
https://git.vectorsigma.ru/public/tubearchivist.git
synced 2026-08-04 19:09:29 +00:00
Get all sponsorblock segment types (testing) (#1021)
* Pull all sponsorblock segment types * Respect segment skip on `segment.actionType` * Lint with `prettier` * Lint with `black`
This commit is contained in:
@@ -48,11 +48,28 @@ class SponsorBlock:
|
|||||||
|
|
||||||
def get_timestamps(self, youtube_id):
|
def get_timestamps(self, youtube_id):
|
||||||
"""get timestamps from the API"""
|
"""get timestamps from the API"""
|
||||||
url = f"{self.API}/skipSegments?videoID={youtube_id}"
|
url = f"{self.API}/skipSegments"
|
||||||
headers = {"User-Agent": self.user_agent}
|
headers = {"User-Agent": self.user_agent}
|
||||||
|
categories = [
|
||||||
|
"sponsor",
|
||||||
|
"selfpromo",
|
||||||
|
"interaction",
|
||||||
|
"intro",
|
||||||
|
"outro",
|
||||||
|
"preview",
|
||||||
|
"music_offtopic",
|
||||||
|
"poi_highlight",
|
||||||
|
"filler",
|
||||||
|
]
|
||||||
|
params = {
|
||||||
|
"videoID": youtube_id,
|
||||||
|
"category": categories,
|
||||||
|
}
|
||||||
print(f"{youtube_id}: get sponsorblock timestamps")
|
print(f"{youtube_id}: get sponsorblock timestamps")
|
||||||
try:
|
try:
|
||||||
response = requests.get(url, headers=headers, timeout=10)
|
response = requests.get(
|
||||||
|
url, headers=headers, params=params, timeout=10
|
||||||
|
)
|
||||||
except (requests.ReadTimeout, requests.ConnectionError) as err:
|
except (requests.ReadTimeout, requests.ConnectionError) as err:
|
||||||
print(f"{youtube_id}: sponsorblock API error: {str(err)}")
|
print(f"{youtube_id}: sponsorblock API error: {str(err)}")
|
||||||
return False
|
return False
|
||||||
@@ -75,9 +92,17 @@ class SponsorBlock:
|
|||||||
|
|
||||||
def _get_sponsor_dict(self, all_segments):
|
def _get_sponsor_dict(self, all_segments):
|
||||||
"""format and process response"""
|
"""format and process response"""
|
||||||
_ = [i.pop("description", None) for i in all_segments]
|
|
||||||
has_unlocked = not any(i.get("locked") for i in all_segments)
|
has_unlocked = not any(i.get("locked") for i in all_segments)
|
||||||
|
|
||||||
|
# Set only sponsor to skip (retain legacy behaviour)
|
||||||
|
categories_skip = ["sponsor"]
|
||||||
|
for segment in all_segments:
|
||||||
|
segment_category = segment["category"]
|
||||||
|
if segment_category in categories_skip:
|
||||||
|
segment["actionType"] = "skip"
|
||||||
|
else:
|
||||||
|
segment["actionType"] = "none"
|
||||||
|
|
||||||
sponsor_dict = {
|
sponsor_dict = {
|
||||||
"last_refresh": self.last_refresh,
|
"last_refresh": self.last_refresh,
|
||||||
"has_unlocked": has_unlocked,
|
"has_unlocked": has_unlocked,
|
||||||
|
|||||||
@@ -70,9 +70,11 @@ const handleTimeUpdate =
|
|||||||
|
|
||||||
if (sponsorBlock && sponsorBlock.segments) {
|
if (sponsorBlock && sponsorBlock.segments) {
|
||||||
sponsorBlock.segments.forEach((segment: SponsorBlockSegmentType) => {
|
sponsorBlock.segments.forEach((segment: SponsorBlockSegmentType) => {
|
||||||
|
const actionType = segment.actionType;
|
||||||
|
const doSkip = actionType == 'skip';
|
||||||
const [from, to] = segment.segment;
|
const [from, to] = segment.segment;
|
||||||
|
|
||||||
if (currentTime >= from && currentTime <= from + 0.3) {
|
if (doSkip && currentTime >= from && currentTime <= from + 0.3) {
|
||||||
videoTag.currentTarget.currentTime = to;
|
videoTag.currentTarget.currentTime = to;
|
||||||
|
|
||||||
setSponsorSegmentSkipped?.((segments: SponsorSegmentsSkippedType) => {
|
setSponsorSegmentSkipped?.((segments: SponsorSegmentsSkippedType) => {
|
||||||
|
|||||||
Reference in New Issue
Block a user