HelpAsync method in K-Relay

Posts 1–4 of 4 · Page 1 of 1
Async method in K-Relay
Writing a K-Relay script that downloads the closed captioning off of a youtube video and plays it back in chat. My problem is that the one of the libraries that I am using uses asynchronous methods. K-Relay does not seem to like this and will not load anything past my plugin. The library is YoutubeExplode.
Thanks!

Edit:
I guess i forgot to put a question in here. I was wondering if there is any way to call the method, and get the same return, without using an asynchronous method. Otherwise is it possible to edit the library and remove the asynchronous methods? Would this damage the functionality of the program?

Code:
namespace CaptionSpeak
{
    public class Plugin : IPlugin
    {
        string userPath = Path.Combine(Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().CodeBase), "CaptionSpeak"); //gets working directory of the K-Relay plugin

        public string GetAuthor()
        {
            return "ElGato";
        }

        public string[] GetCommands()
        {
            string[] TODO = new String[1];
            TODO[1] = "TODO";
            return TODO;
        }

        public string GetDescription()
        {
            return "TODO";
        }

        public string GetName()
        {
            return "CaptionSpeak";
        }

        public void Initialize(Proxy proxy)
        {
            proxy.HookCommand("capspeak", captionDownload);
            Console.WriteLine(userPath);
            if (!File.Exists(userPath)) //creates directory for downloads if not already created
            {
                Directory.CreateDirectory(userPath);
            }
        }

        private void captionParse(string file) //parses the file, removing timestamps and the like
        {
            var parser = new SubtitlesParser.Classes.Parsers.SrtParser();
            using (var fileStream = File.OpenRead(file))
            {
                var items = parser.ParseStream(fileStream, Encoding.Unicode);
            }
        }

        private PlayerTextPacket playback(string path) //TODO chats the text from the caption file
        {
            PlayerTextPacket captionSpeak = (PlayerTextPacket)Packet.Create(PacketType.PLAYERTEXT);
            captionSpeak.Text = " ";
            return captionSpeak;
            
        }

        private async void captionDownload(Client client, string command, string[] args)
        {
            if (args.Length == 0)
            {
                return;
            }
            if (args[0] == "get")
            {
                if (args[1] == null)
                {
                    client.SendToClient(PluginUtils.CreateNotification(client.ObjectId, "No URL Specified"));
                    //TextPacket invalid = (TextPacket)Packet.Create(PacketType.TEXT);
                    //invalid.Name = "CaptionSpeak";
                    //invalid.Text = "No URL Specified";
                    //client.SendToClient(invalid); //using chat instead of notifications
                    return;
                }
                else
                {
                    int num = 1;
                    string[] files = Directory.GetFiles(userPath);
                    for (int i = 0; i < files.Length; i++) //puts files in a numerical order
                    {
                        if (files[i][0] == Convert.ToChar(num))
                        {
                            num++;
                        }
                        else
                        {
                            break;
                        }
                    }
                    var youtubeClient = new YoutubeClient(); //code pretty much copied from the GitHub page
                    var videoInfo = await youtubeClient.GetVideoInfoAsync(args[1]);
                    var captionTrackInfo = videoInfo.ClosedCaptionTracks.FirstOrDefault(c => c.Language.Code == "en" && c.IsAutoGenerated);
                    if (captionTrackInfo != null)
                    {
                        string fileName = Path.Combine(userPath, num.ToString() + videoInfo.Title);
                        await youtubeClient.DownloadClosedCaptionTrackAsync(captionTrackInfo, fileName);
                        //captionParse(fileName);
                    }
                    else
                    {
                        Console.WriteLine("Captions not found for specified video");
                    }
                }
            }
        }
    }
}
Figured I'd bump this with the error shown. Does anyone know if there is anyway to get around this. I am unable to call an asynchronous method within KRelay. Is my only option to use a different method/library that does the process synchronously.
Thanks

Code:
See the end of this message for details on invoking 
just-in-time (JIT) debugging instead of this dialog box.

