Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix youtube CSV playlist importer #4787

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 11 additions & 13 deletions src/invidious/user/imports.cr
Original file line number Diff line number Diff line change
Expand Up @@ -30,28 +30,24 @@ struct Invidious::User
return subscriptions
end

def parse_playlist_export_csv(user : User, raw_input : String)
# Parse a CSV Google Takeout - Youtube Playlist file
def parse_playlist_export_csv(user : User, playlist_name : String, raw_input : String)
# Split the input into head and body content
raw_head, raw_body = raw_input.strip('\n').split("\n\n", limit: 2, remove_empty: true)
raw_head, raw_body = raw_input.split("\n", limit: 2, remove_empty: true)

# Create the playlist from the head content
csv_head = CSV.new(raw_head.strip('\n'), headers: true)
csv_head.next
title = csv_head[4]
description = csv_head[5]
visibility = csv_head[6]
title = playlist_name

if visibility.compare("Public", case_insensitive: true) == 0
privacy = PlaylistPrivacy::Public
else
privacy = PlaylistPrivacy::Private
end
description = "This is the default description of an imported playlist. Feel Free to change it as you see fit."
privacy = PlaylistPrivacy::Private

playlist = create_playlist(title, privacy, user)
Invidious::Database::Playlists.update_description(playlist.id, description)

# Add each video to the playlist from the body content
csv_body = CSV.new(raw_body.strip('\n'), headers: true)
csv_body = CSV.new(raw_body.strip('\n'), headers: false)
csv_body.each do |row|
video_id = row[0]
if playlist
Expand Down Expand Up @@ -204,10 +200,12 @@ struct Invidious::User
end

def from_youtube_pl(user : User, body : String, filename : String, type : String) : Bool
extension = filename.split(".").last
filename_array = filename.split(".")
playlist_name = filename_array.first
extension = filename_array.last

if extension == "csv" || type == "text/csv"
playlist = parse_playlist_export_csv(user, body)
playlist = parse_playlist_export_csv(user, playlist_name, body)
if playlist
return true
else
Expand Down