<commit_before>class Youtube < Plugin

    def init(init)
        @bot = init
        if ( @bot[:mpd] != nil ) && ( @bot[:messages] != nil ) && ( @bot[:youtube] == nil )
            begin
                @youtubefolder = @bot[:mpd_musicfolder] + @bot[:youtube_downloadsubdir]
                @tempyoutubefolder = @bot[:main_tempdir] + @bot[:youtube_tempsubdir]
            rescue
                puts "Error: Youtube-Plugin doesn't found settings for mpd music directory and/or your preferred temporary download directory"
                puts "See pluginbot_conf.rb"
            end
            @songlist = Queue.new
            @keylist = Array.new
            @bot[:youtube] = self
        end
        return @bot
    end

    def name
        if ( @bot[:mpd] == nil ) || ( @bot[:youtube] == nil)
            "false"
        else    
            self.class.name
        end
    end

    def help(h)
        h += "<hr><span style='color:red;'>Plugin #{self.class.name}</span><br />"
        h += "<b>#{@bot[:controlstring]}ytlink</b> will try to get some music from link.<br />"
        h += "<b>#{@bot[:controlstring]}yts keywords</b> will search on youtube for keywords.<br />"
        h += "<b>#{@bot[:controlstring]}yta <i>number</i> </b> get song in yts list.<br />"
    end

    def handle_chat(msg, message)
        if message.start_with?("ytlink <a href=") then
            link = msg.message[msg.message.index('>') + 1 .. -1]
            link = link[0..link.index('<')-1]
            workingdownload = Thread.new {
                #local variables for this thread!
                actor = msg.actor
                @bot[:messages].text(actor, "inspecting link: " + link + "...")
                get_song link
                if ( @songlist.size > 0 ) then
                    @bot[:mpd].update(@bot[:youtube_downloadsubdir].gsub(/\//,"")) 
                    @bot[:messages].text(actor, "Waiting for database update complete...")
                    
                    begin
                        #Caution! following command needs patched ruby-mpd!
                        @bot[:mpd].idle("update")
                        # find this lines in ruby-mpd/plugins/information.rb (actual 47-49)
                        # def idle(*masks)
                        #  send_command(:idle, *masks)
                        # end
                        # and uncomment it there, then build gem new.
                    rescue<commit_msg>ytlink help update<commit_after>class Youtube < Plugin

    def init(init)
        @bot = init
        if ( @bot[:mpd] != nil ) && ( @bot[:messages] != nil ) && ( @bot[:youtube] == nil )
            begin
                @youtubefolder = @bot[:mpd_musicfolder] + @bot[:youtube_downloadsubdir]
                @tempyoutubefolder = @bot[:main_tempdir] + @bot[:youtube_tempsubdir]
            rescue
                puts "Error: Youtube-Plugin doesn't found settings for mpd music directory and/or your preferred temporary download directory"
                puts "See pluginbot_conf.rb"
            end
            @songlist = Queue.new
            @keylist = Array.new
            @bot[:youtube] = self
        end
        return @bot
    end

    def name
        if ( @bot[:mpd] == nil ) || ( @bot[:youtube] == nil)
            "false"
        else    
            self.class.name
        end
    end

    def help(h)
        h += "<hr><span style='color:red;'>Plugin #{self.class.name}</span><br />"
        h += "<b>#{@bot[:controlstring]}ytlink <i>url</i></b> will try to get some music from link.<br />"
        h += "<b>#{@bot[:controlstring]}yts keywords</b> will search on youtube for keywords.<br />"
        h += "<b>#{@bot[:controlstring]}yta <i>number</i> </b> get song in yts list.<br />"
    end

    def handle_chat(msg, message)
        if message.start_with?("ytlink <a href=") then
            link = msg.message[msg.message.index('>') + 1 .. -1]
            link = link[0..link.index('<')-1]
            workingdownload = Thread.new {
                #local variables for this thread!
                actor = msg.actor
                @bot[:messages].text(actor, "inspecting link: " + link + "...")
                get_song link
                if ( @songlist.size > 0 ) then
                    @bot[:mpd].update(@bot[:youtube_downloadsubdir].gsub(/\//,"")) 
                    @bot[:messages].text(actor, "Waiting for database update complete...")
                    
                    begin
                        #Caution! following command needs patched ruby-mpd!
                        @bot[:mpd].idle("update")
                        # find this lines in ruby-mpd/plugins/information.rb (actual 47-49)
                        # def idle(*masks)
                        #  send_command(:idle, *masks)
                        # end
                        # and uncomment it there, then build gem new.
                    rescue
{'fraction_non_alphanumeric': 0.13525091799265607, 'fraction_numerical': 0.0036719706242350062, 'mean_word_length': 1.557642149191445, 'pattern_counts': {'":': 0, '<': 41, '<?xml version=': 0, '>': 39, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 8, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1311165', 'n_tokens_mistral': 1432, 'n_tokens_neox': 1361, 'n_words': 338}