************** Exception Text **************
System.Reflection.ReflectionTypeLoadException: Unable to load one or more of the requested types. Retrieve the LoaderExceptions property for more information.
   at System.Reflection.RuntimeModule.GetTypes(RuntimeModule module)
   at System.Reflection.RuntimeModule.GetTypes()
   at System.Reflection.Assembly.GetTypes()
   at K_Relay.FrmMainMetro.InitPlugins()
   at K_Relay.FrmMainMetro.<FrmMainMetro_Load>d__2.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.AsyncMethodBuilderCore.<>c.<ThrowAsync>b__6_0(Object state)


************** Loaded Assemblies **************
mscorlib
    Assembly Version: 4.0.0.0
    Win32 Version: 4.7.2102.0 built by: NET47REL1LAST
    CodeBase: file:///C:/Windows/Microsoft.NET/Framework/v4.0.30319/mscorlib.dll
----------------------------------------
K_Relay
    Assembly Version: 1.0.0.0
    Win32 Version: 1.0.0.0
    CodeBase: file:///C:/Users/kmcgr/Documents/RotMG/K-Relay/K_Relay.exe
----------------------------------------
MetroFramework
    Assembly Version: 1.3.0.0
    Win32 Version: 1.0.0.0
    CodeBase: file:///C:/Users/kmcgr/Documents/RotMG/K-Relay/K_Relay.exe
----------------------------------------
MetroFramework.Design
    Assembly Version: 1.3.0.0
    Win32 Version: 1.0.0.0
    CodeBase: file:///C:/Users/kmcgr/Documents/RotMG/K-Relay/K_Relay.exe
----------------------------------------
MetroFramework.Fonts
    Assembly Version: 1.3.0.0
    Win32 Version: 1.0.0.0
    CodeBase: file:///C:/Users/kmcgr/Documents/RotMG/K-Relay/K_Relay.exe
----------------------------------------
System.Windows.Forms
    Assembly Version: 4.0.0.0
    Win32 Version: 4.7.2104.0 built by: NET47REL1LAST
    CodeBase: file:///C:/WINDOWS/Microsoft.Net/assembly/GAC_MSIL/System.Windows.Forms/v4.0_4.0.0.0__b77a5c561934e089/System.Windows.Forms.dll
----------------------------------------
System
    Assembly Version: 4.0.0.0
    Win32 Version: 4.7.2103.2 built by: NET47REL1LAST
    CodeBase: file:///C:/WINDOWS/Microsoft.Net/assembly/GAC_MSIL/System/v4.0_4.0.0.0__b77a5c561934e089/System.dll
----------------------------------------
System.Drawing
    Assembly Version: 4.0.0.0
    Win32 Version: 4.7.2046.0 built by: NET47REL1
    CodeBase: file:///C:/WINDOWS/Microsoft.Net/assembly/GAC_MSIL/System.Drawing/v4.0_4.0.0.0__b03f5f7f11d50a3a/System.Drawing.dll
----------------------------------------
Lib K Relay
    Assembly Version: 1.0.0.0
    Win32 Version: 1.0.0.0
    CodeBase: file:///C:/Users/kmcgr/Documents/RotMG/K-Relay/Lib%20K%20Relay.DLL
----------------------------------------
System.Configuration
    Assembly Version: 4.0.0.0
    Win32 Version: 4.7.2046.0 built by: NET47REL1
    CodeBase: file:///C:/WINDOWS/Microsoft.Net/assembly/GAC_MSIL/System.Configuration/v4.0_4.0.0.0__b03f5f7f11d50a3a/System.Configuration.dll
----------------------------------------
System.Core
    Assembly Version: 4.0.0.0
    Win32 Version: 4.7.2102.0 built by: NET47REL1LAST
    CodeBase: file:///C:/WINDOWS/Microsoft.Net/assembly/GAC_MSIL/System.Core/v4.0_4.0.0.0__b77a5c561934e089/System.Core.dll
----------------------------------------
System.Xml
    Assembly Version: 4.0.0.0
    Win32 Version: 4.7.2102.0 built by: NET47REL1LAST
    CodeBase: file:///C:/WINDOWS/Microsoft.Net/assembly/GAC_MSIL/System.Xml/v4.0_4.0.0.0__b77a5c561934e089/System.Xml.dll
