-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
209 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
_G.LazyYoutubeMusicGeneratorMain = _G.LazyYoutubeMusicGeneratorMain or {} | ||
_G.LazyYoutubeMusicGeneratorMain.ModPath = _G.LazyYoutubeMusicGeneratorMain.ModPath or ModPath | ||
_G.LazyYoutubeMusicGeneratorMain.Download = function(ThisDL_ID) | ||
local __YPMF = _G.LazyYoutubeMusicGeneratorMain | ||
local ThisModPath = __YPMF.ModPath | ||
local ThisDL_URL = 'https://www.youtube.com/watch?v='..ThisDL_ID | ||
local __BPath = Application:base_path() | ||
local __B_MPath = __BPath..'/'..ThisModPath | ||
--local __dump_json = ThisModPath..'__dump.json' | ||
local __ffmpeg_exe = Application:nice_path(__B_MPath.."/ffmpeg.exe", false) | ||
local __ogg_folder = Application:nice_path(__B_MPath..'/__tmp_oggs/', false) | ||
os.execute(string.format('rd /S /Q "%s"', __ogg_folder)) | ||
os.execute(string.format('md "%s"', __ogg_folder)) | ||
--os.remove(__dump_json) | ||
--os.execute(tostring(string.format('yt-dlp.exe --quiet --no-warnings --simulate --dump-json "%s" >> "%s"', 'https://www.youtube.com/watch?v=w2HR1aUvJGs', __dump_json))) | ||
local __to_MusicMod = function(__path, __yt_id) | ||
__path = tostring(__path) | ||
__yt_id = tostring(__yt_id) | ||
if not file.DirectoryExists(__path) then | ||
|
||
else | ||
local __files = file.GetFiles(__path) | ||
if type(__files) ~= "table" or table.empty(__files) then | ||
|
||
else | ||
local __VideoInfoFile = io.open(ThisModPath..'/__tmp_oggs/'..ThisDL_ID..'.info.json', 'r') | ||
if __VideoInfoFile then | ||
local __VideoInfoJson = json.decode(__VideoInfoFile:read("*all")) | ||
__VideoInfoFile:close() | ||
if type(__VideoInfoJson) == "table" and not table.empty(__VideoInfoJson) and type(__VideoInfoJson.id) == "string" and __VideoInfoJson.id == __yt_id and type(__VideoInfoJson.title) == "string" then | ||
local __music_mod_name = '[Music] '..__yt_id | ||
local __music_mod_path = __BPath..'/mods/'..__music_mod_name..'/' | ||
local __music_mod_path_nice = Application:nice_path(__music_mod_path, false) | ||
|
||
--[[ creat folder ]] | ||
os.execute(string.format('rd /S /Q "%s"', __music_mod_path_nice)) | ||
os.execute(string.format('md "%s"', __music_mod_path_nice)) | ||
os.execute(string.format('md "%s"', __music_mod_path_nice..'/loc/')) | ||
os.execute(string.format('md "%s"', __music_mod_path_nice..'/sounds/')) | ||
|
||
--[[ music name file and info ]] | ||
local __music_mod_name_to_file_path = __music_mod_path..'/'..__VideoInfoJson.title..'.txt' | ||
local __music_mod_name_to_file = io.open(__music_mod_name_to_file_path, 'w+') | ||
if __music_mod_name_to_file then | ||
__music_mod_name_to_file:write(json.encode(__VideoInfoJson)) | ||
__music_mod_name_to_file:close() | ||
end | ||
|
||
--[[ main.xml ]] | ||
local __music_mod_main_xml_path = __music_mod_path..'/main.xml' | ||
local __music_mod_main_xml = io.open(__music_mod_main_xml_path, 'w+') | ||
if __music_mod_main_xml then | ||
__music_mod_main_xml:write('<table name="'..__music_mod_name..'"> \n') | ||
__music_mod_main_xml:write(' <Localization directory="loc" default="en.json"/> \n') | ||
__music_mod_main_xml:write(' <MenuMusic id="yt_'..__yt_id..'" source="sounds/'..__yt_id..'.ogg"/> \n') | ||
__music_mod_main_xml:write('</table> \n') | ||
__music_mod_main_xml:close() | ||
end | ||
|
||
--[[ write loc file ]] | ||
local __music_mod_loc_path = __music_mod_path..'/loc/en.json' | ||
local __music_mod_loc = io.open(__music_mod_loc_path, 'w+') | ||
if __music_mod_loc then | ||
local __tmp_loc = { | ||
["menu_jukebox_yt_"..__yt_id..""] = __VideoInfoJson.title, | ||
["menu_jukebox_screen_yt_"..__yt_id..""] = __VideoInfoJson.title | ||
} | ||
__music_mod_loc:write(json.encode(__tmp_loc)) | ||
__music_mod_loc:close() | ||
--managers.localization:add_localized_strings(__tmp_loc) | ||
end | ||
|
||
--[[ copy ogg ]] | ||
local __ogg_from_nice = Application:nice_path(__path..'/'..__yt_id..'.ogg', false) | ||
local __ogg_to_nice = Application:nice_path(__music_mod_path_nice..'/sounds/', false) | ||
os.execute(string.format('copy /Y "%s" "%s"', __ogg_from_nice, __ogg_to_nice)) | ||
|
||
--[[ Load into Game ]] | ||
if ModCore then | ||
--ModCore:new(__music_mod_main_xml_path, true, true) | ||
end | ||
end | ||
end | ||
end | ||
end | ||
return | ||
end | ||
assert( | ||
os.execute( | ||
string.format('yt-dlp.exe --quiet --no-warnings --write-info-json --extract-audio --audio-format vorbis --ffmpeg-location "%s" --paths "%s" --output "%s" "%s"', __ffmpeg_exe, __ogg_folder, "%(id)s.%(ext)s", ThisDL_URL) | ||
) == 0, | ||
pcall(__to_MusicMod, __ogg_folder, ThisDL_ID) | ||
) | ||
return | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
{ | ||
"menu_LazyYoutubeMusicGenerator_name": "Lazy Youtube Music Generator", | ||
"menu_LazyYoutubeMusicGenerator_desc": " ", | ||
"menu_LazyYoutubeMusicGenerator_menu_msgs": "You're going to download https://youtu.be/$yturl$", | ||
"menu_LazyYoutubeMusicGenerator_menu_yes": "Yes", | ||
"menu_LazyYoutubeMusicGenerator_menu_show": "Open URL", | ||
"menu_LazyYoutubeMusicGenerator_menu_close": "[Close]", | ||
"menu_LazyYoutubeMusicGenerator_menu_downloading": "Nowloading...", | ||
"menu_LazyYoutubeMusicGenerator_menu_download_ok": "OK", | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
https://ffmpeg.org/download.html |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<table name="Lazy Youtube Music Generator"> | ||
<Localization directory="Loc" default="English.txt"> | ||
<loc file="English.txt" language="english"/> | ||
</Localization> | ||
</table> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
_G.LazyYoutubeMusicGeneratorMain = _G.LazyYoutubeMusicGeneratorMain or {} | ||
_G.LazyYoutubeMusicGeneratorMain.ModPath = _G.LazyYoutubeMusicGeneratorMain.ModPath or ModPath | ||
_G.LazyYoutubeMusicGeneratorMain.MenuID = "LazyYoutubeMusicGeneratorMenuID" | ||
|
||
Hooks:Add("MenuManagerSetupCustomMenus", "LazyYoutubeMusicGeneratorSetup", function(menu_manager, nodes) | ||
MenuHelper:NewMenu(_G.LazyYoutubeMusicGeneratorMain.MenuID) | ||
end) | ||
|
||
Hooks:Add("MenuManagerBuildCustomMenus", "LazyYoutubeMusicGeneratorBuild", function(menu_manager, nodes) | ||
nodes[_G.LazyYoutubeMusicGeneratorMain.MenuID] = MenuHelper:BuildMenu(_G.LazyYoutubeMusicGeneratorMain.MenuID) | ||
MenuHelper:AddMenuItem(nodes["blt_options"], _G.LazyYoutubeMusicGeneratorMain.MenuID, "menu_LazyYoutubeMusicGenerator_name", "menu_LazyYoutubeMusicGenerator_desc") | ||
end) | ||
|
||
Hooks:Add("MenuManagerPopulateCustomMenus", "LazyYoutubeMusicGeneratorPopulate", function(menu_manager, nodes) | ||
MenuCallbackHandler.RunLazyYoutubeMusicGeneratorFunc = function() | ||
local __clipboard = Application:get_clipboard() | ||
__clipboard = tostring(__clipboard) | ||
local vidid1 = string.match(__clipboard, "v=(...........)") | ||
local vidid2 = string.match(__clipboard, "youtu.be/(...........)") | ||
local vidid_now | ||
if vidid1 then | ||
vidid_now = vidid1 | ||
elseif vidid2 then | ||
vidid_now = vidid2 | ||
end | ||
local menu_title = managers.localization:text("menu_LazyYoutubeMusicGenerator_name") | ||
local menu_message = managers.localization:text("menu_LazyYoutubeMusicGenerator_menu_msgs") | ||
menu_message = menu_message:gsub('%$yturl%$', vidid_now) | ||
local menu_options = { | ||
[1] = { | ||
text = managers.localization:text("menu_LazyYoutubeMusicGenerator_menu_yes"), | ||
callback = function() | ||
QuickMenu:new( | ||
menu_title, | ||
managers.localization:text("menu_LazyYoutubeMusicGenerator_menu_downloading"), | ||
{ | ||
{ | ||
text = managers.localization:text("menu_LazyYoutubeMusicGenerator_menu_close"), | ||
is_cancel_button = true | ||
} | ||
} | ||
):Show() | ||
_G.LazyYoutubeMusicGeneratorMain.Download(vidid_now) | ||
QuickMenu:new( | ||
menu_title, | ||
managers.localization:text("menu_LazyYoutubeMusicGenerator_menu_download_ok"), | ||
{ | ||
{ | ||
text = managers.localization:text("menu_LazyYoutubeMusicGenerator_menu_close"), | ||
is_cancel_button = true | ||
} | ||
} | ||
):Show() | ||
end | ||
}, | ||
[2] = { | ||
text = managers.localization:text("menu_LazyYoutubeMusicGenerator_menu_show"), | ||
callback = function() | ||
Steam:overlay_activate("url", "https://youtu.be/"..vidid_now) | ||
end, | ||
}, | ||
[3] = { | ||
text = managers.localization:text("menu_LazyYoutubeMusicGenerator_menu_close"), | ||
is_cancel_button = true | ||
} | ||
} | ||
local menu = QuickMenu:new(menu_title, menu_message, menu_options) | ||
menu:Show() | ||
end | ||
MenuHelper:AddButton({ | ||
id = "RunLazyYoutubeMusicGenerator", | ||
title = "menu_LazyYoutubeMusicGenerator_name", | ||
desc = "menu_LazyYoutubeMusicGenerator_desc", | ||
callback = "RunLazyYoutubeMusicGeneratorFunc", | ||
menu_id = _G.LazyYoutubeMusicGeneratorMain.MenuID | ||
}) | ||
end) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
{ | ||
"name": "Lazy Youtube Music Generator", | ||
"description": "https://modworkshop.net/mod/39301", | ||
"author": "Dr_Newbie", | ||
"contact": "https://modworkshop.net/mod/39301", | ||
"version": "1", | ||
"priority": 100, | ||
"blt_version": 2, | ||
"hooks": [ | ||
{ | ||
"hook_id": "lib/entry", | ||
"script_path": "Core.lua" | ||
}, | ||
{ | ||
"hook_id": "lib/managers/menumanager", | ||
"script_path": "menumanager.lua" | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
https://github.com/yt-dlp/yt-dlp |