|
|
|
@ -30,44 +30,42 @@ struct Invidious::User
|
|
|
|
|
return subscriptions
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
# Parse a youtube CSV playlist file and create the playlist
|
|
|
|
|
#NEW - Done
|
|
|
|
|
# Gavin Johnson (thtmnisamnstr), 20230127: Parse a youtube CSV playlist file and create the playlist
|
|
|
|
|
def parse_playlist_export_csv(user : User, csv_content : String)
|
|
|
|
|
rows = CSV.new(csv_content, headers: false)
|
|
|
|
|
if rows.size >= 2
|
|
|
|
|
title = rows[1][4]?.try &.as_s?.try
|
|
|
|
|
descripton = rows[1][5]?.try &.as_s?.try
|
|
|
|
|
visibility = rows[1][6]?.try &.as_s?.try
|
|
|
|
|
rows = CSV.new(csv_content, headers: true)
|
|
|
|
|
row_counter = 0
|
|
|
|
|
playlist = uninitialized InvidiousPlaylist
|
|
|
|
|
title = uninitialized String
|
|
|
|
|
description = uninitialized String
|
|
|
|
|
visibility = uninitialized String
|
|
|
|
|
rows.each do |row|
|
|
|
|
|
if row_counter == 0
|
|
|
|
|
title = row[4]
|
|
|
|
|
description = row[5]
|
|
|
|
|
visibility = row[6]
|
|
|
|
|
|
|
|
|
|
if visibility.compare("Public", case_insensitive: true) == 0
|
|
|
|
|
privacy = PlaylistPrivacy:Public
|
|
|
|
|
privacy = PlaylistPrivacy::Public
|
|
|
|
|
else
|
|
|
|
|
privacy = PlaylistPrivacy:Private
|
|
|
|
|
privacy = PlaylistPrivacy::Private
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
if title && privacy && user
|
|
|
|
|
playlist = create_playlist(title, privacy, user)
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
if playlist && descripton
|
|
|
|
|
if playlist && description
|
|
|
|
|
Invidious::Database::Playlists.update_description(playlist.id, description)
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
return playlist
|
|
|
|
|
row_counter += 1
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
# Parse a youtube CSV playlist file and add videos from it to a playlist
|
|
|
|
|
#NEW - done
|
|
|
|
|
def parse_playlist_videos_export_csv(playlist : Playlist, csv_content : String)
|
|
|
|
|
rows = CSV.new(csv_content, headers: false)
|
|
|
|
|
if rows.size >= 5
|
|
|
|
|
offset = env.params.query["index"]?.try &.to_i? || 0
|
|
|
|
|
row_counter = 0
|
|
|
|
|
rows.each do |row|
|
|
|
|
|
if row_counter >= 4
|
|
|
|
|
video_id = row[0]?.try &.as_s?.try
|
|
|
|
|
if row_counter > 0 && row_counter < 3
|
|
|
|
|
row_counter += 1
|
|
|
|
|
end
|
|
|
|
|
if row_counter >= 3
|
|
|
|
|
if playlist
|
|
|
|
|
video_id = row[0]
|
|
|
|
|
row_counter += 1
|
|
|
|
|
next if !video_id
|
|
|
|
|
|
|
|
|
@ -92,11 +90,10 @@ struct Invidious::User
|
|
|
|
|
Invidious::Database::PlaylistVideos.insert(playlist_video)
|
|
|
|
|
Invidious::Database::Playlists.update_video_added(playlist.id, playlist_video.index)
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
videos = get_playlist_videos(playlist, offset: offset)
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
return videos
|
|
|
|
|
return playlist
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
# -------------------
|
|
|
|
@ -218,20 +215,20 @@ struct Invidious::User
|
|
|
|
|
return true
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
# Import playlist from Youtube
|
|
|
|
|
# Returns success status
|
|
|
|
|
#NEW
|
|
|
|
|
# Gavin Johnson (thtmnisamnstr), 20230127: Import playlist from Youtube export. Returns success status.
|
|
|
|
|
def from_youtube_pl(user : User, body : String, filename : String, type : String) : Bool
|
|
|
|
|
extension = filename.split(".").last
|
|
|
|
|
|
|
|
|
|
if extension == "csv" || type == "text/csv"
|
|
|
|
|
playlist = parse_playlist_export_csv(user, body)
|
|
|
|
|
playlist = parse_playlist_videos_export_csv(playlist, body)
|
|
|
|
|
if playlist
|
|
|
|
|
return true
|
|
|
|
|
else
|
|
|
|
|
return false
|
|
|
|
|
end
|
|
|
|
|
else
|
|
|
|
|
return false
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
return true
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
# -------------------
|
|
|
|
|