Browse Source

lazy update

John ShaggyTwoDope Jenkins 4 years ago
parent
commit
f0a810f73d
5 changed files with 257 additions and 1 deletions
  1. 174
    0
      8chan
  2. 1
    1
      convertvideosavitomkv
  3. 72
    0
      gamelauncher
  4. 10
    0
      markallread
  5. 0
    0
      osdmixer

+ 174
- 0
8chan View File

@@ -0,0 +1,174 @@
1
+#!/usr/bin/env python2
2
+"""Usage: dl.py [-s SUBJECT] [options] THREAD
3
+
4
+-d --directory SAVEPATH  Save images to a directory in SAVEPATH
5
+-s --subject SUBJECT     If set, don't ask for folder name, but directly save
6
+                         in SUBJECT. If not set 8changrab tries the subject
7
+                         of the thread, and asks otherwise.
8
+--workers=<num>          # of processes to spawn [default: 10]
9
+--original-names
10
+
11
+-h --help     Show this
12
+-v --version  Show version
13
+"""
14
+from __future__ import print_function
15
+import sys
16
+import os
17
+import urllib2
18
+import shutil
19
+from docopt import docopt
20
+from bs4 import BeautifulSoup
21
+from os.path import expanduser
22
+from multiprocessing import Pool
23
+from multiprocessing import Value
24
+
25
+VERSION = "8changrab 0.2"
26
+DEFAULT_SAVE_PATH = '{}/8chan'.format(expanduser("~"))
27
+
28
+def pretty_update_progress(current, total):
29
+    """Create a pretty progress bar by constantly updating one line"""
30
+    progress_bar_length = 40
31
+
32
+    percent_finished = current/float(total) # 0 -> 1
33
+
34
+    fillers = int(percent_finished * progress_bar_length)
35
+    empty_fillers = progress_bar_length - fillers
36
+
37
+    progress_bar = "["
38
+    progress_bar += fillers*"="
39
+    progress_bar += ">"
40
+    progress_bar += empty_fillers*" "
41
+    progress_bar += "]"
42
+
43
+    term = Terminal()
44
+    with term.location(x=0):
45
+        print("{} {}/{}".format(progress_bar, current, total), end="")
46
+    sys.stdout.flush()
47
+
48
+def simple_update_progress(current, total):
49
+    """Simple update progress"""
50
+    sys.stdout.write("|")
51
+    sys.stdout.flush()
52
+
53
+# Use dumb output on non-tty by default
54
+update_progress = simple_update_progress
55
+try:
56
+    # If available, use pretty terminal output
57
+    from blessings import Terminal
58
+    TERM = Terminal()
59
+    if TERM.is_a_tty:
60
+        update_progress = pretty_update_progress
61
+except ImportError: pass
62
+
63
+HDR = {'User-Agent': 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.11 (KHTML, like Gecko) Chrome/23.0.1271.64 Safari/537.11',
64
+       'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
65
+    }
66
+
67
+def download_image(link, filename):
68
+    """Download LINK to FILENAME if FILENAME doesn't already exist"""
69
+    if os.path.exists(filename):
70
+        return
71
+
72
+    try:
73
+        req = urllib2.Request(link, headers=HDR)
74
+        response = urllib2.urlopen(req)
75
+        with open(filename, "wb") as _file:
76
+            _file.write(response.read())
77
+            _file.close()
78
+    except KeyboardInterrupt:
79
+        # Remove unfinished download
80
+        os.remove(filename)
81
+
82
+def download_and_update_progress(image):
83
+    """Spawned as a separate process to download IMAGE"""
84
+    try:
85
+        link, filename = image
86
+        download_image(link, filename)
87
+        with COUNTER.get_lock():
88
+            COUNTER.value += 1
89
+            update_progress(COUNTER.value, TOTAL_COUNT.value)
90
+    except KeyboardInterrupt: pass
91
+
92
+def main(argv):
93
+    """Grabs images from an 8chan thread"""
94
+    args = docopt(__doc__, argv=argv[1:], version=VERSION)
95
+
96
+    url = args['THREAD']
97
+    savepath = args['--directory'] or DEFAULT_SAVE_PATH
98
+
99
+    if not "8ch.net" in url:
100
+        print("Not an 8chan URL")
101
+        return 1
102
+
103
+    if not os.path.exists(savepath):
104
+        os.makedirs(savepath)
105
+
106
+    req = urllib2.Request(url, headers=HDR)
107
+    page = urllib2.urlopen(req).read()
108
+    soup = BeautifulSoup(page)
109
+
110
+    if args['--subject']:
111
+        topic = args['--subject']
112
+    else:
113
+        subject = soup.find(attrs={"class": "subject"})
114
+        if subject:
115
+            topic = subject.string
116
+        else:
117
+            topic = raw_input('Please specify folder name: ')
118
+
119
+    workers = int(args['--workers'])
120
+
121
+    download_path = '{}/{}'.format(savepath, topic)
122
+
123
+    if not os.path.exists(download_path):
124
+        os.makedirs(download_path)
125
+
126
+    print("Downloading to {}".format(download_path))
127
+
128
+    fileinfos = soup.find_all(attrs={"class": "fileinfo"})
129
+
130
+    # Global values used in download_and_update_progress()
131
+    global TOTAL_COUNT
132
+    TOTAL_COUNT = Value('i', 0)
133
+    global COUNTER
134
+    COUNTER = Value('i', 0)
135
+
136
+    TOTAL_COUNT.value = len(fileinfos)
137
+
138
+    # Create a list of images to download
139
+    downloads = []
140
+    for fileinfo in fileinfos:
141
+	if args['--original-names']:
142
+		download_link = ""
143
+		save_name = ""
144
+		for link in fileinfo.find_all('a'):
145
+			download_link = link.get('href')
146
+		for sp in fileinfo.find_all('span', class_="postfilename"):
147
+			save_name = unicode(sp.string)
148
+		downloads.append((download_link,'%s/%s'%(download_path,save_name)))
149
+	else:
150
+		for link in fileinfo.find_all('a'):
151
+			download_link = link.get('href')
152
+			downloads.append((download_link,'%s/%s'%(download_path, link.string)))
153
+
154
+    # Use a pool of processes to download the images in the list
155
+    pool = Pool(workers)
156
+    p = pool.map_async(download_and_update_progress, downloads)
157
+
158
+    # Wait for downloads to complete
159
+    try:
160
+        # Wow. Python is great. I *ABSOLUTELY ADORE* python.
161
+        results = p.get(0xFFFF)
162
+    except KeyboardInterrupt:
163
+        print("Aborting")
164
+        pool.terminate()
165
+        pool.join()
166
+    else:
167
+        pool.close()
168
+        pool.join()
169
+    print()
170
+    return 0
171
+
172
+if __name__ == "__main__":
173
+    sys.exit(main(sys.argv))
174
+

