Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

bit.lyButler v1.3 - URL shortening


  • Please log in to reply
22 replies to this topic
sumon
  • Moderators
  • 1317 posts
  • Last active: Dec 05 2016 10:14 PM
  • Joined: 18 May 2010
Posted Image


Download bitlyButler v1.3


Posted Image

Instant link shortening:
<!-- m -->http://bit.ly/tIuc6K<!-- m -->

New in 1.3
- Added ahk4.me support for Autohotkey links
- Added DockA so GUI can be dragged around
- Fixed a few GUI bugs
- Added check for having internet (removing http Errors)
- Better Feedback function (Appifyer API)
- Added singlemonitor "sticky GUI" support (so it doesn't fall out of the screen)
- Added Mouseover effects for buttons and Header.

...in 1.2

- Added groupboxes to GUI (much better)
- Fixed a few bugs concerning adding private API & hotkeying
- A few silent improvements
- Added a few textbased "easter eggs", we'll see if anyone finds them

... in 1.1
- Goo.gl added
- Traybar menu added
- Improved and extended menus
- Changed icon
- Bugfixes

Features:
- Instant link-shortening
- Three modes: On-demand, always-on & commandline
- Visual and audial feedback
- Configure to work with your own bit.ly-account (or get one)
- Includes access to bit.lyButler's API key(s)

Code:

The code was written in AHK_L. Please note that the below appended code will not work due to missing files, it is solely for the purpose of showing so that you might learn or see the code. The .exe extracts necessary data files (after kindly asking if that's okay) and will be runnable instantly.

Feel free to suggest improvements, use the script or share it with friends!

AHK source code is mostly GUI stuff, but the main functions are the following:

bitlyButler_Shorten(longURL) ; [by RaptorX modified by sumon]
{
	global user, API
	http := ComObjCreate("WinHttp.WinHttpRequest.5.1"), main := "http://api.bit.ly/v3/shorten?"
	longURL := urlEncode(longURL) ; Need urlEncode function
	post := "format=txt&login=" user "&apiKey=" API "&longUrl=" longURL
    http.open("GET", main . post, false)
    http.send()
    return RegexReplace(http.ResponseText, "\r?\n?")
}

googl(url) ; [by Uberi, under original name of "ShortenURL"]
{
  global API_G
  http:=ComObjCreate("WinHttp.WinHttpRequest.5.1")
  main:="https://www.googleapis.com/urlshortener/v1/url"
  params:="?key=" API_G
  http.open("POST", main . params, false)
  http.SetRequestHeader("Content-Type", "application/json")
  http.send("{""longUrl"": """ url """}")
  RegExMatch(http.ResponseText, """id"": ""(.*?)""", match)
  return match1
}


; urlEncode [by RaptorX]
urlEncode(url){
    f = %A_FormatInteger%
    SetFormat, Integer, Hex
    While (RegexMatch(url,"\W", var))
        StringReplace, url, url, %var%, % asc(var), All
    StringReplace, url, url, 0x, `%, All
    SetFormat, Integer, %f%
    return url
}


  • Guests
  • Last active:
  • Joined: --
Thanks! Fantastic piece of work. :)

bruno
  • Members
  • 635 posts
  • Last active: Nov 04 2015 02:26 PM
  • Joined: 07 Mar 2011
hi, sumon,

could you do next something called goo.gl gopher? :lol: thanks!

sumon
  • Moderators
  • 1317 posts
  • Last active: Dec 05 2016 10:14 PM
  • Joined: 18 May 2010

Thanks! Fantastic piece of work. :)


Fantastic is a strong adjective... so, thanks! :)

hi, sumon,

could you do next something called goo.gl gopher? :lol: thanks!


Yeah, I bet. Or I might just rename a general version with multiple selectable services, since I would prefer not being too service-specific in general. Do you prefer Goo.gl for any specific reason?

bruno
  • Members
  • 635 posts
  • Last active: Nov 04 2015 02:26 PM
  • Joined: 07 Mar 2011
Actually, I do not use Goo.gl. I use bit.ly, but I noticed some poster on another technology forum preferred Goo.gl. I am not sure which one is preferable. :?:

sumon
  • Moderators
  • 1317 posts
  • Last active: Dec 05 2016 10:14 PM
  • Joined: 18 May 2010
Major updates in 1.1, it's all lookin' pretty good now. 1.2 will probably be the public* release, so I'd be more than happy if you have suggestions or bug reports for the public release, which I hope will become rather popular.

Download bitlyButler v1.1

*public, as in "Announced outside of the Autohotkey community"

Frankie
  • Members
  • 2930 posts
  • Last active: Feb 05 2015 02:49 PM
  • Joined: 02 Nov 2008
Hey, could you allow the possibility of a custom public API keys? I tried using one, but when I clicked save settings and re-opened it, nothing was saved. It still had "Bitly.Butler's" selected for the API.

I'm trying to get it to work with the key from here. It also uses a custom site instead of bit.ly, so if there's a way to specify the pattern, maybe like pastej? We could type <!-- m -->http://ahk4.me/@short@<!-- m --> which would replace @short@ with the code.

Steps to reproduce:
Posted Image

Then click save.

Open settings again. Posted Image

And back to square one.
Posted Image

Tested on bit.lybutler 1.1
aboutscriptappsscripts
Request Video Tutorials Here or View Current Tutorials on YouTube
Any code ⇈ above ⇈ requires AutoHotkey_L to run

sumon
  • Moderators
  • 1317 posts
  • Last active: Dec 05 2016 10:14 PM
  • Joined: 18 May 2010

Hey, could you allow the possibility of a custom public API keys? I tried using one, but when I clicked save settings and re-opened it, nothing was saved. It still had "Bitly.Butler's" selected for the API.

Tested on bit.lybutler 1.1


What you describe is a bug (I intend to allow custom API keys, atleast for bit.ly and goo.gl) and I will try to fix it as soon as possible. As for "custom sites", the sites are using different API endpoints, so there would have to be a way to define that. Unless you mean something else? As example, look at the following code:

; ******* Functions ******* ------------------------------------------------------
bitlyButler_Shorten(longURL) ; [by RaptorX modified by sumon]
{
	global user, API
	http := ComObjCreate("WinHttp.WinHttpRequest.5.1"), main := "http://api.bit.ly/v3/shorten?"
	longURL := urlEncode(longURL) ; Need urlEncode function
	post := "format=txt&login=" user "&apiKey=" API "&longUrl=" longURL
    http.open("GET", main . post, false)
    http.send()
    return RegexReplace(http.ResponseText, "\r?\n?")
}

googl(url) ; [Thanks to Uberi, modified by Sumon]
{
  global API_G
  http:=ComObjCreate("WinHttp.WinHttpRequest.5.1")
  main:="https://www.googleapis.com/urlshortener/v1/url"
  params:="?key=" API_G
  http.open("POST", main . params, false)
  http.SetRequestHeader("Content-Type", "application/json")
  http.send("{""longUrl"": """ url """}")
  RegExMatch(http.ResponseText, """id"": ""(.*?)""", match)
  return match1
}


; urlEncode [by RaptorX]
urlEncode(url){
    f = %A_FormatInteger%
    SetFormat, Integer, Hex
    While (RegexMatch(url,"\W", var))
        StringReplace, url, url, %var%, % asc(var), All
    StringReplace, url, url, 0x, `%, All
    SetFormat, Integer, %f%
    return url
}


Frankie
  • Members
  • 2930 posts
  • Last active: Feb 05 2015 02:49 PM
  • Joined: 02 Nov 2008

Unless you mean something else?

I do actually. The characters at the end of the URL work with either domain. For example, oOpIXF can be accessed by <!-- m -->http://ahk4.me/oOpIXF<!-- m --> or http://bit.ly/oOpIXF. I was asking about changing the domain for easy pasting.

I guess you could pick a service to shorten with and then if you want a different pattern you can change the default. The default would be something like <!-- m -->http://bit.ly/@id@<!-- m --> for bitly. Users that don't need it can leave it at the default. Those that do can change it.
aboutscriptappsscripts
Request Video Tutorials Here or View Current Tutorials on YouTube
Any code ⇈ above ⇈ requires AutoHotkey_L to run

sumon
  • Moderators
  • 1317 posts
  • Last active: Dec 05 2016 10:14 PM
  • Joined: 18 May 2010

Unless you mean something else?

I do actually. The characters at the end of the URL work with either domain. For example, oOpIXF can be accessed by <!-- m -->http://ahk4.me/oOpIXF<!-- m --> or http://bit.ly/oOpIXF. I was asking about changing the domain for easy pasting.

I guess you could pick a service to shorten with and then if you want a different pattern you can change the default. The default would be something like <!-- m -->http://bit.ly/@id@<!-- m --> for bitly. Users that don't need it can leave it at the default. Those that do can change it.


The bug is fixed now (aswell as some minor things such as the timing before it autocloses), but before I push it live on Appifyer, is there any other request (or some clarification from Frankie)? I noticed all links returned while using the ahk4me key are in ahk4.me-format. Did you have any specific purpose in mind for the behaviour you describe? Using the AHK4me personal key constantly, but returning bitly-links, or vice versa?

The reason it works for AHK4me, I assume, is because the bit.ly account has been set up that way. I'm thinking about the use of making this into something generic, but I would think most link shortening sites would have no gain in this.

I'm just a bit puzzled, maybe I have missed something.

PS. If you shorten links often, I recommend using bitlyButler in always-on-mode. The tray menu is actually pretty handy for being a tray menu.

Frankie
  • Members
  • 2930 posts
  • Last active: Feb 05 2015 02:49 PM
  • Joined: 02 Nov 2008
If you use an ahk4.me key you should get an ahk4.me link.
aboutscriptappsscripts
Request Video Tutorials Here or View Current Tutorials on YouTube
Any code ⇈ above ⇈ requires AutoHotkey_L to run

sumon
  • Moderators
  • 1317 posts
  • Last active: Dec 05 2016 10:14 PM
  • Joined: 18 May 2010

If you use an ahk4.me key you should get an ahk4.me link.


Yes. It works like that at the moment. Is that okay? :)

Frankie
  • Members
  • 2930 posts
  • Last active: Feb 05 2015 02:49 PM
  • Joined: 02 Nov 2008

If you use an ahk4.me key you should get an ahk4.me link.


Yes. It works like that at the moment. Is that okay? :)

Yes. Thanks.
aboutscriptappsscripts
Request Video Tutorials Here or View Current Tutorials on YouTube
Any code ⇈ above ⇈ requires AutoHotkey_L to run

nimda
  • Members
  • 4368 posts
  • Last active: Aug 09 2015 02:36 AM
  • Joined: 26 Dec 2010
Note: the bit.ly v3 API can be accessed through URLDownloadToFile and can return plain-text as demonstrated at <!-- m -->http://ahk4.me/r7JQeu<!-- m -->

sumon
  • Moderators
  • 1317 posts
  • Last active: Dec 05 2016 10:14 PM
  • Joined: 18 May 2010

If you use an ahk4.me key you should get an ahk4.me link.


Yes. It works like that at the moment. Is that okay? :)

Yes. Thanks.


Good, see below :)

Note: the bit.ly v3 API can be accessed through URLDownloadToFile and can return plain-text as demonstrated at <!-- m -->http://ahk4.me/r7JQeu<!-- m -->


Is there any advantage over what I currently do? (Basically an outdated HttpRequest, using COM).

Download latest version (1.2)
appify:bitlyButler (quick-install for those with Appifyer)


I'll "push it" (update the official "online version") via Appifyer if noone notices any bugs.

- Added groupboxes to GUI (much better)
- Fixed a few bugs concerning adding private API & hotkeying
- A few silent improvements
- Added a few textbased "easter eggs", we'll see if anyone finds them

If anyone wants to see the full source code of bitlyButler, it can be found here. I am not very proud of it, alot of code for those little fancy GUI effects. [/b]