feat(import): youtube csv playlist import

This commit is contained in:
Federico Di Filitto 2023-03-21 01:45:14 +01:00
parent 858a284bf9
commit 3ccf1cb9f5
2 changed files with 39 additions and 0 deletions

View File

@ -310,6 +310,8 @@ module Invidious::Routes::PreferencesRoute
response: error_template(415, "Invalid subscription file uploaded")
)
end
when "import_youtube_playlist"
Invidious::User::Import.from_youtube_playlist(user, body)
when "import_freetube"
Invidious::User::Import.from_freetube(user, body)
when "import_newpipe_subscriptions"

View File

@ -149,6 +149,43 @@ struct Invidious::User
return true
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
# -------------------