Skip to content

Instantly share code, notes, and snippets.

@apiarian
Created April 17, 2014 01:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save apiarian/10947921 to your computer and use it in GitHub Desktop.
Save apiarian/10947921 to your computer and use it in GitHub Desktop.
#! /usr/bin/env python
# Aleksandr Pasechnik
# 2014-04-16
# Reads through the Safari Reading List for urls containing youtube.com
# Presents a reverse numbered list of the item titles
# Opens the selected item in Google Chrome
# Because Safari is currently introducing stutters into all youtube videos
import os
import plistlib
import subprocess
import sys
bookmarks_plist = '~/Library/Safari/Bookmarks.plist'
bookmarks_plist = os.path.expanduser(bookmarks_plist)
with open(bookmarks_plist, 'rb') as f:
content = f.read()
p = subprocess.Popen(
['plutil','-convert','xml1','-o','-','--','-'],
stdin = subprocess.PIPE, stdout = subprocess.PIPE
)
p.stdin.write(content)
out,err = p.communicate()
bookmarks = plistlib.readPlistFromString(out)
for list in bookmarks['Children']:
if 'ReadingList' in list['Title']:
youtubes = []
for item in list['Children']:
if 'youtube.com' in item['URLString']:
youtubes.append({
'title':item['URIDictionary']['title'],
'url' :item['URLString']
})
youtubes.reverse()
n = len(youtubes)
for link in youtubes:
print '%3d - %s'%(n, link['title'])
n = n-1
print
try:
c = raw_input('select a video number, none for 1, something else to abort: ')
if c == '':
selection = 1
else:
selection = int(c)
i = -1*selection
youtubes[i]
except:
print 'aborting'
sys.exit(-1)
print
print '%3d - %s selected'%(selection, youtubes[i]['title'])
print '\t', youtubes[i]['url']
subprocess.call([
'open',
'-a','Google Chrome',
youtubes[i]['url'],
])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment