forked from midou/invidious
improved import algorithm, fixed a referer issue from the playlists page after deleting a playlist
Signed-off-by: thtmnisamnstr <gavinj1984@gmail.com>
This commit is contained in:
parent
6f01d6eacf
commit
b3eea6ab3e
@ -30,43 +30,44 @@ struct Invidious::User
|
|||||||
return subscriptions
|
return subscriptions
|
||||||
end
|
end
|
||||||
|
|
||||||
def parse_playlist_export_csv(user : User, csv_content : String)
|
def parse_playlist_export_csv(user : User, raw_input : String)
|
||||||
rows = CSV.new(csv_content, headers: true)
|
|
||||||
row_counter = 0
|
|
||||||
playlist = uninitialized InvidiousPlaylist
|
playlist = uninitialized InvidiousPlaylist
|
||||||
title = uninitialized String
|
title = uninitialized String
|
||||||
description = uninitialized String
|
description = uninitialized String
|
||||||
visibility = uninitialized String
|
visibility = uninitialized String
|
||||||
rows.each do |row|
|
privacy = uninitialized PlaylistPrivacy
|
||||||
if row_counter == 0
|
|
||||||
title = row[4]
|
|
||||||
description = row[5]
|
|
||||||
visibility = row[6]
|
|
||||||
|
|
||||||
if visibility.compare("Public", case_insensitive: true) == 0
|
# Split the input into head and body content
|
||||||
privacy = PlaylistPrivacy::Public
|
raw_head, raw_body = raw_input.split("\n\n", limit: 2, remove_empty: true)
|
||||||
else
|
|
||||||
privacy = PlaylistPrivacy::Private
|
|
||||||
end
|
|
||||||
|
|
||||||
if title && privacy && user
|
# Create the playlist from the head content
|
||||||
playlist = create_playlist(title, privacy, user)
|
csv_head = CSV.new(raw_head, headers: true)
|
||||||
end
|
csv_head.next
|
||||||
|
title = csv_head[4]
|
||||||
|
description = csv_head[5]
|
||||||
|
visibility = csv_head[6]
|
||||||
|
|
||||||
if playlist && description
|
if visibility.compare("Public", case_insensitive: true) == 0
|
||||||
Invidious::Database::Playlists.update_description(playlist.id, description)
|
privacy = PlaylistPrivacy::Public
|
||||||
end
|
else
|
||||||
|
privacy = PlaylistPrivacy::Private
|
||||||
|
end
|
||||||
|
|
||||||
row_counter += 1
|
if title && privacy && user
|
||||||
end
|
playlist = create_playlist(title, privacy, user)
|
||||||
if row_counter > 0 && row_counter < 3
|
end
|
||||||
row_counter += 1
|
|
||||||
end
|
if playlist && description
|
||||||
if row_counter >= 3
|
Invidious::Database::Playlists.update_description(playlist.id, description)
|
||||||
|
end
|
||||||
|
|
||||||
|
# Add each video to the playlist from the body content
|
||||||
|
CSV.each_row(raw_body) do |row|
|
||||||
|
if row.size >= 1
|
||||||
|
video_id = row[0]
|
||||||
if playlist
|
if playlist
|
||||||
video_id = row[0]
|
|
||||||
row_counter += 1
|
|
||||||
next if !video_id
|
next if !video_id
|
||||||
|
next if video_id == "Video Id"
|
||||||
|
|
||||||
begin
|
begin
|
||||||
video = get_video(video_id)
|
video = get_video(video_id)
|
||||||
|
@ -10,12 +10,12 @@
|
|||||||
</div>
|
</div>
|
||||||
<div class="pure-u-1-3">
|
<div class="pure-u-1-3">
|
||||||
<h3 style="text-align:center">
|
<h3 style="text-align:center">
|
||||||
<a href="/create_playlist?referer=<%= URI.encode_www_form(referer) %>"><%= translate(locale, "Create playlist") %></a>
|
<a href="/create_playlist?referer=<%= URI.encode_www_form("/feed/playlists") %>"><%= translate(locale, "Create playlist") %></a>
|
||||||
</h3>
|
</h3>
|
||||||
</div>
|
</div>
|
||||||
<div class="pure-u-1-3">
|
<div class="pure-u-1-3">
|
||||||
<h3 style="text-align:right">
|
<h3 style="text-align:right">
|
||||||
<a href="/data_control?referer=<%= URI.encode_www_form(referer) %>">
|
<a href="/data_control?referer=<%= URI.encode_www_form("/feed/playlists") %>">
|
||||||
<%= translate(locale, "Import/export") %>
|
<%= translate(locale, "Import/export") %>
|
||||||
</a>
|
</a>
|
||||||
</h3>
|
</h3>
|
||||||
|
Loading…
Reference in New Issue
Block a user