Closed preginald closed 4 years ago
Did u figure it out ?
I thought I figured it out when I restarted mIRC and it started working again but the issue is still there. I'm troubleshooting it now. Do you have any ideas?
I'm unable to get to the bottom of the NAME_INUSE error. It's not a deal breaker though. I will hit the same endpoint using autohotkey and report back in a couple of days.
edit: suffice to say that I am able to fetch data with JSON-For-Mirc the first time but fails on subsequent calls with the above error.
NAME_IN_USE
indicates that the name you are trying to use for a json handler is... already in use.
Taking your example, the name of the handler is youtube
. If you open one json handler, and before you close it, attempt to open another named youtube you will get that error:
alias example {
JSONOpen example {}
if ($JSONError) {
echo JSON ERROR: $v1
return
}
; attempt to reuse the name 'example' without closing the one above
JSONOpen example {}
if ($JSONError) {
echo JSON ERROR 2: $v1
}
; cleanup
JSONClose example
}
I'm not sure what's going on but after shutting down my pc last night and testing the same script today it seems to be working properly. I do close the json handler as seen below.
alias GetYouTubeVideoMeta {
var %url = https://www.googleapis.com/youtube/v3/videos?id= $+ $1 $+ &key= $+ %youtubekey $+ &part=snippet,contentDetails
JSONOpen -u youtube %url
if ($JSONError) {
;; handle error
echo -a $JSONError %url
}
var %title = $json(youtube,items,0,snippet,title).value
var %channel = $json(youtube,items,0,snippet,channelTitle).value
var %duration = $GetDurationFromYouTubeMeta($json(youtube,items,0,contentDetails,duration).value)
echo -a %title %channel %duration
JSONClose youtube
return %title from %channel duration %duration
}
I think what I'll do is create a youtube handler that contains the youtube video id so it is unique. That should minimise this problem.
I've changed my code to this where $1 is the youtube_id
alias GetYouTubeVideoMeta {
var %v = youtube_ $+ $1
var %url = https://www.googleapis.com/youtube/v3/videos?id= $+ $1 $+ &key= $+ %youtubekey $+ &part=snippet,contentDetails
JSONOpen -u %v %url
if ($JSONError) {
;; handle error
echo -a $JSONError %url
}
var %title = $json(%v,items,0,snippet,title).value
var %channel = $json(%v,items,0,snippet,channelTitle).value
var %duration = $GetDurationFromYouTubeMeta($json(%v,items,0,contentDetails,duration).value)
echo -a %title %channel %duration
JSONClose %v
return %title from %channel duration %duration
}
I just wanted to share that my script was failing due to
NAME_INUSE
and I couldn't figure out why since the call worked properly when fetching via browser.Eventually I restarted mIRC and the script worked again.
This is my script
Hope it helps others