Just bought yourself a Humax Freesat/Freeview box and want it to work with your LG TV model LG32LD490?
I found code 248 did the trick.
Just bought yourself a Humax Freesat/Freeview box and want it to work with your LG TV model LG32LD490?
I found code 248 did the trick.
It’s that time of the the year again. The Great Escape Festival announced the first 150 artists on their bill and I’ve compiled them into a handy Spotify playlist.
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 |
import spotipy artists = ['names', 'of'. 'artists'] def getArtist(artist): spotify = spotipy.Spotify() results = spotify.search(q='artist:' + artist, type='artist') if results['artists']['total'] > 0: for a in results['artists']['items']: if a['name'].lower() == artist.decode('utf-8').lower(): return a return None else: return None def getTop5(artist): artist_obj = getArtist(artist) if not artist_obj: return None artist_id = artist_obj['id'] spotify = spotipy.Spotify() results = spotify.artist_top_tracks(artist_id, country='GB') return results['tracks'][:5] with open('TGE15.txt', 'w') as f: for a in artists: tracks = getTop5(a) if tracks: for t in tracks: f.write(t['uri']+'\n') |
Using the following line:
mencoder mf://@stills.txt -mf fps=30 -ovc copy -oac copy -o timelapse.avi
Lead to a 1.86Gb file – its a good job I’ve got a fibre broadband connection!
The problem: You’re going to a festival with more bands than you could ever hope to see. You need a playlist with songs of all the bands playing so you can decide what to go and see and what to give a miss.
The solution: From a list of the artists, query the Spotify Search API with the artist name and save the URIs of the five most popular tracks returned by Spotify. Simples!
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 |
import requests # for querying the API import json # for interpreting the data returned by the API def top5(artist): # an empty list of tracks tracks = [] # set up for requests module query_params = {'q': 'artist:'+artist} # nospace after colon endpoint = 'http://ws.spotify.com/search/1/track.json' response = requests.get(endpoint, params= query_params) print response.status_code print artist if response.status_code == 200: # server responds nicely data = json.loads(response.content) # load the json data i = 0 while len(tracks) < 5: # check we have some results, or haven't reached the end of them if int(data['info']['num_results']) == i or 100 == i: break # construct our 'track' library track = {'name':data['tracks'][i]['name'], 'artist':data['tracks'][i]['artists'][0]['name'], 'uri':data['tracks'][i]['href']} # check the returned artist matches the queried artist if artist == track['artist']: add = True # Check the track is available in my territory -> GB if not 'GB' in data['tracks'][i]['album']['availability']['territories']: add = False # Check the track isn't included already, eliminates including single and album versions for t in tracks: if t['name'] == track['name']: add = False # Passed all the tests? if add: tracks.append(track) i = i + 1 return tracks else: # bad response from the server print artist+' caused an error' |
The code above is the function which you can pass each artist name to. It’s only a few more lines of code to feed a list of artists into the function and save a playlist
list of tracks
. I’ve deliberately saved more data than is needed for this task, as you never know when it will come in handy e.g. creating a script to query the playlist
for all the artists that were successfully found.
Once you have all the URIs in a text file, with appropriate line breaks, you can drag this into the Spotify client and into a new playlist and they’ll magically become the tracks you want!
The chaps over at MAMA and Company announced the first batch of artists for The Great Escape festival this May, and with more than 100 announced and more to come, its time to get listening to my TGE14 Spotify playlist!
As with last year, I’ll be adding to it as more acts are announced and more tracks become available. As a rule, I’ve taken the top five most popular tracks from each artist (where present). Its work in progress, so do let me know if there’s something in there that shouldn’t be (I’ve tried to eliminate false positives this year).
And if you’d like to see the code that generated it, check out this post.
Scraped from http://skymovies.sky.com/api/carousel/on-sky-movies
For mashing up with Rotten Tomatoes or IMDB or the like…
The problem: Take 1500 images captured from my Raspberry Pi and turn them into a 1080 HD video suitable for upload to YouTube, Facebook, and Vimeo.
The solution: Install ffmpeg and/or mencoder and use either tool to from the Terminal on my mac to compile the images into a suitable video format.
To install the command line tools ffmpeg and mencoder I followed this tutorial from aktagon.com which points you to the binaries available from Mac OSX port website ffmpegx.com, which in turn points you to a few other sourceforge websites to download what you need. Once your set and you can run ffmpeg and mencoder from the command line, you’re ready to go.
The first method I tried was using ffmpeg. I tried this originally with a smaller resolution timelapse (720 HD) and it compiled quickly and easily with a relatively small filesize. Thanks to Greg Heartsfield for the instruction on this approach.
ffmpeg -r 25 -s hd720 -vcodec libx264 -b 1000k timelapse.mp4 -i image%04d.jpg
This roughly translates as: use ffmpeg, with a frame rate of 25fps, with settings preset ‘hd720’, with the H.264 codec, to encode a video with a bit rate of 1 Mbit/s called ‘timelapse.mp4’ using jpg files that follow a image0001, image0002, image0003 etc schema.
However, my timelapses weren’t consistent with this approach, and on some I got tearing and grey blocks across the screen. It may be my ageing MacBook was to blame, but instead I sought an alternative approach. So after failing to compile the video using mencoder with the H.264 codec from this post on a Ubuntu forum, I settled on this PasteBin code from a RaspberryPi For Beginners YouTube:
1 2 |
ls *.jpg > stills.txt mencoder -nosound -ovc lavc -lavcopts vcodec=mpeg4:aspect=16/9:vbitrate=8000000 -vf scale=1920:1080 -o timelapse.avi -mf type=jpeg:fps=24 mf://@stills.txt |
The first line of the code is a handy trick to list all the jpg files of the current directory and save them to a text file. The second line I’m less certain of as I’m unfamiliar with mencoder, and with the success of this encode my desire to trawl Google was somewhat diminished. However, it should be said that this method took a lot longer to encode than ffmpeg and playback was still jerky in places – but I’m definitely putting that down to the MacBook. I would have also have liked to have used the H.264 codec but I couldn’t get the code I’d found elsewhere to work…
Do let me know of any improvements to the code above, or alternative/more reliable methods for encoding jpgs into a timelapse video.
The problem: Invert the colours of a Sublime Text 2 colour theme, so that when I invert the screen on my MacBook the colours are as if they weren’t inverted.
The solution: Write a python script that matches the hex colour codes (e.g. #ffffff) in the colour theme configuration file against a regular expression, and replace the hex colour codes with their inverse.
The code:
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 45 46 47 48 49 50 |
import re def invertHex(hexNumber): #invert a hex number inverse = hex(abs(int(hexNumber, 16) - 255))[2:] # if the number is a single digit add a preceding zero if len(inverse) == 1: inverse = '0'+inverse return inverse def colorInvert(hexCode): #define an empty string for our new colour code inverse = "" # if the code is RGB if len(hexCode) == 6: R = hexCode[:2] G = hexCode[2:4] B = hexCode[4:] # if the code is ARGB elif len(hexCode) == 8: A = hexCode[:2] R = hexCode[2:4] G = hexCode[4:6] B = hexCode[6:] # don't invert the alpha channel inverse = inverse + A else: # do nothing if it is neither length return hexCode inverse = inverse + invertHex(R) inverse = inverse + invertHex(G) inverse = inverse + invertHex(B) return inverse def replaceHex(matchobj): #exclude the preceding hash symbol of the matched object hexCode = matchobj.group(0)[1:] #invert the colour code and return with the hash return '#'+colorInvert(hexCode) #open and read the original file f = open('Monokai.xml', 'r').read() f.close() #invert every match of the regular expression from f invertedcode = re.sub('#([0-9a-fA-F]{6,8})', replaceHex, f) g = open('Inverted Monokai.tmTheme', 'w') g.write(invertedcode) g.close() |
Things to note: The python interpreter returns hex numbers with a preceding ‘0x’, so hex(255)
yields 0xff
. That’s why we use [2:]
to grab just the last two characters of the value. The regular expression here is used to match six character RGB codes as well as eight character ARGB codes. RGB codes can also be expressed as three characters but in the tmTheme file I was working with none were present.
Background: Last year I was diagnosed with cataracts in both eyes. A white back-lit program or webpage is particularly difficult to read because of the glare caused by the white light. Fortunately on Macs ctrl + alt + cmd + 8 inverts the screen to help alleviate this. Unfortunately this meant by code editor (Sublime Text 2) got inverted too. So rather than having to flick back and forth between modes, when working between Sublime and the browser I thought it’d be best to invert Sublime to have my Mac screen consistently inverted.
Tracks from the night as they were played. Now I should stop messing about with Python and feeling pleased with myself and go to bed…
New Young Pony Club – Ice Cream | 22:35:20
Flume – Holdin On | 22:38:32
Major Lazer – Pon De Floor – Radio Edit | 22:41:07
Alt-J – Dissolve Me | 22:44:07
Daft Punk – Get Lucky (feat. Pharrell Williams) | 22:48:01
Vampire Weekend – A-Punk | 22:54:06
Yeah Yeah Yeahs – Date With the Night | 22:56:19
Arcade Fire – Keep the Car Running | 22:58:49
Azari & III – Reckless With Your Love – Paul Epworth Radio Edit | 23:02:13
Haim – Forever | 23:05:24
Maxïmo Park – Apply Some Pressure | 23:09:25
Mumford & Sons – Little Lion Man | 23:12:40
Blondie – Hanging On The Telephone – 2001 Digital Remaster | 23:16:42
Disclosure – F for You | 23:19:00
Bombay Bicycle Club – Shuffle | 23:23:24
Solange – Losing You | 23:27:15
Blur – There’s No Other Way | 23:31:32
The Cure – Close to Me | 23:34:40
Groove Armada – Superstylin’ | 23:38:15
Foals – My Number | 23:44:10
Rudimental – Waiting All Night (feat. Ella Eyre) | 23:48:06
The Wombats – Kill The Director | 23:52:54
Fenech-Soler – Demons | 23:55:30
The Cure – Boys Don’t Cry | 23:59:09
Of Monsters and Men – Little Talks | 00:01:40
The Jam – Town Called Malice | 00:06:02
Joy Division – Love Will Tear Us Apart | 00:08:50
The Clash – I Fought the Law | 00:12:10
M83 – Midnight City | 00:14:47
Phoenix – Lisztomania | 00:18:46
Foo Fighters – Monkey Wrench | 00:22:43
The Chemical Brothers – Swoon – Radio Edit | 00:26:29
Bill Haley & His Comets – Rock Around the Clock | 00:29:31
The 2 Bears – Bear Hug | 00:31:40
Chuck Berry – Johnny B. Goode | 00:36:05
The Maccabees – Can You Give It | 00:38:41
The Wombats – Techno Fan | 00:41:30
AlunaGeorge – You Know You Like It | 00:45:24
Delphic – Halcyon | 00:48:42
Jason Derülo – Talk Dirty – feat. 2 Chainz | 00:53:19
Jessie Ware – Running (Disclosure remix) | 00:56:12
Foals – My Number | 01:01:37
Miike Snow – Animal (Mark Ronson Remix) | 01:05:33
Mumford & Sons – The Cave | 01:09:58
Arctic Monkeys – I Bet You Look Good on the Dancefloor | 01:13:31
Foals – Cassius | 01:16:20
TNGHT – Higher Ground | 01:20:05
DJ Fresh – Golddust | 01:23:19
Hot Chip – One Life Stand | 01:26:25
The Chemical Brothers – Leave Home | 01:31:42
Pete and the Pirates – Bright Lights | 01:37:10
Tom Vek – A Chore | 01:40:16
Chromeo – Needy Girl – Radio Edit | 01:47:14
Tom Vek – Aroused | 01:51:25
Miike Snow – Animal (Mark Ronson Remix) | 01:54:51
The Chemical Brothers – Swoon – Radio Edit | 01:59:16
Chuck Berry – Johnny B. Goode | 02:02:18
Bloc Party – Helicopter | 02:04:55
Orbital – Wonky – Plump DJ’s Mix | 02:08:30
Delta Heavy – Get By | 02:13:25
Prince & The Revolution – Kiss | 02:18:01
Taylor Swift – I Knew You Were Trouble | 02:21:41
The Jam – Town Called Malice | 02:25:15
Fenech-Soler – Demons | 02:28:03
Kindness – That’s Alright | 02:31:42
Friendly Fires – Jump In The Pool | 02:36:24
LCD Soundsystem – North American Scum | 02:39:56
Two Door Cinema Club – What You Know | 02:45:19
Major Lazer – Get Free | 02:48:24
The Libertines – What Became Of The Likely Lads | 02:53:08
MGMT – Electric Feel (Justice Remix) | 02:56:25
Hot Chip – One Life Stand | 03:01:47
Pete and the Pirates – Blood Gets Thin | 03:07:04
M83 – Reunion | 03:10:04
The Rumble Strips – Girls And Boys In Love | 03:13:54
The Clash – I Fought the Law | 03:16:22
Django Django – Default | 03:18:59
Flume – Holdin On | 03:22:01
Phoenix – Lisztomania | 03:24:31
Yeah Yeah Yeahs – Heads Will Roll | 03:28:28
Totally Enormous Extinct Dinosaurs – Garden | 03:32:04
Everything Everything – MY KZ, UR BF | 03:36:34
Joy Division – Love Will Tear Us Apart | 03:40:07
SBTRKT – Pharaohs (feat. Roses Gabor) | 03:43:28
Young Knives – She’s Attracted To – Radio Edit | 03:47:01
Disclosure – Latch (feat. Sam Smith) | 03:50:01
Bombay Bicycle Club – Shuffle | 03:54:12
Arcade Fire – Reflektor | 03:58:03
Florence + the Machine – Dog Days Are Over | 04:05:32
Mumford & Sons – I Will Wait | 04:09:40
Foals – My Number | 04:14:12
Totally Enormous Extinct Dinosaurs – Tapes & Money | 04:18:07
John Travolta – The Grease Megamix | 04:21:42
MGMT – Kids – Soulwax Mix | 04:26:28
Metronomy – The Look | 04:32:02
Disclosure – F for You | 04:36:34
Fake Blood – I Think I Like It | 04:40:58