Internet radio browser GUI for music/video streams from various directory services.

⌈⌋ branch:  streamtuner2


Check-in [4f285c3b31]

Overview
Comment:Allow to add custom statusmsg for lengthier HTTP requests.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: 4f285c3b313fb52db83c9cee132e211ff0227684
User & Date: mario on 2015-05-02 19:53:28
Other Links: manifest | tags
Context
2015-05-02
19:53
Use shorter entity_decode() call. Strip example content. check-in: 405eaaa660 user: mario tags: trunk
19:53
Allow to add custom statusmsg for lengthier HTTP requests. check-in: 4f285c3b31 user: mario tags: trunk
19:52
Move strip_tags(), entity_decode(), and nl() out of class into normal functions. check-in: 41c3273da9 user: mario tags: trunk
Changes

Modified ahttp.py from [4ef18dd32d] to [1ab0a64254].

29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63

  # use reset values if none given
  if not args:
     args = ["", 1.0]

  # send to main win
  if feedback:
    try: [feedback(d) for d in args]
    except: pass


# prepare default query object
session = requests.Session()
# default HTTP headers for requests
session.headers.update({
    "User-Agent": "streamtuner2/2.1 (X11; Linux amd64; rv:33.0) like WinAmp/2.1",
    "Accept": "*/*",
    "Accept-Language": "en-US,en,de,es,fr,it,*;q=0.1",
    "Accept-Encoding": "gzip, deflate",
    "Accept-Charset": "UTF-8, ISO-8859-1;q=0.5, *;q=0.1",
})


#-- Retrieve data via HTTP
#
#  Well, it says "get", but it actually does POST and AJAXish GET requests too.
#
def get(url, params={}, referer="", post=0, ajax=0, binary=0, feedback=None, content=True, verify=False):

    # statusbar info
    progress_feedback(url)
    
    # combine headers
    headers = {}
    if ajax:







|



















|







29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63

  # use reset values if none given
  if not args:
     args = ["", 1.0]

  # send to main win
  if feedback:
    try: [feedback(d, timeout=50) for d in args]
    except: pass


# prepare default query object
session = requests.Session()
# default HTTP headers for requests
session.headers.update({
    "User-Agent": "streamtuner2/2.1 (X11; Linux amd64; rv:33.0) like WinAmp/2.1",
    "Accept": "*/*",
    "Accept-Language": "en-US,en,de,es,fr,it,*;q=0.1",
    "Accept-Encoding": "gzip, deflate",
    "Accept-Charset": "UTF-8, ISO-8859-1;q=0.5, *;q=0.1",
})


#-- Retrieve data via HTTP
#
#  Well, it says "get", but it actually does POST and AJAXish GET requests too.
#
def get(url, params={}, referer="", post=0, ajax=0, binary=0, feedback=None, content=True, verify=False, statusmsg=None):

    # statusbar info
    progress_feedback(url)
    
    # combine headers
    headers = {}
    if ajax:
76
77
78
79
80
81
82
83
84
85
86
87
88

89
90
91
92
93




94
95
96
97
98
99
100
101
    else:    
        log.HTTP("GET"+(" AJAX" if ajax else ""), url, params )
        r = session.get(url, params=params, headers=headers, verify=verify, timeout=9.75)

    log.HTTP(">>>", r.request.headers );
    log.HTTP("<<<", r.headers );
            
    # finish, clean statusbar
    #progress_feedback(0.9)
    #progress_feedback("")

    # result
    log.INFO("Content-Length", len(r.content) )

    if not content:
        return r
    elif binary:
        return r.content
    else:




        return r.text


#-- Append missing trailing slash to URLs
def fix_url(url):
    if url is None:
        url = ""
    if len(url):







<
<
<
<


>



|

>
>
>
>
|







76
77
78
79
80
81
82




83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
    else:    
        log.HTTP("GET"+(" AJAX" if ajax else ""), url, params )
        r = session.get(url, params=params, headers=headers, verify=verify, timeout=9.75)

    log.HTTP(">>>", r.request.headers );
    log.HTTP("<<<", r.headers );
            




    # result
    log.INFO("Content-Length", len(r.content) )
    statusmsg and progress_feedback(statusmsg)
    if not content:
        return r
    elif binary:
        r = r.content
    else:
        # Receival is actually happening here
        r = r.text
    # clean statusbar
    statusmsg and progress_feedback()
    return r


#-- Append missing trailing slash to URLs
def fix_url(url):
    if url is None:
        url = ""
    if len(url):