mirror of
https://github.com/iv-org/invidious.git
synced 2025-08-27 23:18:35 +00:00
feat(import): youtube csv playlist import
This commit is contained in:
parent
858a284bf9
commit
3ccf1cb9f5
@ -310,6 +310,8 @@ module Invidious::Routes::PreferencesRoute
|
|||||||
response: error_template(415, "Invalid subscription file uploaded")
|
response: error_template(415, "Invalid subscription file uploaded")
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
when "import_youtube_playlist"
|
||||||
|
Invidious::User::Import.from_youtube_playlist(user, body)
|
||||||
when "import_freetube"
|
when "import_freetube"
|
||||||
Invidious::User::Import.from_freetube(user, body)
|
Invidious::User::Import.from_freetube(user, body)
|
||||||
when "import_newpipe_subscriptions"
|
when "import_newpipe_subscriptions"
|
||||||
|
@ -149,6 +149,43 @@ struct Invidious::User
|
|||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# -------------------
|
||||||
|
# YouTube playlist
|
||||||
|
# -------------------
|
||||||
|
|
||||||
|
def from_youtube_playlist(user : User, body : String)
|
||||||
|
|
||||||
|
csv = CSV.new(body, headers: true)
|
||||||
|
csv.next
|
||||||
|
|
||||||
|
playlist_title = csv[4]
|
||||||
|
playlist_description = csv[5]
|
||||||
|
playlist = create_playlist(playlist_title, PlaylistPrivacy::Private, user, playlist_description)
|
||||||
|
|
||||||
|
# skip playlist data
|
||||||
|
csv.next
|
||||||
|
|
||||||
|
# skip the blank lines before the videos
|
||||||
|
until csv[0] != ""
|
||||||
|
csv.next
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
while csv.next
|
||||||
|
# check if the string is a valid
|
||||||
|
#YouTube video ID
|
||||||
|
video_id = csv[0]
|
||||||
|
if /^[A-Za-z0-9_-]{11}$/ =~ video_id
|
||||||
|
begin
|
||||||
|
video = get_video(video_id)
|
||||||
|
playlist.add_new_video(video)
|
||||||
|
rescue ex : NotFoundException
|
||||||
|
rescue ex
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
# -------------------
|
# -------------------
|
||||||
# Freetube
|
# Freetube
|
||||||
# -------------------
|
# -------------------
|
||||||
|
Loading…
Reference in New Issue
Block a user