Solved : Base64 decode Google News URL's with a function node

Describe the problem/error/question

So I have this RSS feed and I want to use it as the source of a workflow that would post to Mastodon, but I want to avoid posting the google news encoded URL, because it pushes the user to a google news page with a redirect and finally at the destination URL, I want to decode the portion of the URL that is encoded in base64 and then retrieve the redirect real target URL, assemble the whole thing with a Set and post the original Title + decoded URL.

What is the error message (if any)?

edit : it’s working !!

Please share your workflow

Share the output returned by the last node

Edit : this workflow is now working perfectly for my use case, without leaving duplicates URL’s or AMP version of the same URL that google provides with its base64 redirect. What a mess, took me like 3H !!!

Information on your n8n setup

  • n8n version: n8n 1.1.1
  • Database (default: SQLite): PostgreSQL
  • **n8n EXECUTIONS_PROCESS setting (default: own, main):**main
  • Running n8n via : Docker
  • Operating system: Ubuntu 22
1 Like

I’m really glad to hear you got this working, @benb ! Can you go into a little bit more detail about how you solved this so if others search, they’ll know what to do? :slight_smile:

I’m not a developer, I dabble with Python and had a working python function to do just that but I wanted to incorporate this in my existing workflow and work with google news RSS + N8N

So I went and after 3h of work, iteration after iteration I finally covered all the use cases to get this done.

Pain points :

  • Google News redirect is redirecting 2 URL’s on it’s redirect, one normal and one AMP version
    I had to change the function over and over to cover different use cases, invalid characters separating the URL’s or different use case of domain using AMP differently : amp.subdomain or /amp/
  • getting the base64 decoded was actually the easiest part, the problem was splitting two urls inside the same key or tweaking the regex sanitation to not be too strong and remove valid characters in the first URL

If you look at the updated workflow and the provided inoreader RSS feed, you can see how there are constantly different sources publishing about Ukraine and each had their own idiosyncrasies to cover.

Chat-GPT is interesting but because I don’t know enough about javascript, there are probably many things I lost time with that a more advanced developer would have understood sooner, also sometimes the tool really hallucinate and gets out of the context, start providing python solutions or typical nodejs solution, so it was ward to constrain it to the context of N8N and the Function node, but after I dunno, 40 iteration I was finally able to constrain it to do what I wanted.

I would be happy to see this demo in the template !!

1 Like

I will now use this base to :

  • fetch the rss feed from google news
  • base64 decode it & clean the Link key
  • use the webhook node to recrerate a RSS feed based on the input of the JSON feed

this will allow me to have my own pure RSS feed, without google news redirect, which I can then pipe into mastodon, bluesky or a newsletter !

1 Like

Final Workflow and explanations of the different parts.

This in short is a JSON converter to RSS, with a step to base64 decode a google news URL, sanitize it and return the final destination, merge the data from the JSON and the decoded URL and then set and create an RSS feed served by a webhook on request.

Edited the “define feed item1” node to properly unescapeHTML (or the opposite if needed)
and added some more usage info on the main note.

3 Likes

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.