Software developer at a big library, cyclist, photographer, hiker, reader. Email: chris@improbable.org
25430 stories
·
227 followers

Video scraping: extracting JSON data from a 35 second screen capture for less than 1/10th of a cent

2 Shares

The other day I found myself needing to add up some numeric values that were scattered across twelve different emails.

I didn't particularly feel like copying and pasting all of the numbers out one at a time, so I decided to try something different: could I record a screen capture while browsing around my Gmail account and then extract the numbers from that video using Google Gemini?

This turned out to work incredibly well.

AI Studio and QuickTime

I recorded the video using QuickTime Player on my Mac: File -> New Screen Recording. I dragged a box around a portion of my screen containing my Gmail account, then clicked on each of the emails in turn, pausing for a couple of seconds on each one.

I uploaded the resulting file directly into Google's AI Studio tool and prompted the following:

Turn this into a JSON array where each item has a yyyy-mm-dd date and a floating point dollar amount for that date

... and it worked. It spat out a JSON array like this:

[
  {
    "date": "2023-01-01",
    "amount": 2...
  },
  ...
]

Screenshot of the Google AI Studio interface - I used Gemini 1.5 Flash 0002, a 35 second screen recording video (which was 10,326 tokens) and the token count says 11,018/1,000,000 - the screenshot redacts some details but you can see the start of the JSON output with date and amount keys in a list

I wanted to paste that into Numbers, so I followed up with:

turn that into copy-pastable csv

Which gave me back the same data formatted as CSV.

You should never trust these things not to make mistakes, so I re-watched the 35 second video and manually checked the numbers. It got everything right.

I had intended to use Gemini 1.5 Pro, aka Google's best model... but it turns out I forgot to select the model and I'd actually run the entire process using the much less expensive Gemini 1.5 Flash 002.

How much did it cost?

According to AI Studio I used 11,018 tokens, of which 10,326 were for the video.

Gemini 1.5 Flash charges $0.075/1 million tokens (the price dropped in August).

11018/1000000 = 0.011018
0.011018 * $0.075 = $0.00082635

So this entire exercise should have cost me just under 1/10th of a cent!

And in fact, it was free. Google AI Studio currently "remains free of charge regardless of if you set up billing across all supported regions". I believe that means they can train on your data though, which is not the case for their paid APIs.

The alternatives aren't actually that great

Let's consider the alternatives here.

  • I could have clicked through the emails and copied out the data manually one at a time. This is error prone and kind of boring. For twelve emails it would have been OK, but for a hundred it would have been a real pain.
  • Accessing my Gmail data programatically. This seems to get harder every year - it's still possible to access it via IMAP right now if you set up a dedicated app password but that's a whole lot of work for a one-off scraping task. The official API is no fun at all.
  • Some kind of browser automation (Playwright or similar) that can click through my Gmail account for me. Even with an LLM to help write the code this is still a lot more work, and it doesn't help deal with formatting differences in emails either - I'd have to solve the email parsing step separately.
  • Using some kind of much more sophisticated pre-existing AI tool that has access to my email. A separate Google product also called Gemini can do this if you grant it access, but my results with that so far haven't been particularly great. AI tools are inherently unpredictable. I'm also nervous about giving any tool full access to my email account due to the risk from things like prompt injection.

Video scraping is really powerful

The great thing about this video scraping technique is that it works with anything that you can see on your screen... and it puts you in total control of what you end up exposing to the AI model.

There's no level of website authentication or anti-scraping technology that can stop me from recording a video of my screen while I manually click around inside a web application.

The results I get depend entirely on how thoughtful I was about how I positioned my screen capture area and how I clicked around.

There is no setup cost for this at all - sign into a site, hit record, browse around a bit and then dump the video into Gemini.

And the cost is so low that I had to re-run my calculations three times to make sure I hadn't made a mistake.

I expect I'll be using this technique a whole lot more in the future. It also has applications in the data journalism world, which frequently involves the need to scrape data from sources that really don't want to be scraped.

Bonus: An LLM pricing calculator

In writing up this experiment I got fed up of having to manually calculate token prices. I actually usually outsource that to ChatGPT Code Interpreter, but I've caught it messing up the conversion from dollars to cents once or twice so I always have to double-check its work.

So I got Claude 3.5 Sonnet with Claude Artifacts to build me this pricing calculator tool (source code here):

