Created
September 2, 2015 23:09
-
-
Save hemebond/fa37adf4ddb96a737579 to your computer and use it in GitHub Desktop.
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
#!/usr/bin/python3 | |
# | |
# Save Flash videos on Linux when using Mozilla Firefox | |
# | |
# When watching Flash videos in Mozilla Firefox using the Adobe Flash player a | |
# temporary but "deleted" file is created. This file can still be accessed and | |
# copied somewhere else. This script will find all the temporary video files | |
# and save them to the current directory. | |
# | |
import os | |
import re | |
import shutil | |
import psutil | |
from pathlib import Path | |
def find_flash_process(): | |
""" | |
Returns the flash plugin process ID | |
""" | |
for pid in psutil.pids(): | |
p = psutil.Process(pid) | |
try: | |
cmdline = p.cmdline() | |
except: | |
continue | |
if "plugin-container" in cmdline[0]: | |
if "libflashplayer.so" in cmdline[1]: | |
return pid | |
return None | |
def main(): | |
""" | |
Finds the flash plugin process | |
Finds symlinks to the (deleted) flash videos | |
Copies the videos to the script directory | |
""" | |
pid = find_flash_process() | |
pid_dir = Path("/proc/{0}/fd".format(pid)) | |
for item in pid_dir.iterdir(): | |
if item.is_symlink(): | |
src = str(item.absolute()) | |
link_target = os.readlink(src) | |
if "/tmp/Flash" in link_target: | |
string_match = re.search("Flash\S+", link_target) | |
if string_match: | |
flash_name = string_match.group() | |
dst = os.path.join(os.path.dirname(os.path.realpath(__file__)), "{0}.flv".format(flash_name)) | |
print("Copying {0} to {1}".format(src, dst)) | |
shutil.copy(src, dst) | |
if __name__ == "__main__": | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment