Last active
December 12, 2023 02:27
-
-
Save tanys123/40465bd4877922f51baa3297b09ed193 to your computer and use it in GitHub Desktop.
Extract Google Ads Transparency Center Direct Link for Media
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def extract_media(url) | |
response = HTTP::Utils.get url | |
content = response[:html] | |
if (matching_image = content.match(/previewservice.insertPreviewImageContent\('fletch.+', 'fletch.+', '(.+?)'/)&.[](1)) | |
return matching_image | |
elsif (matching_html = content.match(/previewservice.insertPreviewHtmlContent\('fletch.+', 'fletch.+', '(.+?)'/)&.[](1)) | |
html = JSUtils.unescape_js matching_html | |
if html.include? "lima-exp-data" | |
video_id = html.match(/yt_video_id': '(.+?)'/)&.[](1) | |
return "https://youtube.com/watch?v=#{video_id}" | |
elsif html.include? "youtube" | |
data = html.match(/<script>var adData = ({.+?});/)&.[](1) | |
video_id = data.match(/video_id': '(.+?)'/)&.[](1) | |
return "https://youtube.com/watch?v=#{video_id}" | |
end | |
end | |
end | |
puts extract_media("https://displayads-formats.googleusercontent.com/ads/preview/content.js?client=ads-integrity-transparency&creativeId=668596296645&obfuscatedCustomerId=1697351971&uiFeatures=12,54&adGroupId=153159500858&allowedVariations=44&overlay=%3DH4sIAAAAAAAAAPNS4OJPrShJLcpLzAnLTEnN90wR4uXijg8IDvTKyU8yzTMAAAE4ZsYiAAAA&sig=ACiVB_y9LtnoHa6zGz0G9nyHqg-UVfXA5w&htmlParentId=fletch-render-14409692349477595883&responseCallback=fletchCallback14409692349477595883") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment