mirror of
https://github.com/iv-org/invidious.git
synced 2024-10-01 01:25:56 -04:00
Fix(user/importers): Fixed youtube csv playlist importer
This commit is contained in:
parent
bad92093bf
commit
16f3f0979f
@ -30,22 +30,18 @@ struct Invidious::User
|
|||||||
return subscriptions
|
return subscriptions
|
||||||
end
|
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
|
# 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.strip('\n').split("\n\n", limit: 2, remove_empty: true)
|
||||||
|
|
||||||
# Create the playlist from the head content
|
# Create the playlist from the head content
|
||||||
csv_head = CSV.new(raw_head.strip('\n'), headers: true)
|
csv_head = CSV.new(raw_head.strip('\n'), headers: true)
|
||||||
csv_head.next
|
csv_head.next
|
||||||
title = csv_head[4]
|
title = playlist_name
|
||||||
description = csv_head[5]
|
|
||||||
visibility = csv_head[6]
|
|
||||||
|
|
||||||
if visibility.compare("Public", case_insensitive: true) == 0
|
description = "This is the default description of an imported playlist. Feel Free to change it as you see fit."
|
||||||
privacy = PlaylistPrivacy::Public
|
privacy = PlaylistPrivacy::Private
|
||||||
else
|
|
||||||
privacy = PlaylistPrivacy::Private
|
|
||||||
end
|
|
||||||
|
|
||||||
playlist = create_playlist(title, privacy, user)
|
playlist = create_playlist(title, privacy, user)
|
||||||
Invidious::Database::Playlists.update_description(playlist.id, description)
|
Invidious::Database::Playlists.update_description(playlist.id, description)
|
||||||
@ -204,10 +200,12 @@ struct Invidious::User
|
|||||||
end
|
end
|
||||||
|
|
||||||
def from_youtube_pl(user : User, body : String, filename : String, type : String) : Bool
|
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"
|
if extension == "csv" || type == "text/csv"
|
||||||
playlist = parse_playlist_export_csv(user, body)
|
playlist = parse_playlist_export_csv(user, playlist_name,playlist_name, body)
|
||||||
if playlist
|
if playlist
|
||||||
return true
|
return true
|
||||||
else
|
else
|
||||||
@ -219,6 +217,7 @@ struct Invidious::User
|
|||||||
end
|
end
|
||||||
|
|
||||||
def from_youtube_wh(user : User, body : String, filename : String, type : String) : Bool
|
def from_youtube_wh(user : User, body : String, filename : String, type : String) : Bool
|
||||||
|
filename = filename.split(".")
|
||||||
extension = filename.split(".").last
|
extension = filename.split(".").last
|
||||||
|
|
||||||
if extension == "json" || type == "application/json"
|
if extension == "json" || type == "application/json"
|
||||||
|
Loading…
Reference in New Issue
Block a user