|
|
@ -30,73 +30,70 @@ struct Invidious::User
|
|
|
|
return subscriptions
|
|
|
|
return subscriptions
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
# Parse a youtube CSV playlist file and create the playlist
|
|
|
|
# Gavin Johnson (thtmnisamnstr), 20230127: Parse a youtube CSV playlist file and create the playlist
|
|
|
|
#NEW - Done
|
|
|
|
|
|
|
|
def parse_playlist_export_csv(user : User, csv_content : String)
|
|
|
|
def parse_playlist_export_csv(user : User, csv_content : String)
|
|
|
|
rows = CSV.new(csv_content, headers: false)
|
|
|
|
rows = CSV.new(csv_content, headers: true)
|
|
|
|
if rows.size >= 2
|
|
|
|
row_counter = 0
|
|
|
|
title = rows[1][4]?.try &.as_s?.try
|
|
|
|
playlist = uninitialized InvidiousPlaylist
|
|
|
|
descripton = rows[1][5]?.try &.as_s?.try
|
|
|
|
title = uninitialized String
|
|
|
|
visibility = rows[1][6]?.try &.as_s?.try
|
|
|
|
description = uninitialized String
|
|
|
|
|
|
|
|
visibility = uninitialized String
|
|
|
|
if visibility.compare("Public", case_insensitive: true) == 0
|
|
|
|
rows.each do |row|
|
|
|
|
privacy = PlaylistPrivacy:Public
|
|
|
|
if row_counter == 0
|
|
|
|
else
|
|
|
|
title = row[4]
|
|
|
|
privacy = PlaylistPrivacy:Private
|
|
|
|
description = row[5]
|
|
|
|
end
|
|
|
|
visibility = row[6]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if visibility.compare("Public", case_insensitive: true) == 0
|
|
|
|
|
|
|
|
privacy = PlaylistPrivacy::Public
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
privacy = PlaylistPrivacy::Private
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if title && privacy && user
|
|
|
|
|
|
|
|
playlist = create_playlist(title, privacy, user)
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if playlist && description
|
|
|
|
|
|
|
|
Invidious::Database::Playlists.update_description(playlist.id, description)
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
if title && privacy && user
|
|
|
|
row_counter += 1
|
|
|
|
playlist = create_playlist(title, privacy, user)
|
|
|
|
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
if row_counter > 0 && row_counter < 3
|
|
|
|
if playlist && descripton
|
|
|
|
row_counter += 1
|
|
|
|
Invidious::Database::Playlists.update_description(playlist.id, description)
|
|
|
|
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
if row_counter >= 3
|
|
|
|
|
|
|
|
if playlist
|
|
|
|
|
|
|
|
video_id = row[0]
|
|
|
|
|
|
|
|
row_counter += 1
|
|
|
|
|
|
|
|
next if !video_id
|
|
|
|
|
|
|
|
|
|
|
|
return playlist
|
|
|
|
begin
|
|
|
|
end
|
|
|
|
video = get_video(video_id)
|
|
|
|
|
|
|
|
rescue ex
|
|
|
|
|
|
|
|
next
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
# Parse a youtube CSV playlist file and add videos from it to a playlist
|
|
|
|
playlist_video = PlaylistVideo.new({
|
|
|
|
#NEW - done
|
|
|
|
title: video.title,
|
|
|
|
def parse_playlist_videos_export_csv(playlist : Playlist, csv_content : String)
|
|
|
|
id: video.id,
|
|
|
|
rows = CSV.new(csv_content, headers: false)
|
|
|
|
author: video.author,
|
|
|
|
if rows.size >= 5
|
|
|
|
ucid: video.ucid,
|
|
|
|
offset = env.params.query["index"]?.try &.to_i? || 0
|
|
|
|
length_seconds: video.length_seconds,
|
|
|
|
row_counter = 0
|
|
|
|
published: video.published,
|
|
|
|
rows.each do |row|
|
|
|
|
plid: playlist.id,
|
|
|
|
if row_counter >= 4
|
|
|
|
live_now: video.live_now,
|
|
|
|
video_id = row[0]?.try &.as_s?.try
|
|
|
|
index: Random::Secure.rand(0_i64..Int64::MAX),
|
|
|
|
end
|
|
|
|
})
|
|
|
|
row_counter += 1
|
|
|
|
|
|
|
|
next if !video_id
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
begin
|
|
|
|
Invidious::Database::PlaylistVideos.insert(playlist_video)
|
|
|
|
video = get_video(video_id)
|
|
|
|
Invidious::Database::Playlists.update_video_added(playlist.id, playlist_video.index)
|
|
|
|
rescue ex
|
|
|
|
|
|
|
|
next
|
|
|
|
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
playlist_video = PlaylistVideo.new({
|
|
|
|
|
|
|
|
title: video.title,
|
|
|
|
|
|
|
|
id: video.id,
|
|
|
|
|
|
|
|
author: video.author,
|
|
|
|
|
|
|
|
ucid: video.ucid,
|
|
|
|
|
|
|
|
length_seconds: video.length_seconds,
|
|
|
|
|
|
|
|
published: video.published,
|
|
|
|
|
|
|
|
plid: playlist.id,
|
|
|
|
|
|
|
|
live_now: video.live_now,
|
|
|
|
|
|
|
|
index: Random::Secure.rand(0_i64..Int64::MAX),
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Invidious::Database::PlaylistVideos.insert(playlist_video)
|
|
|
|
|
|
|
|
Invidious::Database::Playlists.update_video_added(playlist.id, playlist_video.index)
|
|
|
|
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
videos = get_playlist_videos(playlist, offset: offset)
|
|
|
|
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
return videos
|
|
|
|
return playlist
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
# -------------------
|
|
|
|
# -------------------
|
|
|
@ -218,20 +215,20 @@ struct Invidious::User
|
|
|
|
return true
|
|
|
|
return true
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
# Import playlist from Youtube
|
|
|
|
# Gavin Johnson (thtmnisamnstr), 20230127: Import playlist from Youtube export. Returns success status.
|
|
|
|
# Returns success status
|
|
|
|
|
|
|
|
#NEW
|
|
|
|
|
|
|
|
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
|
|
|
|
extension = filename.split(".").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, body)
|
|
|
|
playlist = parse_playlist_videos_export_csv(playlist, body)
|
|
|
|
if playlist
|
|
|
|
|
|
|
|
return true
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
return false
|
|
|
|
|
|
|
|
end
|
|
|
|
else
|
|
|
|
else
|
|
|
|
return false
|
|
|
|
return false
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
return true
|
|
|
|
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
# -------------------
|
|
|
|
# -------------------
|
|
|
|