summaryrefslogtreecommitdiff
path: root/urlopen.py
blob: 2c2b8da049622235ee0ce1a97c713b44a7713c28 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#!/usr/bin/env python2.7
import sys, os;
from urlparse import urlparse;
def run(process, arg):
    L = [];
    for each in process:
        L.append(each);
    L.append(arg);
    os.spawnvpe(os.P_NOWAIT, L[0], L, os.environ)

def main(args):
    images = ["jpg", "png"]; imageapp = ["feh"];
    videos = ["gif", "gifv", "webm", "mp4"]; videoapp = ["mpv", "--loop"];
    videourls = ["youtube.com", "youtu.be", "streamable.com"];
    pdf = ["pdf"]; pdfapp = ["mupdf"];
    defaultapp = ["/home/daniel_j/compiled/waterfox/waterfox"];
    defaultforcedurls = ["slack.com"]
    x = 0;
    for each in args:
        parsed_uri = urlparse(each);
        domain = '{uri.scheme}://{uri.netloc}/'.format(uri=parsed_uri);
        if (any (s in domain for s in defaultforcedurls)):
                print("running with forced default application {}".format(each));
                run(defaultapp, each);
        elif (each.endswith(tuple(images))):
                print("image {}".format(each));
                run(imageapp, each);
        elif (each.endswith(tuple(videos))):
                print("video {}".format(each));
                run(videoapp, each);
        elif (each.endswith(tuple(pdf))):
                print("pdf {}".format(each));
                run(pdfapp, each);
        elif (any(s in domain for s in videourls)):
                print("video {}".format(each));
                run(videoapp, each);
        else:
            print("running with default application {}".format(each));
            run(defaultapp, each);
        x += 1;

if __name__ == "__main__":
    if sys.argv > 0:
        main(sys.argv[1:]);