YouTube subscriptions cannot be imported (seem to be exported as .csv now)
- [x] I am using the latest version - 0.21.7
- [x] I checked, but didn't find any duplicates (open OR closed) of this issue in the repo.
- [x] This issue contains only one bug. I will open one issue for every bug report I want to file.
I wanted to import my YouTube subscriptions and followed the instructions. The thing is that the file that YouTube creates in the .zip is a .csv file. That cannot be imported to NewPipe. I've also tried changing the file type to .json, but that does not work either.
Device info
- Android version/Custom ROM version: 10
- Device model: Redmi Note 5 Pro
Also running into this. I believe https://github.com/TeamNewPipe/NewPipeExtractor/blob/dev/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/extractors/YoutubeSubscriptionExtractor.java is the file to modify to support csv exports.
Here is a python script that converts from the csv format to the old json format:
import pandas as pd
df = pd.read_csv('subscriptions.csv')
subs_list = [
dict(snippet=dict(
resourceId=dict(
channelId=r["Channel Id"]
),
title=r["Channel Title"]
))
for _, r in df.iterrows()
]
import json
with open('subscriptions.json', 'w') as f:
json.dump(subs_list, f)
There have been several reports of this on IRC, so I think this should be given some priority.
I can't seem to run that python script, i installed pandas but i get this:
Traceback (most recent call last):
File "/usr/lib/python3.9/site-packages/pandas/core/indexes/base.py", line 3361, in get_loc
return self._engine.get_loc(casted_key)
File "pandas/_libs/index.pyx", line 76, in pandas._libs.index.IndexEngine.get_loc
File "pandas/_libs/index.pyx", line 108, in pandas._libs.index.IndexEngine.get_loc
File "pandas/_libs/hashtable_class_helper.pxi", line 5198, in pandas._libs.hashtable.PyObjectHashTable.get_item
File "pandas/_libs/hashtable_class_helper.pxi", line 5206, in pandas._libs.hashtable.PyObjectHashTable.get_item
KeyError: 'Channel Id'
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "/home/communist/Downloads/Telegram Desktop/Takeout/YouTube and YouTube Music/subscriptions/pythonscript.py", line 4, in <module>
subs_list = [
File "/home/communist/Downloads/Telegram Desktop/Takeout/YouTube and YouTube Music/subscriptions/pythonscript.py", line 7, in <listcomp>
channelId=r["Channel Id"]
File "/usr/lib/python3.9/site-packages/pandas/core/series.py", line 942, in __getitem__
return self._get_value(key)
File "/usr/lib/python3.9/site-packages/pandas/core/series.py", line 1051, in _get_value
loc = self.index.get_loc(label)
File "/usr/lib/python3.9/site-packages/pandas/core/indexes/base.py", line 3363, in get_loc
raise KeyError(key) from err
KeyError: 'Channel Id'
That is a weird error. Could you post the first few lines of your subscriptions.csv file? I wonder if it has a different format than mine...
Channel ID,Channel URL,Channel title
UC-9mlH6az1Q_XUP3fw1N4Fg,http://www.youtube.com/channel/UC-9mlH6az1Q_XUP3fw1N4Fg,Steven Wilson
UC-tLyAaPbRZiYrOJxAGB7dQ,http://www.youtube.com/channel/UC-tLyAaPbRZiYrOJxAGB7dQ,Pursuit of Wonder
@Schmuppes why did you close this?
@Schmuppes why did you close this?
It was an accident, I was gonna delete a half-typed reply. Can you open it again?
Edit: Thanks, I'm sorry.
@Kommynct That is bizarre. Your column labels are slightly different from mine:
Channel Id,Channel Url,Channel Title
UC-3SbfTPJsL8fJAPKiVqBLg,http://www.youtube.com/channel/UC-3SbfTPJsL8fJAPKiVqBLg,Deep Look
Here's a fixed version of the script (it normalizes the column names to be all lowercase first):
import pandas as pd
df = pd.read_csv('subscriptions.csv')
df.columns= df.columns.str.lower()
subs_list = [
dict(snippet=dict(
resourceId=dict(
channelId=r["channel id"]
),
title=r["channel title"]
))
for _, r in df.iterrows()
]
import json
with open('subscriptions.json', 'w') as f:
json.dump(subs_list, f)
@Kommynct That is bizarre. Your column labels are slightly different from mine:
Channel Id,Channel Url,Channel Title UC-3SbfTPJsL8fJAPKiVqBLg,http://www.youtube.com/channel/UC-3SbfTPJsL8fJAPKiVqBLg,Deep Look
Which makes me wonder if that makes a difference. My German file has the translated labels of course, but the actual information below it is the same.
I made both scripts, and I get this error when I try running them. Any ideas?
Traceback (most recent call last): File "/home/chapmanfamily/Desktop/takeout-20210726T005738Z-001/Takeout/YouTube and YouTube Music/subscriptions/newpipe1.py", line 16, in
with open('subscriptions.json', 'w') as f: PermissionError: [Errno 13] Permission denied: 'subscriptions.json
i got the same problem yesterday and i also tried the online csv to json but didn't work... the last import was in May version: 0.21.4 Device: Redmi K30 Ultra OS: MIUI 12.5.4 (Android 11)
I made both scripts, and I get this error when I try running them. Any ideas?
Traceback (most recent call last): File "/home/chapmanfamily/Desktop/takeout-20210726T005738Z-001/Takeout/YouTube and YouTube Music/subscriptions/newpipe1.py", line 16, in with open('subscriptions.json', 'w') as f: PermissionError: [Errno 13] Permission denied: 'subscriptions.json
Nm! I changed users and it worked.
beware, the names of the columns change according to the languages from now on, it is better not to do so
The PermissionError y'all are getting I believe is because the files given to you from the Google Takeout are set to be read-only. You may have to have set read-write permissions for those files. When I tried importing just the CSV file alone into NewPipe, I got an traceback error from Java said Media is read-only or something like that.
I just tried the above script from @ed1d1a8d and I had no troubles since I made sure to give read-write permissions to the subscriptions.csv file. Should work for others as well, so long as you do that.
However, in that script, what is this snippet field?
@alecStewart1 Not sure, but going through the existing NewPipe code, it seems it is a required part of the json structure.
Hey.
I'd also face the issue. I'm new to Github and also not really aware of how the scripts and all that works.
I just wanted to leave my voice here to, the issue is present and I tried to roll back to an older version of the .apk, but then I found out it's about .csv has to be .jason
Is someone able to explain for a beginner windows user how those script work and if it works?
Excuse me if this is a dumb question.
@TobiGr or the other main devs: From what I can see, NewPipe now needs to import using the CSV files instead of JSON files (unless its the older format). Is this bug up for grabs?
Hey.
I'd also face the issue. I'm new to Github and also not really aware of how the scripts and all that works.
I just wanted to leave my voice here to, the issue is present and I tried to roll back to an older version of the .apk, but then I found out it's about .csv has to be .jason
Is someone able to explain for a beginner windows user how those script work and if it works?
Excuse me if this is a dumb question.
The script ed1d1a8d shared worked for me. I was able to import all my subscriptions just yesterday!
For this specific snippet, you'll need to have two things installed on your Windows system:
- A Python interpreter, as this script is written in the Python programming language. It doesn't come pre-installed on Windows.
- The Pandas library for Python, which this script uses to comfortably read the subscriptions from the CSV file and transform them to be written in JSON.
There are a few ways you can go about this, but I'll try to explain what I think is the simplest method.
To install Python on Windows 10, you can type python in the Start menu, and it will open the Microsoft Store page where you can install it easily (alternatively, run the installer from https://www.python.org/).
This won't come with the Pandas library, however! (unless you installed Anaconda Python, which happens to be the recommended method in Pandas' website)
For that, open a Command Prompt window (⊞ Win+R cmd) and type
pip install pandas
Hopefully, that will install Pandas without any hiccups.
Now, to use ed1d1a8d's script, copy it and save it to a file with a .py extension next to your subscriptions.csv file.
Double click your new Python script file, and a subscriptions.json should appear! If it doesn't, something went wrong, probably Pandas will be to blame.
Then try to import that in NewPipe.
Good luck!
Hey.
I'd also face the issue. I'm new to Github and also not really aware of how the scripts and all that works.
I just wanted to leave my voice here to, the issue is present and I tried to roll back to an older version of the .apk, but then I found out it's about .csv has to be .jason
Is someone able to explain for a beginner windows user how those script work and if it works?
Excuse me if this is a dumb question.
The script ed1d1a8d shared worked for me. I was able to import all my subscriptions just yesterday!
For this specific snippet, you'll need to have two things installed on your Windows system:
- A Python interpreter, as this script is written in the Python programming language. It doesn't come pre-installed on Windows.
- The Pandas library for Python, which this script uses to comfortably read the subscriptions from the CSV file and transform them to be written in JSON.
There are a few ways you can go about this, but I'll try to explain what I think is the simplest method.
To install Python on Windows 10, you can type
pythonin the Start menu, and it will open the Microsoft Store page where you can install it easily (alternatively, run the installer from https://www.python.org/).This won't come with the Pandas library, however! (unless you installed Anaconda Python, which happens to be the recommended method in Pandas' website) For that, open a Command Prompt window (⊞ Win+R
cmd) and typepip install pandasHopefully, that will install Pandas without any hiccups.
Now, to use ed1d1a8d's script, copy it and save it to a file with a
.pyextension next to yoursubscriptions.csvfile. Double click your new Python script file, and asubscriptions.jsonshould appear! If it doesn't, something went wrong, probably Pandas will be to blame.Then try to import that in NewPipe.
Good luck!
Thank you so much and the reply was really helpful. I'll try it by tomorrow!
Cheers