File tree Expand file tree Collapse file tree 1 file changed +49
-0
lines changed Expand file tree Collapse file tree 1 file changed +49
-0
lines changed Original file line number Diff line number Diff line change 1+ /*
2+ activation_example:!music https://music.apple.com/us/song/inferna/1814573909
3+ regex:!music
4+ flags:gmi
5+ */
6+
7+ var input = current . text . trim ( ) ;
8+ var link = input . replace ( '!music ' , '' ) ;
9+ var tapeLinkObj = getTapeLink ( link ) ;
10+ var msg ;
11+ if ( tapeLinkObj . status == '200' && tapeLinkObj . body . success ) {
12+ msg = `<https://${ tapeLinkObj . body . shareableLink } |Stream this song on other platforms>` ;
13+ } else {
14+ msg = `Something went wrong. Please check that you entered a full link. Error details: ${ tapeLinkObj . body . error } ` ;
15+ }
16+
17+ gs . info ( msg ) ;
18+
19+ function getTapeLink ( url ) {
20+
21+ try {
22+ var endpointURL = 'https://www.tapelink.io/api/generate-link' ;
23+
24+ var request = new sn_ws . RESTMessageV2 ( ) ;
25+ request . setHttpMethod ( 'post' ) ;
26+ request . setEndpoint ( endpointURL ) ;
27+ request . setRequestHeader ( 'Content-Type' , 'application/json' ) ;
28+ request . setRequestHeader ( 'Accept' , 'application/json' ) ;
29+ var payload = {
30+ "url" : url
31+ } ;
32+
33+ request . setRequestBody ( JSON . stringify ( payload ) ) ;
34+
35+
36+ var response = request . execute ( ) ;
37+
38+ var httpStatus = response . getStatusCode ( ) ;
39+ var responseBody = JSON . parse ( response . getBody ( ) ) ;
40+
41+ return {
42+ body : responseBody ,
43+ status : httpStatus
44+ } ;
45+
46+ } catch ( ex ) {
47+ gs . error ( 'An error occurred in the RESTMessageV2 script: ' + ex . getMessage ( ) ) ;
48+ }
49+ }
You can’t perform that action at this time.
0 commit comments