@@ -71,6 +71,13 @@ import {
71
71
sendDirectMessage ,
72
72
SendDirectMessageResponse ,
73
73
} from './messages' ;
74
+ import {
75
+ fetchAudioSpaceById ,
76
+ fetchAuthenticatePeriscope ,
77
+ fetchBrowseSpaceTopics ,
78
+ fetchCommunitySelectQuery , fetchLiveVideoStreamStatus , fetchLoginTwitterToken
79
+ } from './spaces' ;
80
+ import { AudioSpace , Community , LiveVideoStreamStatus , LoginTwitterTokenResponse , Subtopic } from './types/spaces' ;
74
81
75
82
const twUrl = 'https://twitter.com' ;
76
83
const UserTweetsUrl =
@@ -899,4 +906,97 @@ export class Scraper {
899
906
900
907
return res . value ;
901
908
}
909
+
910
+ /**
911
+ * Retrieves the details of an Audio Space by its ID.
912
+ * @param id The ID of the Audio Space.
913
+ * @returns The details of the Audio Space.
914
+ */
915
+ public async getAudioSpaceById ( id : string ) : Promise < AudioSpace > {
916
+ const variables = {
917
+ id,
918
+ isMetatagsQuery : false ,
919
+ withReplays : true ,
920
+ withListeners : true ,
921
+ } ;
922
+
923
+ return await fetchAudioSpaceById ( variables , this . auth ) ;
924
+ }
925
+
926
+ /**
927
+ * Retrieves available space topics.
928
+ * @returns An array of space topics.
929
+ */
930
+ public async browseSpaceTopics ( ) : Promise < Subtopic [ ] > {
931
+ return await fetchBrowseSpaceTopics ( this . auth ) ;
932
+ }
933
+
934
+ /**
935
+ * Retrieves available communities.
936
+ * @returns An array of communities.
937
+ */
938
+ public async communitySelectQuery ( ) : Promise < Community [ ] > {
939
+ return await fetchCommunitySelectQuery ( this . auth ) ;
940
+ }
941
+
942
+ /**
943
+ * Retrieves the status of an Audio Space stream by its media key.
944
+ * @param mediaKey The media key of the Audio Space.
945
+ * @returns The status of the Audio Space stream.
946
+ */
947
+ public async getAudioSpaceStreamStatus (
948
+ mediaKey : string ,
949
+ ) : Promise < LiveVideoStreamStatus > {
950
+ return await fetchLiveVideoStreamStatus ( mediaKey , this . auth ) ;
951
+ }
952
+
953
+ /**
954
+ * Retrieves the status of an Audio Space by its ID.
955
+ * This method internally fetches the Audio Space to obtain the media key,
956
+ * then retrieves the stream status using the media key.
957
+ * @param audioSpaceId The ID of the Audio Space.
958
+ * @returns The status of the Audio Space stream.
959
+ */
960
+ public async getAudioSpaceStatus (
961
+ audioSpaceId : string ,
962
+ ) : Promise < LiveVideoStreamStatus > {
963
+ const audioSpace = await this . getAudioSpaceById ( audioSpaceId ) ;
964
+
965
+ const mediaKey = audioSpace . metadata . media_key ;
966
+ if ( ! mediaKey ) {
967
+ throw new Error ( 'Media Key not found in Audio Space metadata.' ) ;
968
+ }
969
+
970
+ return await this . getAudioSpaceStreamStatus ( mediaKey ) ;
971
+ }
972
+
973
+ /**
974
+ * Authenticates Periscope to obtain a token.
975
+ * @returns The Periscope authentication token.
976
+ */
977
+ public async authenticatePeriscope ( ) : Promise < string > {
978
+ return await fetchAuthenticatePeriscope ( this . auth ) ;
979
+ }
980
+
981
+ /**
982
+ * Logs in to Twitter via Proxsee using the Periscope JWT.
983
+ * @param jwt The JWT obtained from AuthenticatePeriscope.
984
+ * @returns The response containing the cookie and user information.
985
+ */
986
+ public async loginTwitterToken (
987
+ jwt : string ,
988
+ ) : Promise < LoginTwitterTokenResponse > {
989
+ return await fetchLoginTwitterToken ( jwt , this . auth ) ;
990
+ }
991
+
992
+ /**
993
+ * Orchestrates the flow: get token -> login -> return Periscope cookie
994
+ */
995
+ public async getPeriscopeCookie ( ) : Promise < string > {
996
+ const periscopeToken = await this . authenticatePeriscope ( ) ;
997
+
998
+ const loginResponse = await this . loginTwitterToken ( periscopeToken ) ;
999
+
1000
+ return loginResponse . cookie ;
1001
+ }
902
1002
}
0 commit comments