Skip to content

Instantly share code, notes, and snippets.

@rubenhorn
Created February 2, 2023 12:49
Show Gist options
  • Save rubenhorn/81b318656f9166956abddd6e6927ac01 to your computer and use it in GitHub Desktop.
Save rubenhorn/81b318656f9166956abddd6e6927ac01 to your computer and use it in GitHub Desktop.
Convert indivious export to NewPipe export
#! /usr/bin/python3
import json
import sys
import requests
import html
indivious_subs = json.load(sys.stdin).get("subscriptions", [])
def get_channel_name(url):
print(f"Getting channel name for {url}...",
file=sys.stderr,
flush=True,
end="")
raw_html = requests.get(url,
headers={
"User-Agent": "curl/7.68.0",
"Accept": "*/*"
}).text
html_title = raw_html.split("<title>")[1].split("</title>")[0]
title = html.unescape(html_title)
channel_name = title.replace(" - YouTube", "")
print(f" {channel_name}", file=sys.stderr, flush=True)
return channel_name
def channel_id_to_newpipe_subscription(channel_id):
url = f"https://www.youtube.com/channel/{channel_id}"
return {
"service_id": 0,
"url": url,
"name": get_channel_name(url),
}
newpipe_subs = {
"app_version":
"0.24.1",
"app_version_int":
991,
"subscriptions": [
channel_id_to_newpipe_subscription(channel_id)
for channel_id in indivious_subs
],
}
json.dump(newpipe_subs, sys.stdout, indent=4)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment