forked from inteoryx/twitter-video-dl
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
👍Support for saving videos via browser extension
- Addition of browser extension (twitter-video-dl-send) - Add video storage server (twitter-video-dl-server.py) Closes: #11
- Loading branch information
1 parent
f96d8f7
commit 6bdd7b0
Showing
12 changed files
with
224 additions
and
11 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
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,8 @@ | ||
function sendUrl(url, fileName) { | ||
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); | ||
} | ||
}); |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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,22 @@ | ||
{ | ||
"manifest_version": 2, | ||
"name": "twitter-video-dl-send", | ||
"version": "0.0.1", | ||
"author": "7rikaz_h785 <7rikaz.h785.stat2ltas41lcijad@gmail.com>", | ||
"homepage_url": "https://github.com/7rikazhexde/twitter-video-dl-for-sc", | ||
"permissions": ["activeTab", "http://localhost:3000/"], | ||
"background": { | ||
"scripts": ["background.js"], | ||
"persistent": false | ||
}, | ||
"browser_action": { | ||
"default_popup": "popup.html", | ||
"default_width": 400, | ||
"default_height": 200 | ||
}, | ||
"icons": { | ||
"16": "images/icon16.png", | ||
"48": "images/icon48.png", | ||
"128": "images/icon128.png" | ||
} | ||
} |
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,43 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<meta charset="UTF-8"> | ||
<style> | ||
body { | ||
font-family: Arial, sans-serif; | ||
width: 450px; | ||
} | ||
#fileNameInput, #urlInput, #languageSelect { | ||
width: 100%; | ||
padding: 12px 20px; | ||
margin: 8px 0; | ||
box-sizing: border-box; | ||
} | ||
#sendCurrentUrl, #sendInputUrl { | ||
background-color: #2a4fc9; | ||
color: white; | ||
padding: 14px 20px; | ||
margin: 8px 0; | ||
border: none; | ||
border-radius: 12px; | ||
cursor: pointer; | ||
width: 100%; | ||
} | ||
#sendCurrentUrl:hover, #sendInputUrl:hover { | ||
background-color: #2a4fc9; | ||
} | ||
</style> | ||
</head> | ||
<body> | ||
<h1 id="title"></h1> | ||
<select id="languageSelect"> | ||
<option value="en">English</option> | ||
<option value="ja">日本語</option> | ||
</select> | ||
<input type="text" id="fileNameInput" placeholder=""> | ||
<button id="sendCurrentUrl"></button> | ||
<input type="text" id="urlInput" placeholder=""> | ||
<button id="sendInputUrl"></button> | ||
<script src="popup.js"></script> | ||
</body> | ||
</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,72 @@ | ||
const languageSelect = document.getElementById('languageSelect'); | ||
const sendCurrentUrlButton = document.getElementById('sendCurrentUrl'); | ||
const sendInputUrlButton = document.getElementById('sendInputUrl'); | ||
const fileNameInput = document.getElementById('fileNameInput'); | ||
const urlInput = document.getElementById('urlInput'); | ||
const title = document.getElementById('title'); | ||
|
||
const text = { | ||
en: { | ||
title: 'twitter-video-dl-send', | ||
fileNamePlaceholder: 'Enter file name', | ||
sendCurrentUrl: 'Send current URL', | ||
sendInputUrl: 'Send the URL you entered', | ||
urlPlaceholder: 'Enter URL', | ||
sent: 'Sent', | ||
}, | ||
ja: { | ||
title: 'twitter-video-dl-send', | ||
fileNamePlaceholder: 'ファイル名を入力', | ||
sendCurrentUrl: '現在のURLを送信', | ||
sendInputUrl: '入力したURLを送信', | ||
urlPlaceholder: 'URLを入力', | ||
sent: '送信済み', | ||
}, | ||
}; | ||
|
||
function updateLanguage() { | ||
const lang = languageSelect.value; | ||
localStorage.setItem('language', lang); | ||
title.innerText = text[lang].title; | ||
fileNameInput.placeholder = text[lang].fileNamePlaceholder; | ||
sendCurrentUrlButton.innerText = text[lang].sendCurrentUrl; | ||
sendInputUrlButton.innerText = text[lang].sendInputUrl; | ||
urlInput.placeholder = text[lang].urlPlaceholder; | ||
} | ||
|
||
languageSelect.addEventListener('change', updateLanguage); | ||
|
||
window.addEventListener('DOMContentLoaded', () => { | ||
const savedLanguage = localStorage.getItem('language') || 'en'; | ||
languageSelect.value = savedLanguage; | ||
updateLanguage(); | ||
}); | ||
|
||
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}); | ||
}); | ||
this.style.backgroundColor = '#888888'; | ||
this.innerText = text[languageSelect.value].sent; | ||
setTimeout(() => { | ||
this.style.backgroundColor = '#2a4fc9'; | ||
this.innerText = text[languageSelect.value].sendCurrentUrl; | ||
}, 2000); | ||
}); | ||
|
||
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}); | ||
this.style.backgroundColor = '#888888'; | ||
this.innerText = text[languageSelect.value].sent; | ||
setTimeout(() => { | ||
this.style.backgroundColor = '#2a4fc9'; | ||
this.innerText = text[languageSelect.value].sendInputUrl; | ||
}, 2000); | ||
} else { | ||
alert('URLを入力してください'); | ||
} | ||
}); |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
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
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,41 @@ | ||
from http.server import BaseHTTPRequestHandler, HTTPServer | ||
from urllib.parse import parse_qs, urlparse | ||
|
||
import src.twitter_video_dl.twitter_video_dl as tvdl | ||
|
||
DCEBUG_MODE = False | ||
|
||
|
||
class RequestHandler(BaseHTTPRequestHandler): | ||
def do_GET(self): | ||
query = urlparse(self.path).query | ||
params = parse_qs(query) | ||
url = params.get("url", [""])[0] | ||
fileName = params.get("fileName", [""])[0] | ||
if url: | ||
tvdl.download_video_for_sc(url, fileName) | ||
self.send_response(200) | ||
self.send_header("Content-type", "text/html") | ||
self.end_headers() | ||
self.wfile.write(b"URL received") | ||
else: | ||
self.send_response(200) | ||
self.send_header("Content-type", "text/html") | ||
self.end_headers() | ||
self.wfile.write(b"No URL received") | ||
|
||
def log_message(self, format, *args): | ||
if DCEBUG_MODE: | ||
# Display log only when debug mode is True. | ||
super().log_message(format, *args) | ||
|
||
|
||
def run(server_class=HTTPServer, handler_class=RequestHandler, port=3000): | ||
server_address = ("", port) | ||
httpd = server_class(server_address, handler_class) | ||
print(f"Starting server on port {port}") | ||
httpd.serve_forever() | ||
|
||
|
||
if __name__ == "__main__": | ||
run() |