Screenshot of LLM Pricing Calculator interface. Left panel: input fields for tokens and costs. Input Tokens: 11018, Output Tokens: empty, Cost per Million Input Tokens: $0.075, Cost per Million Output Tokens: $0.3. Total Cost calculated: $0.000826 or 0.0826 cents. Right panel: Presets for various models including Gemini, Claude, and GPT versions with their respective input/output costs per 1M tokens. Footer: Prices were correct as of 16th October 2024, they may have changed.

You can set the input/output token prices by hand, or click one of the preset buttons to pre-fill it with the prices for different existing models (as-of 16th October 2024 - I won't promise that I'll promptly update them in the future!)

The entire thing was written by Claude. Here's the full conversation transcript - we spent 19 minutes iterating on it through 10 different versions.

Rather than hunt down all of those prices myself, I took screenshots of the pricing pages for each of the model providers and dumped those directly into the Claude conversation:

Claude: Is there anything else you'd like me to adjust or explain about this updated calculator? Me: Add a onkeyup event too, I want that calculator to update as I type. Also add a section underneath the calculator called Presets which lets the user click a model to populate the cost per million fields with that model's prices - which should be shown on the page too. I've dumped in some screenshots of pricing pages you can use - ignore prompt caching prices. There are five attached screenshots of pricing pages for different models.

Tags: data-journalism, gmail, google, scraping, ai, generative-ai, llms, ai-assisted-programming, claude, gemini, vision-llms, claude-artifacts, claude-3-5-sonnet

Read the whole story
Share this story
Delete

"Mama, Pray for Me": The Women Soldiers Who Warned Israel of the Approaching Attack

1 Share
The young women soldiers stationed at the Gaza border fence could have prevented the October 7 attack - if only their superiors had listened to them. Many were murdered or kidnapped in the Palestinian attack. Their story is one of a tragically missed opportunity.

Read the whole story
Share this story
Delete

Solar Protons

6 Shares
If any of you want to meet some cool local oxygen atoms, I can introduce you!
Read the whole story
MaryEllenCG
4 days ago
reply
Greater Bostonia
Share this story
Delete

How Trump allies stoked election chaos in Detroit in 2020 — and what's planned for 2024

1 Share

IE 11 is not supported. For an optimal experience visit our site on another browser.

Read the whole story
Share this story
Delete

Harris Ratchets Up Her Attacks On Trump’s Fascism

1 Share

A lot of things happened. Here are some of the things. This is TPM’s Morning Memo. Sign up for the email version.

Seeming to ditch the long-held Democratic tendency to fight on only one front at a time, Vice President Kamala Harris is mixing in more attacks on Donald Trump’s authoritarianism to her usual campaign rhetoric aimed at middle class economic issues.

In recent days, Harris has more directly attacked Trump, calling him “weak and unstable” and “incredibly unstable and unhinged.” But she’s increasingly focused her attention on his anti-democratic rhetoric, going so far as to play clips of Trump at her own rally Monday. Today, in a speech in Pennsylvania, she will focus on the threat Trump poses to the Constitution.

“When Vice President Kamala Harris walked off the stage of her rally in Erie, Pa., which included a video compilation of Donald Trump’s recent comments about ‘the enemy from within,’ she told her campaign staff that she wanted to keep using the former president’s own words against him, advisers said,” the WSJ reports.

Harris wants to use Trump’s own words as “evidence” against him in the closing days of the campaign, according to the WSJ report.

In the plodding, “check the box” campaign strategy that Democrats often default to, candidates are given the false choice of either addressing voters’ most pressing concerns or warning that Trump is a menace and threat to democratic values. Harris’ “all of the above” approach in recent days weaves together both attack lines into a seamless whole.

Most notably, Harris has connected Trump’s essential weakness of character with his authoritarian impulses, his fondness for dictators, and his disregard for the Constitution. You get these threats with Trump precisely because he is a such a hollowed-out shell of a human. It’s a powerful reminder that fascism is a refuge for the weak and insecure, an argument that defuses the fear that Trump seeks to instill.

Chris Hayes lays it out plainly:

As Morning Memo touched on yesterday, Trump has entered a new, more sinister phase in his quest to retake the White House and fend off the criminal cases against him. These are the kinds of headlines that will be especially chilling in retrospect if Trump wins:

  • NYT: Trump Escalates Threats to Political Opponents He Deems the ‘Enemy’
  • ABC News: Trump’s ‘enemy from within’ threat spurs critics’ alarm about his authoritarian shift
  • WaPo: Trump’s erratic endgame: Dark threats, personal insults and some dancing