----------------------------------------
System.Data
    Assembly Version: 4.0.0.0
    Win32 Version: 4.7.2102.0 built by: NET47REL1LAST
    CodeBase: file:///C:/WINDOWS/Microsoft.Net/assembly/GAC_32/System.Data/v4.0_4.0.0.0__b77a5c561934e089/System.Data.dll
----------------------------------------
System.Numerics
    Assembly Version: 4.0.0.0
    Win32 Version: 4.7.2046.0 built by: NET47REL1
    CodeBase: file:///C:/WINDOWS/Microsoft.Net/assembly/GAC_MSIL/System.Numerics/v4.0_4.0.0.0__b77a5c561934e089/System.Numerics.dll
----------------------------------------
System.Xml.Linq
    Assembly Version: 4.0.0.0
    Win32 Version: 4.7.2046.0 built by: NET47REL1
    CodeBase: file:///C:/WINDOWS/Microsoft.Net/assembly/GAC_MSIL/System.Xml.Linq/v4.0_4.0.0.0__b77a5c561934e089/System.Xml.Linq.dll
----------------------------------------
AutoAbility
    Assembly Version: 1.0.0.0
    Win32 Version: 1.0.0.0
    CodeBase: file:///C:/Users/kmcgr/Documents/RotMG/K-Relay/Plugins/AutoAbility.dll
----------------------------------------
AutoNexus
    Assembly Version: 1.0.0.0
    Win32 Version: 1.0.0.0
    CodeBase: file:///C:/Users/kmcgr/Documents/RotMG/K-Relay/Plugins/AutoNexus.dll
----------------------------------------
MapCacher
    Assembly Version: 1.0.0.0
    Win32 Version: 1.0.0.0
    CodeBase: file:///C:/Users/kmcgr/Documents/RotMG/K-Relay/Plugins/MapCacher.DLL
----------------------------------------
BouncyCastle.Crypto
    Assembly Version: 1.8.1.0
    Win32 Version: 1.8.15362.1
    CodeBase: file:///C:/Users/kmcgr/Documents/RotMG/K-Relay/Plugins/BouncyCastle.Crypto.dll
----------------------------------------
CaptionSpeak
    Assembly Version: 1.0.0.0
    Win32 Version: 1.0.0.0
    CodeBase: file:///C:/Users/kmcgr/Documents/RotMG/K-Relay/Plugins/CaptionSpeak.dll
----------------------------------------

************** JIT Debugging **************
To enable just-in-time (JIT) debugging, the .config file for this
application or computer (machine.config) must have the
jitDebugging value set in the system.windows.forms section.
The application must also be compiled with debugging
enabled.

For example:

<configuration>
    <system.windows.forms jitDebugging="true" />
</configuration>

When JIT debugging is enabled, any unhandled exception
will be sent to the JIT debugger registered on the computer
rather than be handled by this dialog box.
Have you tried something along the lines of

Code:
private void startCaptionDownload(Client client, string command, string[] args)
{
       captionDownload(client, command, args);
}
and then

Code:
proxy.HookCommand("capspeak", startCaptionDownload);
I think that it waits until the hook's callback method returns before moving on, so even if you were to use an async method, it's going to wait until the end. If you do what I did above it should start the captionDownload, then return immediately.
Tried that already and it brought up the same error. Not sure why, as I'm not too sure as to how async methods work with KRelay and such, but I think that the error has nothing to do with running the actual code. Instead KRelay looks through it, sees there is an async method and says "shit". Not even the initialize method gets run. Currently looking for another library or something to download youtube captions that is not asynchronous so if anyone knows anything about that it would be helpful.
Thanks

- - - Updated - - -

Figure I'm going to go back to using the python script as the method for downloading the captions unless someone can show me a better way, this means people will have to have python in order for the plugin to work. Oh well.
Posts 1–4 of 4 · Page 1 of 1
This thread is closed for replies.

Similar Threads

Talk with us