在大文件的尾巴前附加文本

时间:2019-07-02 13:59:44

标签: powershell

我正在尝试使用PowerShell根据youtube-dl的打印输出创建NoSQL JSON数据库。每次下载视频时,都会打印一个JSON格式的字符串,我需要将其附加到我的NoSQL数据库中。但是,要使我的查看器应用程序读取数据库,我需要字符]始终保留在最后一行,这意味着当我插入JSON行时,它们必须位于该行的上方。但是,考虑到要下载的视频数量,我已经计算出我的nosql数据库将成为一个很大的文件。

这是我当前的PowerShell脚本:

Write-Host "Searching for and downloading videos . . . "
if (![System.IO.File]::Exists('.\database.js')) {
    Set-Content -Path .\database.js -Value "const database = [
]"
}
youtube-dl.exe --config-location config.txt --print-json >> database.js
Read-Host -Prompt "Done, press Enter to exit"

这是我的database.js文件的理想状态:

const database = [
{"id": "Zre0TRsGVsA", "uploader": "an0nymooose", "uploader_id": "an0nymooose", "uploader_url": "http://www.youtube.com/user/an0nymooose", "channel_id": "UCpclRlEJ2oh6JDEJy68UjKA", "channel_url": "http://www.youtube.com/channel/UCpclRlEJ2oh6JDEJy68UjKA", "upload_date": "20160406", "license": null, "creator": null, "title": "[SFM] Marco Bros", "alt_title": null, "thumbnail": "https://i.ytimg.com/vi/Zre0TRsGVsA/maxresdefault.jpg", "description": "i'll show myself out\n\nI've been super busy, ill still make cool stuff dont worry.\nSource\nhttps://soundcloud.com/regnidlab-paej-rolyat/it-was-your-fault", "categories": ["Film & Animation"], "tags": ["sfm mario", "anonymoose", "an0nymoose", "source film maker"], "subtitles": {}, "automatic_captions": {}, "duration": 19, "age_limit": 0, "annotations": null, "chapters": null, "webpage_url": "https://www.youtube.com/watch?v=Zre0TRsGVsA", "view_count": 1343237, "like_count": 30493, "dislike_count": 245, "average_rating": 4.9681177, "formats": [{"format_id": "249", "url": "https://r3---sn-5aapxquxaxjvh-p5qe.googlevideo.com/videoplayback?expire=1562102342&ei=5nUbXaTpKYu38gSFxpKABg&ip=205.201.245.3&id=o-AIQyMAv9KAgXr7OP25tqJ3GonDqvQCK1eXYzI5QA5hM0&itag=249&source=youtube&requiressl=yes&mm=31%2C29&mn=sn-5aapxquxaxjvh-p5qe%2Csn-p5qs7n76&ms=au%2Crdu&mv=m&mvi=2&pl=20&initcwndbps=1252500&mime=audio%2Fwebm&gir=yes&clen=118049&dur=18.701&lmt=1559546502364814&mt=1562080584&fvip=6&keepalive=yes&c=WEB&txp=5432432&sparams=expire%2Cei%2Cip%2Cid%2Citag%2Csource%2Crequiressl%2Cmime%2Cgir%2Cclen%2Cdur%2Clmt&sig=ALgxI2wwRgIhAJkKbG91rpZ-GaMSW_lUsNPZVQaQ16lT6d5s_AdInwZAAiEAvcqdDVrR6H092E3n0zss6L6Iat79RGITr2f-QvnySJM%3D&lsparams=mm%2Cmn%2Cms%2Cmv%2Cmvi%2Cpl%2Cinitcwndbps&lsig=AHylml4wRgIhAJz3ixqopsu5l8C_jzP-E4EzYnxGBFIC7XGGjD4BRPyIAiEAxoV0lO0XBysnXt8k50Q7F5J7Yig9lS3Xc25XOvHeODo%3D&ratebypass=yes", "player_url": "/yts/jsbin/player_ias-vflxACNZ2/en_US/base.js", "ext": "webm", "format_note": "DASH audio", "acodec": "opus", "abr": 50, "filesize": 118049, "tbr": 52.326, "quality": -1, "vcodec": "none", "downloader_options": {"http_chunk_size": 10485760}, "format": "249 - audio only (DASH audio)", "protocol": "https", "http_headers": {"User-Agent": "Mozilla/5.0 (X11; Linux x86_64; rv:59.0) Gecko/20100101 Firefox/59.0", "Accept-Charset": "ISO-8859-1,utf-8;q=0.7,*;q=0.7", "Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8", "Accept-Encoding": "gzip, deflate", "Accept-Language": "en-us,en;q=0.5"}}, {"format_id": "250", "url": "https://r3---sn-5aapxquxaxjvh-p5qe.googlevideo.com/videoplayback?expire=1562102342&ei=5nUbXaTpKYu38gSFxpKABg&ip=205.201.245.3&id=o-AIQyMAv9KAgXr7OP25tqJ3GonDqvQCK1eXYzI5QA5hM0&itag=250&source=youtube&requiressl=yes&mm=31%2C29&mn=sn-5aapxquxaxjvh-p5qe%2Csn-p5qs7n76&ms=au%2Crdu&mv=m&mvi=2&pl=20&initcwndbps=1252500&mime=audio%2Fwebm&gir=yes&clen=153599&dur=18.701&lmt=1559546502464967&mt=1562080584&fvip=6&keepalive=yes&c=WEB&txp=5432432&sparams=expire%2Cei%2Cip%2Cid%2Citag%2Csource%2Crequiressl%2Cmime%2Cgir%2Cclen%2Cdur%2Clmt&sig=ALgxI2wwRAIge6NHeiSSt0S5ozyQf9o0bW6ddEzcal2rRXPogceLWf0CIAPdRticAWQz6VvPG5MUTtg-t8EubtuJyC7lInCLt0uz&lsparams=mm%2Cmn%2Cms%2Cmv%2Cmvi%2Cpl%2Cinitcwndbps&lsig=AHylml4wRgIhAJz3ixqopsu5l8C_jzP-E4EzYnxGBFIC7XGGjD4BRPyIAiEAxoV0lO0XBysnXt8k50Q7F5J7Yig9lS3Xc25XOvHeODo%3D&ratebypass=yes", "player_url": "/yts/jsbin/player_ias-vflxACNZ2/en_US/base.js", "ext": "webm", "format_note": "DASH audio", "acodec": "opus", "abr": 70, "filesize": 153599, "tbr": 68.228, "quality": -1, "vcodec": "none", "downloader_options": {"http_chunk_size": 10485760}, "format": "250 - audio only (DASH audio)", "protocol": "https", "http_headers": {"User-Agent": "Mozilla/5.0 (X11; Linux x86_64; rv:59.0) Gecko/20100101 Firefox/59.0", "Accept-Charset": "ISO-8859-1,utf-8;q=0.7,*;q=0.7", "Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8", "Accept-Encoding": "gzip, deflate", "Accept-Language": "en-us,en;q=0.5"}}, {"format_id": "251", "url": "https://r3---sn-5aapxquxaxjvh-p5qe.googlevideo.com/videoplayback?expire=1562102342&ei=5nUbXaTpKYu38gSFxpKABg&ip=205.201.245.3&id=o-AIQyMAv9KAgXr7OP25tqJ3GonDqvQCK1eXYzI5QA5hM0&itag=251&source=youtube&requiressl=yes&mm=31%2C29&mn=sn-5aapxquxaxjvh-p5qe%2Csn-p5qs7n76&ms=au%2Crdu&mv=m&mvi=2&pl=20&initcwndbps=1252500&mime=audio%2Fwebm&gir=yes&clen=295267&dur=18.701&lmt=1559546502380639&mt=1562080584&fvip=6&keepalive=yes&c=WEB&txp=5432432&sparams=expire%2Cei%2Cip%2Cid%2Citag%2Csource%2Crequiressl%2Cmime%2Cgir%2Cclen%2Cdur%2Clmt&sig=ALgxI2wwRAIgahDisTbrJoqazA72mCaTG-1QuX1qS9IcbWHe0IEFcicCIElvUXyJL83u9E__VzV_5EUeaWejN1ki9kRlEnNCq7Y_&lsparams=mm%2Cmn%2Cms%2Cmv%2Cmvi%2Cpl%2Cinitcwndbps&lsig=AHylml4wRgIhAJz3ixqopsu5l8C_jzP-E4EzYnxGBFIC7XGGjD4BRPyIAiEAxoV0lO0XBysnXt8k50Q7F5J7Yig9lS3Xc25XOvHeODo%3D&ratebypass=yes", "player_url": "/yts/jsbin/player_ias-vflxACNZ2/en_US/base.js", "ext": "webm", "format_note": "DASH audio", "acodec": "opus", "abr": 160, "filesize": 295267, "tbr": 129.438, "quality": -1, "vcodec": "none", "downloader_options": {"http_chunk_size": 10485760}, "format": "251 - audio only (DASH audio)", "protocol": "https", "http_headers": {"User-Agent": "Mozilla/5.0 (X11; Linux x86_64; rv:59.0) Gecko/20100101 Firefox/59.0", "Accept-Charset": "ISO-8859-1,utf-8;q=0.7,*;q=0.7", "Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8", "Accept-Encoding": "gzip, deflate", "Accept-Language": "en-us,en;q=0.5"}}, {"format_id": "140", "url": "https://r3---sn-5aapxquxaxjvh-p5qe.googlevideo.com/videoplayback?expire=1562102342&ei=5nUbXaTpKYu38gSFxpKABg&ip=205.201.245.3&id=o-AIQyMAv9KAgXr7OP25tqJ3GonDqvQCK1eXYzI5QA5hM0&itag=140&source=youtube&requiressl=yes&mm=31%2C29&mn=sn-5aapxquxaxjvh-p5qe%2Csn-p5qs7n76&ms=au%2Crdu&mv=m&mvi=2&pl=20&initcwndbps=1252500&mime=audio%2Fmp4&gir=yes&clen=303964&dur=18.738&lmt=1559546502363003&mt=1562080584&fvip=6&keepalive=yes&c=WEB&txp=5432432&sparams=expire%2Cei%2Cip%2Cid%2Citag%2Csource%2Crequiressl%2Cmime%2Cgir%2Cclen%2Cdur%2Clmt&sig=ALgxI2wwRAIgMZITJIqAH-Ir0zOrbtQBXKXuyRVSlCicdejddbh_EAcCIBsOsXYEBN-qlSa7Ftodnr8gB_7yEP8jJNJNSC-Rf7Jy&lsparams=mm%2Cmn%2Cms%2Cmv%2Cmvi%2Cpl%2Cinitcwndbps&lsig=AHylml4wRgIhAJz3ixqopsu5l8C_jzP-E4EzYnxGBFIC7XGGjD4BRPyIAiEAxoV0lO0XBysnXt8k50Q7F5J7Yig9lS3Xc25XOvHeODo%3D&ratebypass=yes", "player_url": "/yts/jsbin/player_ias-vflxACNZ2/en_US/base.js", "ext": "m4a", "format_note": "DASH audio", "acodec": "mp4a.40.2", "abr": 128, "container": "m4a_dash", "filesize": 303964, "tbr": 130.404, "quality": -1, "vcodec": "none", "downloader_options": {"http_chunk_size": 10485760}, "format": "140 - audio only (DASH audio)", "protocol": "https", "http_headers": {"User-Agent": "Mozilla/5.0 (X11; Linux x86_64; rv:59.0) Gecko/20100101 Firefox/59.0", "Accept-Charset": "ISO-8859-1,utf-8;q=0.7,*;q=0.7", "Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8", "Accept-Encoding": "gzip, deflate", "Accept-Language": "en-us,en;q=0.5"}}, {"format_id": "171", "url": "https://r3---sn-5aapxquxaxjvh-p5qe.googlevideo.com/videoplayback?expire=1562102342&ei=5nUbXaTpKYu38gSFxpKABg&ip=205.201.245.3&id=o-AIQyMAv9KAgXr7OP25tqJ3GonDqvQCK1eXYzI5QA5hM0&itag=171&source=youtube&requiressl=yes&mm=31%2C29&mn=sn-5aapxquxaxjvh-p5qe%2Csn-p5qs7n76&ms=au%2Crdu&mv=m&mvi=2&pl=20&initcwndbps=1252500&mime=audio%2Fwebm&gir=yes&clen=320876&dur=18.690&lmt=1559546502459212&mt=1562080584&fvip=6&keepalive=yes&c=WEB&txp=5432432&sparams=expire%2Cei%2Cip%2Cid%2Citag%2Csource%2Crequiressl%2Cmime%2Cgir%2Cclen%2Cdur%2Clmt&sig=ALgxI2wwRgIhANaKnYXGFFDN7w78hbmCC7opUKNB4stV6M4fD8hf6vcAAiEA4FnYWosi8AaEJuyR_fTljVrG10vkAc4MYEDuvn6jgJ8%3D&lsparams=mm%2Cmn%2Cms%2Cmv%2Cmvi%2Cpl%2Cinitcwndbps&lsig=AHylml4wRgIhAJz3ixqopsu5l8C_jzP-E4EzYnxGBFIC7XGGjD4BRPyIAiEAxoV0lO0XBysnXt8k50Q7F5J7Yig9lS3Xc25XOvHeODo%3D&ratebypass=yes", "player_url": "/yts/jsbin/player_ias-vflxACNZ2/en_US/base.js", "ext": "webm", "acodec": "vorbis", "format_note": "DASH audio", "abr": 128, "filesize": 320876, "tbr": 148.28, "quality": -1, "vcodec": "none", "downloader_options": {"http_chunk_size": 10485760}, "format": "171 - audio only (DASH audio)", "protocol": "https", "http_headers": {"User-Agent": "Mozilla/5.0 (X11; Linux x86_64; rv:59.0) Gecko/20100101 Firefox/59.0", "Accept-Charset": "ISO-8859-1,utf-8;q=0.7,*;q=0.7", "Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8", "Accept-Encoding": "gzip, deflate", "Accept-Language": "en-us,en;q=0.5"}}, {"format_id": "278", "url": "https://r3---sn-5aapxquxaxjvh-p5qe.googlevideo.com/videoplayback?expire=1562102342&ei=5nUbXaTpKYu38gSFxpKABg&ip=205.201.245.3&id=o-AIQyMAv9KAgXr7OP25tqJ3GonDqvQCK1eXYzI5QA5hM0&itag=278&aitags=133%2C134%2C135%2C136%2C137%2C160%2C242%2C243%2C244%2C247%2C248%2C278%2C298%2C299%2C302%2C303&source=youtube&requiressl=yes&mm=31%2C29&mn=sn-5aapxquxaxjvh-p5qe%2Csn-p5qs7n76&ms=au%2Crdu&mv=m&mvi=2&pl=20&initcwndbps=1252500&mime=video%2Fwebm&gir=yes&clen=219883&dur=18.666&lmt=1559546957289995&mt=1562080584&fvip=6&keepalive=yes&c=WEB&txp=5432432&sparams=expire%2Cei%2Cip%2Cid%2Caitags%2Csource%2Crequiressl%2Cmime%2Cgir%2Cclen%2Cdur%2Clmt&sig=ALgxI2wwRQIhAPa2epstA8eMxFspW2eR_DFK48f3df74nhwE3uJjx9YtAiBw0aHV2ydjeh4boYq8XggbP-SO7UeR4wRGPIx6euNduA%3D%3D&lsparams=mm%2Cmn%2Cms%2Cmv%2Cmvi%2Cpl%2Cinitcwndbps&lsig=AHylml4wRgIhAJz3ixqopsu5l8C_jzP-E4EzYnxGBFIC7XGGjD4BRPyIAiEAxoV0lO0XBysnXt8k50Q7F5J7Yig9lS3Xc25XOvHeODo%3D&ratebypass=yes", "player_url": "/yts/jsbin/player_ias-vflxACNZ2/en_US/base.js", "ext": "webm", "height": 144, "format_note": "144p", "container": "webm", "vcodec": "vp9", "filesize": 219883, "tbr": 96.07, "width": 256, "fps": 30, "quality": -1, "acodec": "none", "downloader_options": {"http_chunk_size": 10485760}, "format": "278 - 256x144 (144p)", "protocol": "https", "http_headers": {"User-Agent": "Mozilla/5.0 (X11; Linux x86_64; rv:59.0) Gecko/20100101 Firefox/59.0", "Accept-Charset": "ISO-8859-1,utf-8;q=0.7,*;q=0.7", "Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8", "Accept-Encoding": "gzip, deflate", "Accept-Language": "en-uu...},
{"id": "RzMh3nTheCo", "uploader": "an0nymooose", "uploader_id": "an0nymooose", "uploader_url": "http://www.youtube.com/user/an0nymooose", "channel_id": "UCpclRlEJ2oh6JDEJy68UjKA", "channel_url": "http://www.youtube.com/channel/UCpclRlEJ2oh6JDEJy68UjKA", "upload_date": "20190401", "license": null, "creator": null, "title": "[SFM] Hocus Bogus", "alt_title": null, "thumbnail": "https://i.ytimg.com/vi/RzMh3nTheCo/maxresdefault.jpg", "description": "Months and months of work for the adult swim video, sorry. Hopefully you guys will like it, its got all 100% custom models/mapping which is very hard to get together and generate an idea for in SFM (i didnt model it tho, had it all converted). Here's the sad news: it didn't get approved at adult swim (wasn't notified until the video was fully done), but oh well I tried I guess. Sorta didn't want to post this video but I figured I put in a ton of work, but it didn't come out to be as perfect as I wanted, don't hate me pls.\n\nsnapchat: an0nsnap\ntwitter: https://twitter.com/an0nymoooseYT\ninsta: https://www.instagram.com/an0nymooose/\npatreon: https://www.patreon.com/an0nymooose\nSONG: https://soundcloud.com/tregsmusic/flow\nDiscord: https://discord.gg/WPVrE7t\n\nsome neat facts:\n\n-No valve models/textures\n-I was only given 1 model from the start, the rainbow guy (veryman) and told to do whatever, so I picked a song I liked, and sat there for hundreds of hours trying to generate ideas and animate it. By far the most difficult one I've done yet. (thanks Vince M. from adult swim for all the model help, and thank you SterlingFM for the modeling help)\n-a few runescape references in the video. The modified bones to bananas spell is the same as the ingame animation. (Same with the Ancient Magicks spell he casts on the cat)\n- The beard and the bag physics were all hand animated 100%, SFM has no real physics, and the beard itself probably has 700+ keys alone (pls watch and think \"wow nice beard physics an0nmose\").\n- valve please update sfm its incredibly buggy\n- ur kinda hot lollll... ;) add my snapchat ;))\n- https://imgur.com/a/0Yyl3\n\nFAQ:\n\nQ: amonmonoose more like anona-go-NOOSE urself LOL\nA: dude come on wtf\n\nQ: whens the next video!!! i need it NOW NOW NOW\nA: alch urself.\n\nQ: ananaOAONOOmoOOSE wat is CRACKIN!!\nA: bACK, GET BACK NOW", "categories": ["Film & Animation"], "tags": [], "subtitles": {}, "automatic_captions": {}, "duration": 103, "age_limit": 0, "annotations": null, "chapters": null, "webpage_url": "https://www.youtube.com/watch?v=RzMh3nTheCo", "view_count": 790679, "like_count": 62408, "dislike_count": 325, "average_rating": 4.9792771, "formats": [{"format_id": "249", "url": "https://r3---sn-5aapxquxaxjvh-p5qe.googlevideo.com/videoplayback?expire=1562102345&ei=6XUbXdrLIq6shwaojLuIAg&ip=205.201.245.3&id=o-AJr4pgfPjGzM_f0dYlbAI4kq8ljVvQ0LX1RdcsTivFPV&itag=249&source=youtube&requiressl=yes&mm=31%2C29&mn=sn-5aapxquxaxjvh-p5qe%2Csn-p5qs7n7e&ms=au%2Crdu&mv=m&mvi=2&pl=20&initcwndbps=1252500&mime=audio%2Fwebm&gir=yes&clen=674773&dur=102.961&lmt=1559550315355298&mt=1562080584&fvip=3&keepalive=yes&c=WEB&txp=5531432&sparams=expire%2Cei%2Cip%2Cid%2Citag%2Csource%2Crequiressl%2Cmime%2Cgir%2Cclen%2Cdur%2Clmt&sig=ALgxI2wwRQIgUsDQZKCx1KxfshHZiOz8vZoQuo6GEX5CCqRlxi0_cjICIQD3y4Ev-Zz03f66rcWDI9saUOOGqwwEltU6dRXiDShIQg%3D%3D&lsparams=mm%2Cmn%2Cms%2Cmv%2Cmvi%2Cpl%2Cinitcwndbps&lsig=AHylml4wRQIhAKmfnwS_dcIMrapCFNs4DYQqRspMTFKcExW_tJ4ORmL7AiBsfQiRa-YjkkDg6xWla-W2Pl0VWtMefpyLkK2e5E3Rzg%3D%3D&ratebypass=yes", "player_url": "/yts/jsbin/player_ias-vflxACNZ2/en_US/base.js", "ext": "webm", "format_note": "DASH audio", "acodec": "opus", "abr": 50, "filesize": 674773, "tbr": 54.492, "quality": -1, "vcodec": "none", "downloader_options": {"http_chunk_size": 10485760}, "format": "249 - audio only (DASH audio)", "protocol": "https", "http_headers": {"User-Agent": "Mozilla/5.0 (X11; Linux x86_64; rv:59.0) Gecko/20100101 Firefox/59.0", "Accept-Charset": "ISO-8859-1,utf-8;q=0.7,*;q=0.7", "Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8", "Accept-Encoding": "gzip, deflate", "Accept-Language": "en-us,en;q=0.5"}}, {"format_id": "250", "url": "https://r3---sn-5aapxquxaxjvh-p5qe.googlevideo.com/videoplayback?expire=1562102345&ei=6XUbXdrLIq6shwaojLuIAg&ip=205.201.245.3&id=o-AJr4pgfPjGzM_f0dYlbAI4kq8ljVvQ0LX1RdcsTivFPV&itag=250&source=youtube&requiressl=yes&mm=31%2C29&mn=sn-5aapxquxaxjvh-p5qe%2Csn-p5qs7n7e&ms=au%2Crdu&mv=m&mvi=2&pl=20&initcwndbps=1252500&mime=audio%2Fwebm&gir=yes&clen=881079&dur=102.961&lmt=1559550314949272&mt=1562080584&fvip=3&keepalive=yes&c=WEB&txp=5531432&sparams=expire%2Cei%2Cip%2Cid%2Citag%2Csource%2Crequiressl%2Cmime%2Cgir%2Cclen%2Cdur%2Clmt&sig=ALgxI2wwRQIgSBl6Dxy3PQT5ENME-q2PH62YPdYusJCb19tBv5ApgfgCIQDYO3iz1HqsiDPETxXWi4TdXG7gU-N4MU5PUOf0zuKkCQ%3D%3D&lsparams=mm%2Cmn%2Cms%2Cmv%2Cmvi%2Cpl%2Cinitcwndbps&lsig=AHylml4wRQIhAKmfnwS_dcIMrapCFNs4DYQqRspMTFKcExW_tJ4ORmL7AiBsfQiRa-YjkkDg6xWla-W2Pl0VWtMefpyLkK2e5E3Rzg%3D%3D&ratebypass=yes", "player_url": "/yts/jsbin/player_ias-vflxACNZ2/en_US/base.js", "ext": "webm", "format_note": "DASH audio", "acodec": "opus", "abr": 70, "filesize": 881079, "tbr": 72.143, "quality": -1, "vcodec": "none", "downloader_options": {"http_chunk_size": 10485760}, "format": "250 - audio only (DASH audio)", "protocol": "https", "http_headers": {"User-Agent": "Mozilla/5.0 (X11; Linux x86_64; rv:59.0) Gecko/20100101 Firefox/59.0", "Accept-Charset": "ISO-8859-1,utf-8;q=0.7,*;q=0.7", "Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8", "Accept-Encoding": "gzip, deflate", "Accept-Language": "en-us,en;q=0.5"}}, {"format_id": "140", "url": "https://r3---sn-5aapxquxaxjvh-p5qe.googlevideo.com/videoplayback?expire=1562102345&ei=6XUbXdrLIq6shwaojLuIAg&ip=205.201.245.3&id=o-AJr4pgfPjGzM_f0dYlbAI4kq8ljVvQ0LX1RdcsTivFPV&itag=140&source=youtube&requiressl=yes&mm=31%2C29&mn=sn-5aapxquxaxjvh-p5qe%2Csn-p5qs7n7e&ms=au%2Crdu&mv=m&mvi=2&pl=20&initcwndbps=1252500&mime=audio%2Fmp4&gir=yes&clen=1667731&dur=102.980&lmt=1559550314605164&mt=1562080584&fvip=3&keepalive=yes&c=WEB&txp=5531432&sparams=expire%2Cei%2Cip%2Cid%2Citag%2Csource%2Crequiressl%2Cmime%2Cgir%2Cclen%2Cdur%2Clmt&sig=ALgxI2wwRQIhAIUKI4wpVTVGIzvGrXyXMguSmHL3L6fsJrafsA50xCBrAiB4nui2-LZ5Ud-3ObvK7IMwK4G-n7kyYZTlpuOSgmUZDQ%3D%3D&lsparams=mm%2Cmn%2Cms%2Cmv%2Cmvi%2Cpl%2Cinitcwndbps&lsig=AHylml4wRQIhAKmfnwS_dcIMrapCFNs4DYQqRspMTFKcExW_tJ4ORmL7AiBsfQiRa-YjkkDg6xWla-W2Pl0VWtMefpyLkK2e5E3Rzg%3D%3D&ratebypass=yes", "player_url": "/yts/jsbin/player_ias-vflxACNZ2/en_US/base.js", "ext": "m4a", "format_note": "DASH audio", "acodec": "mp4a.40.2", "abr": 128, "container": "m4a_dash", "filesize": 1667731, "tbr": 130.43, "quality": -1, "vcodec": "none", "downloader_options": {"http_chunk_size": 10485760}, "format": "140 - audio only (DASH audio)", "protocol": "https", "http_headers": {"User-Agent": "Mozilla/5.0 (X11; Linux x86_64; rv:59.0) Gecko/20100101 Firefox/59.0", "Accept-Charset": "ISO-8859-1,utf-8;q=0.7,*;q=0.7", "Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8", "Accept-Encoding": "gzip, deflate", "Accept-Language": "en-us,en;q=0.5"}}, {"format_id": "171", "url": "https://r3---sn-5aapxquxaxjvh-p5qe.googlevideo.com/videoplayback?expire=1562102345&ei=6XUbXdrLIq6shwaojLuIAg&ip=205.201.245.3&id=o-AJr4pgfPjGzM_f0dYlbAI4kq8ljVvQ0LX1RdcsTivFPV&itag=171&source=youtube&requiressl=yes&mm=31%2C29&mn=sn-5aapxquxaxjvh-p5qe%2Csn-p5qs7n7e&ms=au%2Crdu&mv=m&mvi=2&pl=20&initcwndbps=1252500&mime=audio%2Fwebm&gir=yes&clen=1671555&dur=102.929&lmt=1559550315664049&mt=1562080584&fvip=3&keepalive=yes&c=WEB&txp=5531432&sparams=expire%2Cei%2Cip%2Cid%2Citag%2Csource%2Crequiressl%2Cmime%2Cgir%2Cclen%2Cdur%2Clmt&sig=ALgxI2wwRQIgLKxgnDmzVwWd9w3s51bFKzAy0CCdTspdhv0PcSQK-5ACIQCRYQWoboJTU9PtChvn02-tWBOjkor0JHNwu-UDG1I0jw%3D%3D&lsparams=mm%2Cmn%2Cms%2Cmv%2Cmvi%2Cpl%2Cinitcwndbps&lsig=AHylml4wRQIhAKmfnwS_dcIMrapCFNs4DYQqRspMTFKcExW_tJ4ORmL7AiBsfQiRa-YjkkDg6xWla-W2Pl0VWtMefpyLkK2e5E3Rzg%3D%3D&ratebypass=yes", "player_url": "/yts/jsbin/player_ias-vflxACNZ2/en_US/base.js", "ext": "webm", "acodec": "vorbis", "format_note": "DASH audio", "abr": 128, "filesize": 1671555, "tbr": 142.703, "quality": -1, "vcodec": "none", "downloader_options": {"http_chunk_size": 10485760}, "format": "171 - audio only (DASH audio)", "protocol": "https", "http_headers": {"User-Agent": "Mozilla/5.0 (X11; Linux x86_64; rv:59.0) Gecko/20100101 Firefox/59.0", "Accept-Charset": "ISO-8859-1,utf-8;q=0.7,*;q=0.7", "Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8", "Accept-Encoding": "gzip, deflate", "Accept-Language": "en-us,en;q=0.5"}}, {"format_id": "251", "url": "https://r3---sn-5aapxquxaxjvh-p5qe.googlevideo.com/videoplayback?expire=1562102345&ei=6XUbXdrLIq6shwaojLuIAg&ip=205.201.245.3&id=o-AJr4pgfPjGzM_f0dYlbAI4kq8ljVvQ0LX1RdcsTivFPV&itag=251&source=youtube&requiressl=yes&mm=31%2C29&mn=sn-5aapxquxaxjvh-p5qe%2Csn-p5qs7n7e&ms=au%2Crdu&mv=m&mvi=2&pl=20&initcwndbps=1252500&mime=audio%2Fwebm&gir=yes&clen=1710085&dur=102.961&lmt=1559550315663826&mt=1562080584&fvip=3&keepalive=yes&c=WEB&txp=5531432&sparams=expire%2Cei%2Cip%2Cid%2Citag%2Csource%2Crequiressl%2Cmime%2Cgir%2Cclen%2Cdur%2Clmt&sig=ALgxI2wwRQIhAMME64zEj8EghuSDrqRk8JvT8pldDEugH-RV5X3U-VmOAiBa4Q1YZ5v3Kfbn9pY2jstCIlbnTfeCoWa5mVAOy-7eYw%3D%3D&lsparams=mm%2Cmn%2Cms%2Cmv%2Cmvi%2Cpl%2Cinitcwndbps&lsig=AHylml4wRQIhAKmfnwS_dcIMrapCFNs4DYQqRspMTFKcExW_tJ4ORmL7AiBsfQiRa-YjkkDg6xWla-W2Pl0VWtMefpyLkK2e5E3Rzg%3D%3D&ratebypass=yes", "player_url": "/yts/jsbin/player_ias-vflxACNZ2/en_US/base.js", "ext": "webm", "format_note": "DASH audio", "acodec": "opus", "abr": 160, "filesize": 1710085, "tbr": 142.97, "quality": -1, "vcodec": "none", "downloader_options": {"http_chunk_size": 10485760}, "format": "251 - audio only (DASH audio)", "protocol": "https", "http_headers": {"User-Agent": "Mozilla/5.0 (X11; Linux x86_64; rv:59.0) Gecko/20100101 Firefox/59.0", "Accept-Charset": "ISO-8859-1,utf-8;q=0.7,*;q=0.7", "Accept": "text/html,application/xhtml+xx...},
]

我知道我可以使用gc nosql.db | select -tail 1使用PowerShell快速检索大文件的最后几行,但是有没有办法在尾部上方插入一行而不读取和写入整个文件?

已更新

这是我的脚本,使用正确的答案进行了更新:

Write-Host "Searching for and downloading videos . . . "
if(![System.IO.File]::Exists('.\database.js')){
    Set-Content -Path .\database.js -Value "const database = [
]"
}
$PSDefaultParameterValues['Out-File:Encoding'] = 'utf8'
youtube-dl.exe --config-location config.txt --print-json | foreach {
    $stream = [IO.File]::OpenWrite('.\database.js')
    $stream.SetLength($stream.Length - 4)
    $stream.Close()
    $stream.Dispose()

    $_ + ",
]" | Add-Content .\database.js
}
Read-Host -Prompt "Done, press Enter to exit"

1 个答案:

答案 0 :(得分:1)

试试吧:

// format of ImageString is DLL;Relative Path. 
this.Dispatcher.BeginInvoke(() =>
{
   // UserControl Details = new EIL005020307("/SolutionName;component/Images/" + staticImage);
    UserControl Details = new EIL005151217("/SolutionName;component/Images/" + staticImage);
    AddItemToItemControl(Details);
});
Thread.Sleep(5);

我删除最后一行“]”,然后添加新内容以及“]”。

希望有帮助! BR