#include <StringConstants.au3> ; to declare the Constants of StringRegExp
#include <Array.au3> ; UDF needed for _ArrayDisplay and _ArrayConcatenate
Local $sRegex = "(?sm)function\s+\w+\s*\([^{]+({(?:[^{}]+\/\*.*?\*\/|[^{}]+\/\/.*?$|[^{}]+|(?-1))*+})"
Local $sString = " // Retrieve your client ID from the {{ Google Cloud Console }} at" & @CRLF & _
" // {{ https://cloud.google.com/console }}." & @CRLF & _
" var OAUTH2_CLIENT_ID = 'YOUR_CLIENT_ID';" & @CRLF & _
" var OAUTH2_SCOPES = [" & @CRLF & _
" 'https://www.googleapis.com/auth/yt-analytics.readonly'," & @CRLF & _
" 'https://www.googleapis.com/auth/youtube.readonly'" & @CRLF & _
" ];" & @CRLF & _
"" & @CRLF & _
" var ONE_MONTH_IN_MILLISECONDS = 1000 * 60 * 60 * 24 * 30;" & @CRLF & _
"" & @CRLF & _
" // Keep track of the currently authenticated user's YouTube channel ID." & @CRLF & _
" var channelId;" & @CRLF & _
"" & @CRLF & _
" // For information about the Google Chart Tools API, see:" & @CRLF & _
" // https://developers.google.com/chart/interactive/docs/quick_start" & @CRLF & _
" google.load('visualization', '1.0', {'packages': ['corechart']});" & @CRLF & _
"" & @CRLF & _
" // Upon loading, the Google APIs JS client automatically invokes this callback." & @CRLF & _
" // See https://developers.google.com/api-client-library/javascript/features/authentication " & @CRLF & _
" window.onJSClientLoad = function() {" & @CRLF & _
" gapi.auth.init(function() {" & @CRLF & _
" window.setTimeout(checkAuth, 1);" & @CRLF & _
" });" & @CRLF & _
" };" & @CRLF & _
"" & @CRLF & _
" // Attempt the immediate OAuth 2.0 client flow as soon as the page loads." & @CRLF & _
" // If the currently logged-in Google Account has previously authorized" & @CRLF & _
" // the client specified as the OAUTH2_CLIENT_ID, then the authorization" & @CRLF & _
" // succeeds with no user intervention. Otherwise, it fails and the" & @CRLF & _
" // user interface that prompts for authorization needs to display." & @CRLF & _
" function checkAuth() {" & @CRLF & _
" gapi.auth.authorize({" & @CRLF & _
" client_id: OAUTH2_CLIENT_ID," & @CRLF & _
" scope: OAUTH2_SCOPES," & @CRLF & _
" immediate: true" & @CRLF & _
" }, handleAuthResult);" & @CRLF & _
" }" & @CRLF & _
"" & @CRLF & _
" // Handle the result of a gapi.auth.authorize() call." & @CRLF & _
" function handleAuthResult(authResult) {" & @CRLF & _
" if (authResult) {" & @CRLF & _
" // Authorization was successful. Hide authorization prompts and show" & @CRLF & _
" // content that should be visible after authorization succeeds." & @CRLF & _
" $('.pre-auth').hide();" & @CRLF & _
" $('.post-auth').show();" & @CRLF & _
"" & @CRLF & _
" loadAPIClientInterfaces();" & @CRLF & _
" } else {" & @CRLF & _
" // Authorization was unsuccessful. Show content related to prompting for" & @CRLF & _
" // authorization and hide content that should be visible if authorization" & @CRLF & _
" // succeeds." & @CRLF & _
" $('.post-auth').hide();" & @CRLF & _
" $('.pre-auth').show();" & @CRLF & _
"" & @CRLF & _
" // Make the #login-link clickable. Attempt a non-immediate OAuth 2.0" & @CRLF & _
" // client flow. The current function is called when that flow completes." & @CRLF & _
" $('#login-link').click(function() {" & @CRLF & _
" gapi.auth.authorize({" & @CRLF & _
" client_id: OAUTH2_CLIENT_ID," & @CRLF & _
" scope: OAUTH2_SCOPES," & @CRLF & _
" immediate: false" & @CRLF & _
" }, handleAuthResult);" & @CRLF & _
" });" & @CRLF & _
" }" & @CRLF & _
" }" & @CRLF & _
"" & @CRLF & _
" // Load the client interfaces for the YouTube Analytics and Data APIs, which" & @CRLF & _
" // are required to use the Google APIs JS client. More info is available at" & @CRLF & _
" // https://developers.google.com/api-client-library/javascript/dev/dev_jscript#loading-the-client-library-and-the-api" & @CRLF & _
" function loadAPIClientInterfaces() {" & @CRLF & _
" gapi.client.load('youtube', 'v3', function() {" & @CRLF & _
" gapi.client.load('youtubeAnalytics', 'v1', function() {" & @CRLF & _
" // After both client interfaces load, use the Data API to request" & @CRLF & _
" // information about the authenticated user's channel." & @CRLF & _
" getUserChannel();" & @CRLF & _
" });" & @CRLF & _
" });" & @CRLF & _
" }" & @CRLF & _
"" & @CRLF & _
" // Call the Data API to retrieve information about the currently" & @CRLF & _
" // authenticated user's YouTube channel." & @CRLF & _
" function getUserChannel() {" & @CRLF & _
" // Also see: https://developers.google.com/youtube/v3/docs/channels/list" & @CRLF & _
" var request = gapi.client.youtube.channels.list({" & @CRLF & _
" // Setting the "mine" request parameter's value to "true" indicates that" & @CRLF & _
" // you want to retrieve the currently authenticated user's channel." & @CRLF & _
" mine: true," & @CRLF & _
" part: 'id,contentDetails'" & @CRLF & _
" });" & @CRLF & _
"" & @CRLF & _
" request.execute(function(response) {" & @CRLF & _
" if ('error' in response) {" & @CRLF & _
" displayMessage(response.error.message);" & @CRLF & _
" } else {" & @CRLF & _
" // We need the channel's channel ID to make calls to the Analytics API." & @CRLF & _
" // The channel ID value has the form "UCdLFeWKpkLhkguiMZUp8lWA"." & @CRLF & _
" channelId = response.items[0].id;" & @CRLF & _
" // Retrieve the playlist ID that uniquely identifies the playlist of" & @CRLF & _
" // videos uploaded to the authenticated user's channel. This value has" & @CRLF & _
" // the form "UUdLFeWKpkLhkguiMZUp8lWA"." & @CRLF & _
" var uploadsListId = response.items[0].contentDetails.relatedPlaylists.uploads;" & @CRLF & _
" // Use the playlist ID to retrieve the list of uploaded videos." & @CRLF & _
" getPlaylistItems(uploadsListId);" & @CRLF & _
" }" & @CRLF & _
" });" & @CRLF & _
" }" & @CRLF & _
"" & @CRLF & _
" // Call the Data API to retrieve the items in a particular playlist. In this" & @CRLF & _
" // example, we are retrieving a playlist of the currently authenticated user's" & @CRLF & _
" // uploaded videos. By default, the list returns the most recent videos first." & @CRLF & _
" function getPlaylistItems(listId) {" & @CRLF & _
" // See https://developers.google.com/youtube/v3/docs/playlistitems/list" & @CRLF & _
" var request = gapi.client.youtube.playlistItems.list({" & @CRLF & _
" playlistId: listId," & @CRLF & _
" part: 'snippet'" & @CRLF & _
" });" & @CRLF & _
"" & @CRLF & _
" request.execute(function(response) {" & @CRLF & _
" if ('error' in response) {" & @CRLF & _
" displayMessage(response.error.message);" & @CRLF & _
" } else {" & @CRLF & _
" if ('items' in response) {" & @CRLF & _
" // The jQuery.map() function iterates through all of the items in" & @CRLF & _
" // the response and creates a new array that only contains the" & @CRLF & _
" // specific property we're looking for: videoId." & @CRLF & _
" var videoIds = $.map(response.items, function(item) {" & @CRLF & _
" return item.snippet.resourceId.videoId;" & @CRLF & _
" });" & @CRLF & _
"" & @CRLF & _
" // Now that we know the IDs of all the videos in the uploads list," & @CRLF & _
" // we can retrieve information about each video." & @CRLF & _
" getVideoMetadata(videoIds);" & @CRLF & _
" } else {" & @CRLF & _
" displayMessage('There are no videos in your channel.');" & @CRLF & _
" }" & @CRLF & _
" }" & @CRLF & _
" });" & @CRLF & _
" }" & @CRLF & _
"" & @CRLF & _
" // Given an array of video IDs, this function obtains metadata about each" & @CRLF & _
" // video and then uses that metadata to display a list of videos." & @CRLF & _
" function getVideoMetadata(videoIds) {" & @CRLF & _
" // https://developers.google.com/youtube/v3/docs/videos/list" & @CRLF & _
" var request = gapi.client.youtube.videos.list({" & @CRLF & _
" // The 'id' property's value is a comma-separated string of video IDs." & @CRLF & _
" id: videoIds.join(',')," & @CRLF & _
" part: 'id,snippet,statistics'" & @CRLF & _
" });" & @CRLF & _
"" & @CRLF & _
" request.execute(function(response) {" & @CRLF & _
" if ('error' in response) {" & @CRLF & _
" displayMessage(response.error.message);" & @CRLF & _
" } else {" & @CRLF & _
" // Get the jQuery wrapper for the #video-list element before starting" & @CRLF & _
" // the loop." & @CRLF & _
" var videoList = $('#video-list');" & @CRLF & _
" $.each(response.items, function() {" & @CRLF & _
" // Exclude videos that do not have any views, since those videos" & @CRLF & _
" // will not have any interesting viewcount Analytics data." & @CRLF & _
" if (this.statistics.viewCount == 0) {" & @CRLF & _
" return;" & @CRLF & _
" }" & @CRLF & _
"" & @CRLF & _
" var title = this.snippet.title;" & @CRLF & _
" var videoId = this.id;" & @CRLF & _
"" & @CRLF & _
" // Create a new <li> element that contains an <a> element." & @CRLF & _
" // Set the <a> element's text content to the video's title, and" & @CRLF & _
" // add a click handler that will display Analytics data when invoked." & @CRLF & _
" var liElement = $('<li>');" & @CRLF & _
" var aElement = $('<a>');" & @CRLF & _
" // Setting the href value to '#' ensures that the browser renders the" & @CRLF & _
" // <a> element as a clickable link." & @CRLF & _
" aElement.attr('href', '#');" & @CRLF & _
" aElement.text(title);" & @CRLF & _
" aElement.click(function() {" & @CRLF & _
" displayVideoAnalytics(videoId);" & @CRLF & _
" });" & @CRLF & _
"" & @CRLF & _
" // Call the jQuery.append() method to add the new <a> element to" & @CRLF & _
" // the <li> element, and the <li> element to the parent" & @CRLF & _
" // list, which is identified by the 'videoList' variable." & @CRLF & _
" liElement.append(aElement);" & @CRLF & _
" videoList.append(liElement);" & @CRLF & _
" });" & @CRLF & _
"" & @CRLF & _
" if (videoList.children().length == 0) {" & @CRLF & _
" // Display a message if the channel does not have any viewed videos." & @CRLF & _
" displayMessage('Your channel does not have any videos that have been viewed.');" & @CRLF & _
" }" & @CRLF & _
" }" & @CRLF & _
" });" & @CRLF & _
" }" & @CRLF & _
"" & @CRLF & _
" // This function requests YouTube Analytics data for a video and displays" & @CRLF & _
" // the results in a chart." & @CRLF & _
" function displayVideoAnalytics(videoId) {" & @CRLF & _
" if (channelId) {" & @CRLF & _
" // To use a different date range, modify the ONE_MONTH_IN_MILLISECONDS" & @CRLF & _
" // variable to a different millisecond delta as desired." & @CRLF & _
" var today = new Date();" & @CRLF & _
" var lastMonth = new Date(today.getTime() - ONE_MONTH_IN_MILLISECONDS);" & @CRLF & _
"" & @CRLF & _
" var request = gapi.client.youtubeAnalytics.reports.query({" & @CRLF & _
" // The start-date and end-date parameters must be YYYY-MM-DD strings." & @CRLF & _
" 'start-date': formatDateString(lastMonth)," & @CRLF & _
" 'end-date': formatDateString(today)," & @CRLF & _
" // At this time, you need to explicitly specify channel==channelId." & @CRLF & _
" // See https://developers.google.com/youtube/analytics/v1/#ids" & @CRLF & _
" ids: 'channel==' + channelId," & @CRLF & _
" dimensions: 'day'," & @CRLF & _
" sort: 'day'," & @CRLF & _
" // See https://developers.google.com/youtube/analytics/v1/available_reports" & @CRLF & _
" // for details about the different filters and metrics you can request" & @CRLF & _
" // if the "dimensions" parameter value is "day"." & @CRLF & _
" metrics: 'views'," & @CRLF & _
" filters: 'video==' + videoId" & @CRLF & _
" });" & @CRLF & _
"" & @CRLF & _
" request.execute(function(response) {" & @CRLF & _
" // This function is called regardless of whether the request succeeds." & @CRLF & _
" // The response contains YouTube Analytics data or an error message." & @CRLF & _
" if ('error' in response) {" & @CRLF & _
" displayMessage(response.error.message);" & @CRLF & _
" } else {" & @CRLF & _
" displayChart(videoId, response);" & @CRLF & _
" }" & @CRLF & _
" });" & @CRLF & _
" } else {" & @CRLF & _
" // The currently authenticated user's channel ID is not available." & @CRLF & _
" displayMessage('The YouTube channel ID for the current user is not available.');" & @CRLF & _
" }" & @CRLF & _
" }" & @CRLF & _
"" & @CRLF & _
" // This boilerplate code takes a Date object and returns a YYYY-MM-DD string." & @CRLF & _
" function formatDateString(date) {" & @CRLF & _
" var yyyy = date.getFullYear().toString();" & @CRLF & _
" var mm = padToTwoCharacters(date.getMonth() + 1);" & @CRLF & _
" var dd = padToTwoCharacters(date.getDate());" & @CRLF & _
"" & @CRLF & _
" return yyyy + '-' + mm + '-' + dd;" & @CRLF & _
" }" & @CRLF & _
"" & @CRLF & _
" // If number is a single digit, prepend a '0'. Otherwise, return the number" & @CRLF & _
" // as a string." & @CRLF & _
" function padToTwoCharacters(number) {" & @CRLF & _
" if (number < 10) {" & @CRLF & _
" return '0' + number;" & @CRLF & _
" } else {" & @CRLF & _
" return number.toString();" & @CRLF & _
" }" & @CRLF & _
" }" & @CRLF & _
"" & @CRLF & _
" // Call the Google Chart Tools API to generate a chart of Analytics data." & @CRLF & _
" function displayChart(videoId, response) {" & @CRLF & _
" if ('rows' in response) {" & @CRLF & _
" hideMessage();" & @CRLF & _
"" & @CRLF & _
" // The columnHeaders property contains an array of objects representing" & @CRLF & _
" // each column's title -- e.g.: [{name:"day"},{name:"views"}]" & @CRLF & _
" // We need these column titles as a simple array, so we call jQuery.map()" & @CRLF & _
" // to get each element's "name" property and create a new array that only" & @CRLF & _
" // contains those values." & @CRLF & _
" var columns = $.map(response.columnHeaders, function(item) {" & @CRLF & _
" return item.name;" & @CRLF & _
" });" & @CRLF & _
" // The google.visualization.arrayToDataTable() function wants an array" & @CRLF & _
" // of arrays. The first element is an array of column titles, calculated" & @CRLF & _
" // above as "columns". The remaining elements are arrays that each" & @CRLF & _
" // represent a row of data. Fortunately, response.rows is already in" & @CRLF & _
" // this format, so it can just be concatenated." & @CRLF & _
" // See https://developers.google.com/chart/interactive/docs/datatables_dataviews#arraytodatatable" & @CRLF & _
" var chartDataArray = [columns].concat(response.rows);" & @CRLF & _
" var chartDataTable = google.visualization.arrayToDataTable(chartDataArray);" & @CRLF & _
"" & @CRLF & _
" var chart = new google.visualization.LineChart(document.getElementById('chart'));" & @CRLF & _
" chart.draw(chartDataTable, {" & @CRLF & _
" // Additional options can be set if desired as described at:" & @CRLF & _
" // https://developers.google.com/chart/interactive/docs/reference#visdraw" & @CRLF & _
" title: 'Views per Day of Video ' + videoId" & @CRLF & _
" });" & @CRLF & _
" } else {" & @CRLF & _
" displayMessage('No data available for video ' + videoId);" & @CRLF & _
" }" & @CRLF & _
" }" & @CRLF & _
"" & @CRLF & _
" // This helper method displays a message on the page." & @CRLF & _
" function displayMessage(message) {" & @CRLF & _
" $('#message').text(message).show();" & @CRLF & _
" }" & @CRLF & _
"" & @CRLF & _
" // This helper method hides a previously displayed message on the page." & @CRLF & _
" function hideMessage() {" & @CRLF & _
" $('#message').hide();" & @CRLF & _
" }" & @CRLF & _
""
Local $aArray = StringRegExp($sString, $sRegex, $STR_REGEXPARRAYGLOBALFULLMATCH)
Local $aFullArray[0]
For $i = 0 To UBound($aArray) -1
_ArrayConcatenate($aFullArray, $aArray[$i])
Next
$aArray = $aFullArray
; Present the entire match result
_ArrayDisplay($aArray, "Result")
Please keep in mind that these code samples are automatically generated and are not guaranteed to work. If you find any syntax errors, feel free to submit a bug report. For a full regex reference for AutoIt, please visit: https://www.autoitscript.com/autoit3/docs/functions/StringRegExp.htm