mirror of
https://github.com/iv-org/invidious.git
synced 2024-12-22 16:19:53 +05:30
User: Add support for importing Youtube watch history (#4171)
This commit is contained in:
commit
2414e7db41
@ -82,7 +82,7 @@
|
|||||||
|
|
||||||
**Data import/export**
|
**Data import/export**
|
||||||
- Import subscriptions from YouTube, NewPipe and Freetube
|
- Import subscriptions from YouTube, NewPipe and Freetube
|
||||||
- Import watch history from NewPipe
|
- Import watch history from YouTube and NewPipe
|
||||||
- Export subscriptions to NewPipe and Freetube
|
- Export subscriptions to NewPipe and Freetube
|
||||||
- Import/Export Invidious user data
|
- Import/Export Invidious user data
|
||||||
|
|
||||||
|
@ -40,6 +40,7 @@
|
|||||||
"Import Invidious data": "Import Invidious JSON data",
|
"Import Invidious data": "Import Invidious JSON data",
|
||||||
"Import YouTube subscriptions": "Import YouTube/OPML subscriptions",
|
"Import YouTube subscriptions": "Import YouTube/OPML subscriptions",
|
||||||
"Import YouTube playlist (.csv)": "Import YouTube playlist (.csv)",
|
"Import YouTube playlist (.csv)": "Import YouTube playlist (.csv)",
|
||||||
|
"Import YouTube watch history (.json)": "Import YouTube watch history (.json)",
|
||||||
"Import FreeTube subscriptions (.db)": "Import FreeTube subscriptions (.db)",
|
"Import FreeTube subscriptions (.db)": "Import FreeTube subscriptions (.db)",
|
||||||
"Import NewPipe subscriptions (.json)": "Import NewPipe subscriptions (.json)",
|
"Import NewPipe subscriptions (.json)": "Import NewPipe subscriptions (.json)",
|
||||||
"Import NewPipe data (.zip)": "Import NewPipe data (.zip)",
|
"Import NewPipe data (.zip)": "Import NewPipe data (.zip)",
|
||||||
|
@ -461,6 +461,7 @@
|
|||||||
"Standard YouTube license": "标准 YouTube 许可证",
|
"Standard YouTube license": "标准 YouTube 许可证",
|
||||||
"Download is disabled": "已禁用下载",
|
"Download is disabled": "已禁用下载",
|
||||||
"Import YouTube playlist (.csv)": "导入 YouTube 播放列表(.csv)",
|
"Import YouTube playlist (.csv)": "导入 YouTube 播放列表(.csv)",
|
||||||
|
"Import YouTube watch history (.json)": "导入 YouTube 观看历史(.json)",
|
||||||
"generic_button_cancel": "取消",
|
"generic_button_cancel": "取消",
|
||||||
"playlist_button_add_items": "添加视频",
|
"playlist_button_add_items": "添加视频",
|
||||||
"generic_button_delete": "删除",
|
"generic_button_delete": "删除",
|
||||||
|
@ -461,6 +461,7 @@
|
|||||||
"Standard YouTube license": "標準 YouTube 授權條款",
|
"Standard YouTube license": "標準 YouTube 授權條款",
|
||||||
"Download is disabled": "已停用下載",
|
"Download is disabled": "已停用下載",
|
||||||
"Import YouTube playlist (.csv)": "匯入 YouTube 播放清單 (.csv)",
|
"Import YouTube playlist (.csv)": "匯入 YouTube 播放清單 (.csv)",
|
||||||
|
"Import YouTube watch history (.json)": "匯入 YouTube 觀看歷史 (.json)",
|
||||||
"generic_button_cancel": "取消",
|
"generic_button_cancel": "取消",
|
||||||
"generic_button_edit": "編輯",
|
"generic_button_edit": "編輯",
|
||||||
"generic_button_save": "儲存",
|
"generic_button_save": "儲存",
|
||||||
|
@ -319,6 +319,15 @@ module Invidious::Routes::PreferencesRoute
|
|||||||
response: error_template(415, "Invalid playlist file uploaded")
|
response: error_template(415, "Invalid playlist file uploaded")
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
when "import_youtube_wh"
|
||||||
|
filename = part.filename || ""
|
||||||
|
success = Invidious::User::Import.from_youtube_wh(user, body, filename, type)
|
||||||
|
|
||||||
|
if !success
|
||||||
|
haltf(env, status_code: 415,
|
||||||
|
response: error_template(415, "Invalid watch history file uploaded")
|
||||||
|
)
|
||||||
|
end
|
||||||
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"
|
||||||
|
@ -218,6 +218,26 @@ struct Invidious::User
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def from_youtube_wh(user : User, body : String, filename : String, type : String) : Bool
|
||||||
|
extension = filename.split(".").last
|
||||||
|
|
||||||
|
if extension == "json" || type == "application/json"
|
||||||
|
data = JSON.parse(body)
|
||||||
|
watched = data.as_a.compact_map do |item|
|
||||||
|
next unless url = item["titleUrl"]?
|
||||||
|
next unless match = url.as_s.match(/\?v=(?<video_id>[a-zA-Z0-9_-]+)$/)
|
||||||
|
match["video_id"]
|
||||||
|
end
|
||||||
|
watched.reverse! # YouTube have newest first
|
||||||
|
user.watched += watched
|
||||||
|
user.watched.uniq!
|
||||||
|
Invidious::Database::Users.update_watch_history(user)
|
||||||
|
return true
|
||||||
|
else
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
# -------------------
|
# -------------------
|
||||||
# Freetube
|
# Freetube
|
||||||
# -------------------
|
# -------------------
|
||||||
|
@ -26,6 +26,11 @@
|
|||||||
<input type="file" id="import_youtube_pl" name="import_youtube_pl">
|
<input type="file" id="import_youtube_pl" name="import_youtube_pl">
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<div class="pure-control-group">
|
||||||
|
<label for="import_youtube_wh"><%= translate(locale, "Import YouTube watch history (.json)") %></label>
|
||||||
|
<input type="file" id="import_youtube_wh" name="import_youtube_wh">
|
||||||
|
</div>
|
||||||
|
|
||||||
<div class="pure-control-group">
|
<div class="pure-control-group">
|
||||||
<label for="import_freetube"><%= translate(locale, "Import FreeTube subscriptions (.db)") %></label>
|
<label for="import_freetube"><%= translate(locale, "Import FreeTube subscriptions (.db)") %></label>
|
||||||
<input type="file" id="import_freetube" name="import_freetube">
|
<input type="file" id="import_freetube" name="import_freetube">
|
||||||
|
Loading…
Reference in New Issue
Block a user