Finished cleanup
This commit is contained in:
@@ -191,4 +191,4 @@ if __name__ == '__main__':
|
||||
screenshot()
|
||||
pixelate()
|
||||
lock()
|
||||
log(start_time)
|
||||
# log(start_time)
|
||||
|
||||
@@ -1,93 +0,0 @@
|
||||
/* ______ _________ _______ _______ _ _______ _________ _______ _______ _______
|
||||
* ( __ \ \__ __/( ____ \( ____ \( \ ( ___ )\__ __/( )( ____ \( ____ )
|
||||
* | ( \ ) ) ( | ( \/| ( \/| ( | ( ) | ) ( | () () || ( \/| ( )|
|
||||
* | | ) | | | | (_____ | | | | | (___) | | | | || || || (__ | (____)|
|
||||
* | | | | | | (_____ )| | | | | ___ | | | | |(_)| || __) | __)
|
||||
* | | ) | | | ) || | | | | ( ) | | | | | | || ( | (\ (
|
||||
* | (__/ )___) (___/\____) || (____/\| (____/\| ) ( |___) (___| ) ( || (____/\| ) \ \__
|
||||
* (______/ \_______/\_______)(_______/(_______/|/ \|\_______/|/ \|(_______/|/ \__/
|
||||
*
|
||||
*
|
||||
* THIS IS GARBAGE CODE AND I KNOW IT.
|
||||
* I KNOW ABSOLUTLY NOTHING ABOUT C++ AND JUST FRANKENSTEINED
|
||||
* A BUNCH OF CODE SAMPLES, USING MY PYTHON CODE AS A TEMPLATE.
|
||||
*/
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <unistd.h>
|
||||
#include <pwd.h>
|
||||
#include <dirent.h>
|
||||
#include <errno.h>
|
||||
#include <vector>
|
||||
#include <string>
|
||||
#include <fstream>
|
||||
#include <iostream>
|
||||
|
||||
using namespace std;
|
||||
|
||||
int getdir(string dir, vector<string> &files){
|
||||
DIR *dp;
|
||||
struct dirent *dirp;
|
||||
if((dp = opendir(dir.c_str())) == NULL){
|
||||
cout << "Error(" << errno << ") opening " << dir << endl;
|
||||
return errno;
|
||||
}
|
||||
|
||||
while ((dirp = readdir(dp)) != NULL){
|
||||
files.push_back(string(dirp->d_name));
|
||||
}
|
||||
closedir(dp);
|
||||
return 0;
|
||||
}
|
||||
|
||||
string getfile(string file_path){
|
||||
ifstream inFile;
|
||||
string file_content;
|
||||
inFile.open(file_path);
|
||||
if(!inFile){
|
||||
return "";
|
||||
}
|
||||
inFile >> file_content;
|
||||
return file_content;
|
||||
}
|
||||
|
||||
bool spotify_running(){
|
||||
string dir = string("/proc/");
|
||||
vector<string> processes = vector<string>();
|
||||
getdir(dir, processes);
|
||||
string proc_name = string("");
|
||||
for (unsigned int i = 0; i < procs.size(); i++){
|
||||
proc_name = dir + procs[i] + "/cmdline";
|
||||
if(getfile(proc_name).find(string("/usr/bin/spotify")) != string::npos){
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
int main(){
|
||||
//
|
||||
struct passwd *pw = getpwuid(getuid());
|
||||
const char *homedir = pw->pw_dir;
|
||||
int state = -1;
|
||||
int playstate = 0;
|
||||
string playstate_file = "";
|
||||
playstate_file += homedir + string("/.scripts/playstate");
|
||||
while (spotify_running()){
|
||||
usleep(100000);
|
||||
// cout << spotify_running() << endl;
|
||||
playstate = stoi(getfile(playstate_file));
|
||||
if(playstate != state){
|
||||
state = playstate;
|
||||
if (state == 0){
|
||||
cout << "" << endl;
|
||||
system("playerctl pause");
|
||||
}
|
||||
else if (state == 1){
|
||||
cout << "" << endl;
|
||||
system("playerctl play");
|
||||
}
|
||||
}
|
||||
}
|
||||
cout << endl;
|
||||
}
|
||||
Binary file not shown.
@@ -1,47 +0,0 @@
|
||||
#!/usr/bin/python
|
||||
import subprocess
|
||||
import time
|
||||
import os
|
||||
|
||||
|
||||
def find_proc(proc_name):
|
||||
this_proc = "pythonspotify-play.py"
|
||||
proc_path = '/proc'
|
||||
proc = next(os.walk('{}/'.format(proc_path)))[1]
|
||||
for process in proc:
|
||||
cmdline_path = '{}/{}/cmdline'.format(proc_path,process)
|
||||
try:
|
||||
with open(cmdline_path, 'r') as cmd:
|
||||
proc_content = cmd.readline()
|
||||
if (proc_name in proc_content):
|
||||
return True
|
||||
except FileNotFoundError:
|
||||
pass
|
||||
return False
|
||||
|
||||
|
||||
def spotify_running():
|
||||
return find_proc('/usr/bin/spotify')
|
||||
|
||||
|
||||
def main():
|
||||
state = -1
|
||||
home = os.path.expanduser("~")
|
||||
while spotify_running():
|
||||
with open(home + '/.scripts/playstate', 'r') as f:
|
||||
try:
|
||||
file_state = int(f.readline().strip('\n'))
|
||||
except ValueError:
|
||||
pass
|
||||
if state != file_state:
|
||||
state = file_state
|
||||
if state == 0:
|
||||
print("")
|
||||
subprocess.run(["playerctl","pause"])
|
||||
elif state == 1:
|
||||
print("")
|
||||
subprocess.run(["playerctl","play"])
|
||||
time.sleep(0.1)
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
Reference in New Issue
Block a user