11import { BaseHelper , VideoHelperError } from "./base" ;
2+ import { MinimalVideoData } from "../types/client" ;
23
34import * as Sap from "@vot.js/shared/types/helpers/sap" ;
45
@@ -38,7 +39,23 @@ export default class TwitchHelper extends BaseHelper {
3839 return `${ channelName } /clip/${ isEmbed ? clipId : clearPathname } ` ;
3940 }
4041
41- async getVideoId ( url : URL ) {
42+ // eslint-disable-next-line @typescript-eslint/require-await
43+ async getVideoData ( videoId : string ) : Promise < MinimalVideoData | undefined > {
44+ const title = document . querySelector < HTMLElement > (
45+ '[data-a-target="stream-title"], [data-test-selector="stream-info-card-component__subtitle"]' ,
46+ ) ?. innerText ;
47+ const isStream = ! ! document . querySelector (
48+ '[data-a-target="animated-channel-viewers-count"], .channel-status-info--live, .top-bar--pointer-enabled .tw-channel-status-text-indicator' ,
49+ ) ;
50+
51+ return {
52+ url : this . service ! . url + videoId ,
53+ isStream,
54+ title,
55+ } ;
56+ }
57+
58+ async getVideoId ( url : URL ) : Promise < string | undefined > {
4259 const pathname = url . pathname ;
4360 if ( / ^ m \. t w i t c h \. t v $ / . test ( pathname ) ) {
4461 return / v i d e o s \/ ( [ ^ / ] + ) / . exec ( url . href ) ?. [ 0 ] ?? pathname . slice ( 1 ) ;
@@ -56,6 +73,19 @@ export default class TwitchHelper extends BaseHelper {
5673 return await this . getClipLink ( pathname , url . searchParams . get ( "clip" ) ) ;
5774 }
5875
59- return / (?: v i d e o s ) \/ ( [ ^ / ] + ) / . exec ( pathname ) ?. [ 0 ] ;
76+ const videoPath = / (?: v i d e o s ) \/ ( [ ^ / ] + ) / . exec ( pathname ) ;
77+ if ( videoPath ) {
78+ return videoPath [ 0 ] ;
79+ }
80+
81+ const isUserOfflinePage = document . querySelector < HTMLLinkElement > (
82+ ".home-offline-hero .tw-link" ,
83+ ) ;
84+ if ( isUserOfflinePage ?. href ) {
85+ const pageUrl = new URL ( isUserOfflinePage . href ) ;
86+ return / (?: v i d e o s ) \/ ( [ ^ / ] + ) / . exec ( pageUrl . pathname ) ?. [ 0 ] ;
87+ }
88+
89+ return document . querySelector ( ".persistent-player" ) ? pathname : undefined ;
6090 }
6191}
0 commit comments