diff --git a/browser_extension/twitter-video-dl-send/background.js b/browser_extension/twitter-video-dl-send/background.js index a2ddf9b..1f7b045 100644 --- a/browser_extension/twitter-video-dl-send/background.js +++ b/browser_extension/twitter-video-dl-send/background.js @@ -1,8 +1,17 @@ -function sendUrl(url, fileName) { - fetch(`http://localhost:3000/?url=${encodeURIComponent(url)}&fileName=${encodeURIComponent(fileName)}`); +let lastError = null; + +async function sendUrl(url, fileName) { + await fetch(`http://localhost:3000/?url=${encodeURIComponent(url)}&fileName=${encodeURIComponent(fileName)}`); } + chrome.runtime.onMessage.addListener((request, sender, sendResponse) => { if (request.action === "sendUrl") { - sendUrl(request.url, request.fileName); + sendUrl(request.url, request.fileName).catch((error) => { + console.log(error); + lastError = error.message; + }); + } else if (request.action === "getLastError") { + sendResponse({error: lastError}); + lastError = null; } }); diff --git a/browser_extension/twitter-video-dl-send/manifest.json b/browser_extension/twitter-video-dl-send/manifest.json index 05da091..c07cd03 100644 --- a/browser_extension/twitter-video-dl-send/manifest.json +++ b/browser_extension/twitter-video-dl-send/manifest.json @@ -1,22 +1,22 @@ { - "manifest_version": 2, + "manifest_version": 3, "name": "twitter-video-dl-send", - "version": "0.0.1", + "version": "0.0.2", "author": "7rikaz_h785 <7rikaz.h785.stat2ltas41lcijad@gmail.com>", "homepage_url": "https://github.com/7rikazhexde/twitter-video-dl-for-sc", - "permissions": ["activeTab", "http://localhost:3000/"], + "permissions": ["activeTab"], + "host_permissions": ["http://localhost:3000/"], "background": { - "scripts": ["background.js"], - "persistent": false + "service_worker": "background.js" }, - "browser_action": { + "action": { "default_popup": "popup.html", "default_width": 400, "default_height": 200 }, - "icons": { - "16": "images/icon16.png", - "48": "images/icon48.png", - "128": "images/icon128.png" - } + "icons": { + "16": "images/icon16.png", + "48": "images/icon48.png", + "128": "images/icon128.png" + } } diff --git a/browser_extension/twitter-video-dl-send/popup.js b/browser_extension/twitter-video-dl-send/popup.js index df8a29c..7b90256 100644 --- a/browser_extension/twitter-video-dl-send/popup.js +++ b/browser_extension/twitter-video-dl-send/popup.js @@ -45,7 +45,14 @@ window.addEventListener('DOMContentLoaded', () => { document.getElementById('sendCurrentUrl').addEventListener('click', function() { const fileName = document.getElementById('fileNameInput').value; chrome.tabs.query({active: true, currentWindow: true}, tabs => { - chrome.runtime.sendMessage({action: "sendUrl", url: tabs[0].url, fileName: fileName}); + chrome.runtime.sendMessage({action: "sendUrl", url: tabs[0].url, fileName: fileName}).catch((error) => { + console.log(error); + chrome.runtime.sendMessage({action: "getLastError"}, response => { + if (response.error) { + alert(response.error); + } + }); + }); }); this.style.backgroundColor = '#888888'; this.innerText = text[languageSelect.value].sent; @@ -59,7 +66,14 @@ document.getElementById('sendInputUrl').addEventListener('click', function() { const url = document.getElementById('urlInput').value; const fileName = document.getElementById('fileNameInput').value; if (url) { - chrome.runtime.sendMessage({action: "sendUrl", url: url, fileName: fileName}); + chrome.runtime.sendMessage({action: "sendUrl", url: url, fileName: fileName}).catch((error) => { + console.log(error); + chrome.runtime.sendMessage({action: "getLastError"}, response => { + if (response.error) { + alert(response.error); + } + }); + }); this.style.backgroundColor = '#888888'; this.innerText = text[languageSelect.value].sent; setTimeout(() => { diff --git a/poetry.lock b/poetry.lock index 6c27334..b312acc 100644 --- a/poetry.lock +++ b/poetry.lock @@ -265,6 +265,20 @@ files = [ {file = "distlib-0.3.8.tar.gz", hash = "sha256:1530ea13e350031b6312d8580ddb6b27a104275a31106523b8f123787f494f64"}, ] +[[package]] +name = "execnet" +version = "2.0.2" +description = "execnet: rapid multi-Python deployment" +optional = false +python-versions = ">=3.7" +files = [ + {file = "execnet-2.0.2-py3-none-any.whl", hash = "sha256:88256416ae766bc9e8895c76a87928c0012183da3cc4fc18016e6f050e025f41"}, + {file = "execnet-2.0.2.tar.gz", hash = "sha256:cc59bc4423742fd71ad227122eb0dd44db51efb3dc4095b45ac9a08c770096af"}, +] + +[package.extras] +testing = ["hatch", "pre-commit", "pytest", "tox"] + [[package]] name = "ffmpeg-python" version = "0.2.0" @@ -433,13 +447,13 @@ files = [ [[package]] name = "mslex" -version = "1.1.0" +version = "1.2.0" description = "shlex for windows" optional = false python-versions = ">=3.5" files = [ - {file = "mslex-1.1.0-py2.py3-none-any.whl", hash = "sha256:8826f4bb8d8c63402203d921dc8c2df0c7fec0d9c91d020ddf02fc9d0dce81bd"}, - {file = "mslex-1.1.0.tar.gz", hash = "sha256:7fe305fbdc9721283875e0b737fdb344374b761338a7f41af91875de278568e4"}, + {file = "mslex-1.2.0-py3-none-any.whl", hash = "sha256:c68ec637485ee3544c5847c1b4e78b02940b32708568fb1d8715491815aa2341"}, + {file = "mslex-1.2.0.tar.gz", hash = "sha256:79e2abc5a129dd71cdde58a22a2039abb7fa8afcbac498b723ba6e9b9fbacc14"}, ] [[package]] @@ -657,6 +671,26 @@ pytest = ">=5.0" [package.extras] dev = ["pre-commit", "pytest-asyncio", "tox"] +[[package]] +name = "pytest-xdist" +version = "3.5.0" +description = "pytest xdist plugin for distributed testing, most importantly across multiple CPUs" +optional = false +python-versions = ">=3.7" +files = [ + {file = "pytest-xdist-3.5.0.tar.gz", hash = "sha256:cbb36f3d67e0c478baa57fa4edc8843887e0f6cfc42d677530a36d7472b32d8a"}, + {file = "pytest_xdist-3.5.0-py3-none-any.whl", hash = "sha256:d075629c7e00b611df89f490a5063944bee7a4362a5ff11c7cc7824a03dfce24"}, +] + +[package.dependencies] +execnet = ">=1.1" +pytest = ">=6.2.0" + +[package.extras] +psutil = ["psutil (>=3.0)"] +setproctitle = ["setproctitle"] +testing = ["filelock"] + [[package]] name = "pyyaml" version = "6.0.1" @@ -799,13 +833,13 @@ files = [ [[package]] name = "tomlkit" -version = "0.12.3" +version = "0.12.4" description = "Style preserving TOML library" optional = false python-versions = ">=3.7" files = [ - {file = "tomlkit-0.12.3-py3-none-any.whl", hash = "sha256:b0a645a9156dc7cb5d3a1f0d4bab66db287fcb8e0430bdd4664a095ea16414ba"}, - {file = "tomlkit-0.12.3.tar.gz", hash = "sha256:75baf5012d06501f07bee5bf8e801b9f343e7aac5a92581f20f80ce632e6b5a4"}, + {file = "tomlkit-0.12.4-py3-none-any.whl", hash = "sha256:5cd82d48a3dd89dee1f9d64420aa20ae65cfbd00668d6f094d7578a78efbb77b"}, + {file = "tomlkit-0.12.4.tar.gz", hash = "sha256:7ca1cfc12232806517a8515047ba66a19369e71edf2439d0f5824f91032b6cc3"}, ] [[package]] @@ -848,4 +882,4 @@ test = ["covdefaults (>=2.3)", "coverage (>=7.2.7)", "coverage-enable-subprocess [metadata] lock-version = "2.0" python-versions = "^3.11.0" -content-hash = "7a82eef4f5c46d4aaa3674c60afe4181cb7b30301bec981c8a9028a9905757a7" +content-hash = "e3f8bf50daac5b0b2c7b565675d12635a4f7be8de23559d9039d4b7898898fe2" diff --git a/pyproject.toml b/pyproject.toml index cb9425b..45bd911 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,7 +4,7 @@ description = "This project is based on the original code of the [inteoryx / twi license = "Unlicense" name = "twitter-video-dl-for-sc" readme = "README.md" -version = "0.2.8" +version = "0.2.9" [tool.poetry.dependencies] python = "^3.11.0" @@ -21,6 +21,7 @@ pytest = "^7.4.3" pytest-mock = "^3.12.0" pytest-cov = "^4.1.0" pytest-html = "^4.1.1" +pytest-xdist = "^3.5.0" [tool.taskipy.tasks] # poetry run task [task] diff --git a/requirements-dev.txt b/requirements-dev.txt index b7ba611..cc38596 100644 --- a/requirements-dev.txt +++ b/requirements-dev.txt @@ -180,6 +180,9 @@ coverage[toml]==7.4.3 ; python_full_version >= "3.11.0" and python_full_version distlib==0.3.8 ; python_full_version >= "3.11.0" and python_full_version < "4.0.0" \ --hash=sha256:034db59a0b96f8ca18035f36290806a9a6e6bd9d1ff91e45a7f172eb17e51784 \ --hash=sha256:1530ea13e350031b6312d8580ddb6b27a104275a31106523b8f123787f494f64 +execnet==2.0.2 ; python_full_version >= "3.11.0" and python_full_version < "4.0.0" \ + --hash=sha256:88256416ae766bc9e8895c76a87928c0012183da3cc4fc18016e6f050e025f41 \ + --hash=sha256:cc59bc4423742fd71ad227122eb0dd44db51efb3dc4095b45ac9a08c770096af ffmpeg-python==0.2.0 ; python_full_version >= "3.11.0" and python_full_version < "4.0.0" \ --hash=sha256:65225db34627c578ef0e11c8b1eb528bb35e024752f6f10b78c011f6f64c4127 \ --hash=sha256:ac441a0404e053f8b6a1113a77c0f452f1cfc62f6344a769475ffdc0f56c23c5 @@ -262,9 +265,9 @@ markupsafe==2.1.5 ; python_full_version >= "3.11.0" and python_full_version < "4 --hash=sha256:fa9db3f79de01457b03d4f01b34cf91bc0048eb2c3846ff26f66687c2f6d16ab \ --hash=sha256:fce659a462a1be54d2ffcacea5e3ba2d74daa74f30f5f143fe0c58636e355fdd \ --hash=sha256:ffee1f21e5ef0d712f9033568f8344d5da8cc2869dbd08d87c84656e6a2d2f68 -mslex==1.1.0 ; python_full_version >= "3.11.0" and python_version < "4.0" and sys_platform == "win32" \ - --hash=sha256:7fe305fbdc9721283875e0b737fdb344374b761338a7f41af91875de278568e4 \ - --hash=sha256:8826f4bb8d8c63402203d921dc8c2df0c7fec0d9c91d020ddf02fc9d0dce81bd +mslex==1.2.0 ; python_full_version >= "3.11.0" and python_version < "4.0" and sys_platform == "win32" \ + --hash=sha256:79e2abc5a129dd71cdde58a22a2039abb7fa8afcbac498b723ba6e9b9fbacc14 \ + --hash=sha256:c68ec637485ee3544c5847c1b4e78b02940b32708568fb1d8715491815aa2341 mypy-extensions==1.0.0 ; python_full_version >= "3.11.0" and python_full_version < "4.0.0" \ --hash=sha256:4392f6c0eb8a5668a69e23d168ffa70f0be9ccfd32b5cc2d26a34ae5b844552d \ --hash=sha256:75dbf8955dc00442a438fc4d0666508a9a97b6bd41aa2f0ffe9d2f2725af0782 @@ -315,6 +318,9 @@ pytest-metadata==3.1.1 ; python_full_version >= "3.11.0" and python_full_version pytest-mock==3.12.0 ; python_full_version >= "3.11.0" and python_full_version < "4.0.0" \ --hash=sha256:0972719a7263072da3a21c7f4773069bcc7486027d7e8e1f81d98a47e701bc4f \ --hash=sha256:31a40f038c22cad32287bb43932054451ff5583ff094bca6f675df2f8bc1a6e9 +pytest-xdist==3.5.0 ; python_full_version >= "3.11.0" and python_full_version < "4.0.0" \ + --hash=sha256:cbb36f3d67e0c478baa57fa4edc8843887e0f6cfc42d677530a36d7472b32d8a \ + --hash=sha256:d075629c7e00b611df89f490a5063944bee7a4362a5ff11c7cc7824a03dfce24 pytest==7.4.4 ; python_full_version >= "3.11.0" and python_full_version < "4.0.0" \ --hash=sha256:2cf0005922c6ace4a3e2ec8b4080eb0d9753fdc93107415332f50ce9e7994280 \ --hash=sha256:b090cdf5ed60bf4c45261be03239c2c1c22df034fbffe691abe93cd80cea01d8 @@ -389,9 +395,9 @@ taskipy==1.12.2 ; python_full_version >= "3.11.0" and python_version < "4.0" \ tomli==2.0.1 ; python_full_version >= "3.11.0" and python_version < "4.0" \ --hash=sha256:939de3e7a6161af0c887ef91b7d41a53e7c5a1ca976325f429cb46ea9bc30ecc \ --hash=sha256:de526c12914f0c550d15924c62d72abc48d6fe7364aa87328337a31007fe8a4f -tomlkit==0.12.3 ; python_full_version >= "3.11.0" and python_full_version < "4.0.0" \ - --hash=sha256:75baf5012d06501f07bee5bf8e801b9f343e7aac5a92581f20f80ce632e6b5a4 \ - --hash=sha256:b0a645a9156dc7cb5d3a1f0d4bab66db287fcb8e0430bdd4664a095ea16414ba +tomlkit==0.12.4 ; python_full_version >= "3.11.0" and python_full_version < "4.0.0" \ + --hash=sha256:5cd82d48a3dd89dee1f9d64420aa20ae65cfbd00668d6f094d7578a78efbb77b \ + --hash=sha256:7ca1cfc12232806517a8515047ba66a19369e71edf2439d0f5824f91032b6cc3 urllib3==2.2.1 ; python_full_version >= "3.11.0" and python_full_version < "4.0.0" \ --hash=sha256:450b20ec296a467077128bff42b73080516e71b56ff59a60a02bef2232c4fa9d \ --hash=sha256:d0570876c61ab9e520d776c38acbbb5b05a776d3f9ff98a5c8fd5162a444cf19 diff --git a/twitter-video-dl-server.py b/twitter-video-dl-server.py index acd9f0d..8231ab3 100644 --- a/twitter-video-dl-server.py +++ b/twitter-video-dl-server.py @@ -13,6 +13,7 @@ def do_GET(self): url = params.get("url", [""])[0] fileName = params.get("fileName", [""])[0] if url: + fileName = fileName.replace(" ", "_").replace(" ", "_").replace("/", "-") tvdl.download_video_for_sc(url, fileName) self.send_response(200) self.send_header("Content-type", "text/html")