NBC News’ Ryan J. Reilly and Jane C. Timm have a new deeply reported piece on: “How Trump allies stoked election chaos in Detroit in 2020 — and what they’re planning in 2024”

Donald Trump falsely claimed that there was a peaceful transfer of power in 2020 and sidestepped a question about whether he would commit to a peaceful transition in 2024.

Politico: “Federal employees throughout the executive branch are panicking at the thought of another Trump administration.”

  • Kamala Harris sits today in Pennsylvania for her first Fox News interview, which will air tonight.
  • WaPo: Harris urges Black Americans not to be fooled into sitting out the race
  • NYT: With Trump Facing Threats, Security and Politics Intersect as Never Before

WaPo: “The Justice Department will monitor voting in Portage County, Ohio, during the November election, after the county sheriff last month posted on Facebook urging residents to write down the addresses of people displaying yard signs for Vice President Kamala Harris.”

  • Georgia, Part I: Fulton County Superior Court Judge Robert McBurney ruled that certification of the vote at the county level is mandatory under state law, ratifying existing Georgia law that would prevent local officials from engaging in funny business by refusing or delaying certification.
  • Georgia, Part II: Judge McBurney separately blocked the controversial new rule from the State Election Board requiring the hand-counting of total ballots cast, saying it was too close to Election Day to implement in this cycle.
  • Alabama: A federal judge appointed by Donald Trump ordered a halt to the state’s ham-handed effort to purge the voter rolls of noncitizens immediately before the election.

Sen. Ted Cruz (R) was pushed hard on abortion by Rep. Colin Allred (D) during what is expected to be their one and only Senate campaign debate in a race that is closer than anticipated and may represent Democrats last best hope of flipping a GOP seat.

But it was on Jan. 6 that Allred hit Cruz the hardest:

TPM’s Kate Riga: Inside The Mystery Of Why The Supreme Court Declined To Hear A Pressing Abortion Case

GOP gubernatorial nominee Mark Robinson filed a defamation lawsuit against CNN in state court in North Carolina over its report last month that he made explicit racial and sexual posts on a porn site message board.

Do you like Morning Memo? Let us know!

Read the whole story
Share this story
Delete

Brianna Keilar Howls At Trump-Linked 'Male Enhancement Honey'

1 Share

A CNN investigation into “Swiss-made” watches being sold by former President Donald Trump led to an unexpectedly stimulating discovery.

Being the Republican presidential nominee hasn’t stopped Trump from hawking all kinds of products, including sneakers, Bibles, cryptocurrency, silver coins, and other items. Of particular interest to CNN reporters Steve Contorno and Scott Glover were the watches Trump sells. As it turns out, the watches were not actually made in Switzerland, which has strict rules on what products can be deemed Swiss-made.

Trump’s timepieces sell for hundreds of dollars, but one sells for $100,000. The website where they can be purchased describes them as “Swiss-made.”

However, CNN’s probe of the origin of Trump’s watches led them to a company called BestWachesOnEarth LLC, which has an address in a small town in Wyoming called Sheridan.

“[A] CNN investigation into the manufacturing and distribution of the Trump-branded timepieces dead-ended at an innocuous-looking shopping center in a small city in remote northern Wyoming, not far from the border of Montana,” the report stated, adding:

There, sharing a parking lot with a hodgepodge of businesses including an H&R Block, a Wendy’s fast-food restaurant and a “vape and hemp smoke shop,” is a nondescript office space that serves as the mailing address for TheBestWatchesOnEarth LLC, the company behind the new line of Trump watches. The building houses a daycare, but there is no sign of the watches Trump says, “puts you in a very exclusive club.”

CNN said that dozens of other companies claim the address, including the aforementioned Trump sneakers. Another company linked to the address is BestHoneyOnEarth.

Contorno joined Thursday’s CNN News Central, where he shared these findings with Boris Sanchez and Brianna Keilar.

“And I should mention, Boris, about that honey company, which, I left out the best detail,” Contorno said. “They sell ‘male enhancement honey,’ which is exactly what it sounds like.”

Sanchez and Keilar burst out laughing.

“Stop it, Steve!” Keilar exclaimed.

“It is a product that helps men perform the bedroom,” Contorno continued. “And the FDA actually flagged several of the products that this company sells on its website because they were sneaking Viagra or the drug behind Viagra into the ingredients.”

“I was not prepared for that!” Keilar said, nearly crying from laughing.

“That’s a curveball,” Sanchez deadpanned.

Watch above via CNN.

Have a tip for us? tips@mediaite.com

Read the whole story
Share this story
Delete
Next Page of Stories