convertvideosavitomp4 → convertvideosavitomkv View File

@@ -2,7 +2,7 @@
2 2
 
3 3
 #mkdir convert
4 4
 
5
-for f in *.avi; do ffmpeg -i "$f" "${f%.avi}.mp4"; done
5
+for f in *.avi; do ffmpeg -i "$f" "${f%.avi}.mkv"; done
6 6
 
7 7
 
8 8
 #find -name '*.avi' -exec ffmpeg -i {} {}.mp4 \;

+ 72
- 0
gamelauncher View File

@@ -0,0 +1,72 @@
1
+#!/usr/bin/env bash
2
+# AUTHOR:   shaggy
3
+# FILE:     gamelauncher.sh
4
+# ROLE:     TODO (some explanation)
5
+# CREATED:  2015-05-18 22:51:55
6
+# MODIFIED: 2015-05-18 22:51:56
7
+# A menu driven shell script sample template 
8
+## ----------------------------------
9
+# Step #1: Define variables
10
+# ----------------------------------
11
+EDITOR=vim
12
+PASSWD=/etc/passwd
13
+RED='\033[0;41;30m'
14
+STD='\033[0;0;39m'
15
+ 
16
+# ----------------------------------
17
+# Step #2: User defined function
18
+# ----------------------------------
19
+pause(){
20
+  read -p "Press [Enter] key to continue..." fackEnterKey
21
+}
22
+ 
23
+one(){
24
+	echo "one() called"
25
+        pause
26
+}
27
+ 
28
+# do something in two()
29
+two(){
30
+	echo "two() called"
31
+        pause
32
+}
33
+ 
34
+# function to display menus
35
+show_menus() {
36
+	clear
37
+	echo "~~~~~~~~~~~~~~~~~~~~~"	
38
+	echo " M A I N - M E N U"
39
+	echo "~~~~~~~~~~~~~~~~~~~~~"
40
+	echo "1. Set Terminal"
41
+	echo "2. Reset Terminal"
42
+	echo "3. Exit"
43
+}
44
+# read input from the keyboard and take a action
45
+# invoke the one() when the user select 1 from the menu option.
46
+# invoke the two() when the user select 2 from the menu option.
47
+# Exit when user the user select 3 form the menu option.
48
+read_options(){
49
+	local choice
50
+	read -p "Enter choice [ 1 - 3] " choice
51
+	case $choice in
52
+		1) one ;;
53
+		2) two ;;
54
+		3) exit 0;;
55
+		*) echo -e "${RED}Error...${STD}" && sleep 2
56
+	esac
57
+}
58
+ 
59
+# ----------------------------------------------
60
+# Step #3: Trap CTRL+C, CTRL+Z and quit singles
61
+# ----------------------------------------------
62
+trap '' SIGINT SIGQUIT SIGTSTP
63
+ 
64
+# -----------------------------------
65
+# Step #4: Main logic - infinite loop
66
+# ------------------------------------
67
+while true
68
+do
69
+ 
70
+	show_menus
71
+	read_options
72
+done

+ 10
- 0
markallread View File

@@ -0,0 +1,10 @@
1
+#!/bin/bash
2
+for i in `ls -1 ~/Maildir/*/*/new/*`
3
+do
4
+  mv $i `echo $i | sed -r "s/^(.*)\/new\/(.*)$/\1\/cur\/\2:2,S/"`
5
+done
6
+
7
+for i in `ls -1 ~/Maildir/*/*/cur/*:2, 2>/dev/null`
8
+do
9
+  mv $i `echo $i | sed -r "s/^(.*)$/\1S/"`
10
+done

osdmixer.sh → osdmixer View File


Loading…
Cancel
Save