Permalink
Browse files

Clipboard inspector added

  • Loading branch information...
1 parent c8f4ade commit a0d64b7357fd21c262a98fd0d194df1372ef13e4 Andrés Bravo Gorgonio committed Aug 25, 2010
Showing with 151 additions and 12 deletions.
  1. +7 −0 README
  2. +65 −4 downtify.py
  3. +74 −0 macOSclipboard.py
  4. BIN macOSclipboard.pyc
  5. +5 −8 spotify-urls.txt
View
7 README
@@ -2,6 +2,11 @@ Downtify - version 0.1
Downtify would be an mac app for getting the spotify songs from youtube. It's easy and works very well. :)
+Downtify is the missing link betwen spotify and jdownloader. Let's select multiple songs from your spotify lists, copy (cmd + c), and see downtify getting this songs from youtube and put it into the clipboard to let jdownloader to get the mp3 file.
+
+In fact, what downtify do is getting the song info, search it in youtube and get the most indicated video for it, then it thows teh link into the clipboard to let jdownloader do what ever it does...
+;)
+
REQUERIMENTS:
@@ -11,3 +16,5 @@ To developping
- python 2.6
- Tkinter
+- Growl (optional)
+- Gdata for python
View
@@ -1,12 +1,16 @@
import sys
+sys.path.append('/Users/andresbravogorgonio/Documents/Proyectos/Downtify/SRC/downtify/')
from Tkinter import *
import urllib2, urllib
import webbrowser
import os
import time
import string
from HTMLParser import HTMLParser
+import gdata.youtube.service
+import macOSclipboard
+
class SpiderParser(HTMLParser):
@@ -47,22 +51,24 @@ def __init__(self, master):
scrollbar = Scrollbar(master, orient=VERTICAL)
self.list = Listbox(frame, yscrollcommand=scrollbar.set)
- self.configuration()
+
scrollbar.config(command=self.yview)
scrollbar.pack(side=RIGHT, fill=Y)
self.list.pack(side=LEFT, fill=BOTH, expand=1)
scrollbar2 = Scrollbar(master, orient=VERTICAL)
self.list2 = Listbox(frame, yscrollcommand=scrollbar.set)
- self.configuration()
+
scrollbar2.config(command=self.yview)
scrollbar2.pack(side=RIGHT, fill=Y)
self.list2.pack(side=LEFT, fill=BOTH, expand=1)
self.button_get_info = Button(frame, text="GET SONGS", fg="red", command=self.getSongsInfo)
self.button_get_info.pack(side=RIGHT)
+ self.button_get_info = Button(frame, text="ISPECT THE CLIPBOARD", fg="red", command=self.getSpotifyLinks)
+ self.button_get_info.pack(side=RIGHT)
- self.configuration()
+ #self.configuration()
def configuration(self):
@@ -77,6 +83,19 @@ def configuration(self):
self.list.insert(END, line)
print line
f.close()
+
+ def getSpotifyLinks(self):
+ #Parsing urls from archive
+ f = macOSclipboard.paste()
+ if f.find('http://open.spotify.com') != -1 :
+ self.urls = []
+ for line in f.split('\n'):
+ if line.find('http://open.spotify.com') == 0 :
+ self.urls += [ line ]
+ self.list.insert(END, line)
+ print line
+ else :
+ print "No spotify urls in clipboard"
def getSongsInfo(self):
#Reader read configuration file
@@ -92,7 +111,7 @@ def getSongsInfo(self):
# parsing the html
songInfo = self.parseHtmlArchive(filename)
# youtube query json
- youtubeFilename = self.getYoutubeResults(songInfo, i)
+ self.SearchAndPrint(songInfo)
i = i + 1
#songInfo = #TODO: parse the archive to get the info
self.songs += [ songInfo ]
@@ -174,6 +193,48 @@ def test_connection(self):
return False
else:
return True
+
+ #YOUTUBE DEFS
+
+ def PrintEntryDetails(self, entry):
+ #print 'Video title: %s' % entry.media.title.text
+ #print 'Video published on: %s ' % entry.published.text
+ #print 'Video description: %s' % entry.media.description.text
+ #print 'Video category: %s' % entry.media.category[0].text
+ #print 'Video tags: %s' % entry.media.keywords.text
+ print "Coping to clipboard the video url :"+entry.media.player.url
+ macOSclipboard.copy(entry.media.player.url);
+ #print 'Video flash player URL: %s' % entry.GetSwfUrl()
+ #print 'Video duration: %s' % entry.media.duration.seconds
+
+ # non entry.media attributes
+ #print 'Video geo location: %s' % entry.geo.location()
+ #print 'Video view count: %s' % entry.statistics.view_count
+ #print 'Video rating: %s' % entry.rating.average
+
+ # show alternate formats
+ # for alternate_format in entry.media.content:
+ # if 'isDefault' not in alternate_format.extension_attributes:
+ # print 'Alternate format: %s | url: %s ' % (alternate_format.type,
+ # alternate_format.url)
+
+ # show thumbnails
+ # for thumbnail in entry.media.thumbnail:
+ # print 'Thumbnail url: %s' % thumbnail.url
+
+ def PrintVideoFeed(self, feed):
+ for entry in feed.entry:
+ self.PrintEntryDetails(entry)
+ return 1
+
+ def SearchAndPrint(self, search_terms):
+ yt_service = gdata.youtube.service.YouTubeService()
+ query = gdata.youtube.service.YouTubeVideoQuery()
+ query.vq = search_terms
+ query.orderby = 'viewCount'
+ query.racy = 'include'
+ feed = yt_service.YouTubeQuery(query)
+ self.PrintVideoFeed(feed)
root = Tk()
View
@@ -0,0 +1,74 @@
+#!/usr/bin/env python
+
+"""Manipulate Mac OS clipboard ("scrap") from Python.
+
+See also: pbcopy(1), pbpaste(1)"""
+
+
+# Usage of commands
+# import commands
+# commands.getoutput('pbpaste')
+#
+# Usage of pbcopy
+# echo "Blah" | pbcopy
+# usage of pbpaste
+# pbpaste -Prefer txt
+
+from sys import stdin, stdout
+from optparse import OptionParser
+import commands
+import MacOS
+
+def paste(flavorType='txt', verbose=False):
+ try:
+ scrap = commands.getoutput('pbpaste -Prefer '+flavorType)
+ return scrap
+ except MacOS.Error, e:
+ if verbose or e[0] != -102:
+ # -102 == noTypeErr
+ raise
+ return ""
+
+def copy(text):
+ scrap = commands.getoutput('pbpaste -Prefer txt')
+ commands.getoutput('echo "'+text+'" | pbcopy')
+
+def list_flavors():
+ scrap = GetCurrentScrap()
+ return [(name, scrap.GetScrapFlavorSize(name))
+ for name, flags in scrap.GetScrapFlavorInfoList()]
+
+def main():
+ parser = OptionParser()
+ parser.set_defaults(flavor='TEXT', translate=True, copy=False,
+ list_=False, verbose=False)
+ parser.add_option("-c", "--copy", dest="copy", action="store_true",
+ help="copy stdin to clipboard [default: paste clipboard"
+ " to stdout]")
+ parser.add_option("-l", "--list", dest="list_", action="store_true",
+ help="list currently available flavors with data sizes")
+ parser.add_option("-x", "--notrans", dest="translate",
+ action="store_false",
+ help="don't translate CR to LF on output")
+ parser.add_option("-f", "--flavor", dest="flavor", action="store",
+ help="specify flavor [default: TEXT]")
+ parser.add_option("-v", "--verbose", dest="verbose", action="store_true",
+ help="complain if scrap flavor not found [default:"
+ " treat as empty]")
+
+ options, args = parser.parse_args()
+ if options.list_:
+ for flavor in list_flavors():
+ print "'%s' %9d" % flavor
+ elif options.copy:
+ copy(stdin.read(), options.flavor)
+ else:
+ text = paste(options.flavor, options.verbose)
+ if options.translate:
+ text = text.replace('\r', '\n')
+ stdout.write(text)
+
+__all__ = ['paste', 'copy', 'list_flavors', 'main']
+
+if __name__ == "__main__":
+ main()
View
Binary file not shown.
View
@@ -1,8 +1,5 @@
-http://open.spotify.com/track/0UopkfGuwDf3hx3tr8rPxC
-http://open.spotify.com/track/0uFir4ix6RY0N5GiDAEtcV
-http://open.spotify.com/track/0rOKhtmOIy1WgExSfZXMed
-http://open.spotify.com/track/4oIcI693uzKhCnOkXGMKpm
-http://open.spotify.com/track/1PINlN6aAHRfkv5zgxjA56
-http://open.spotify.com/track/598ioS7kbtHNBemw00dRqh
-http://open.spotify.com/track/200AMTxZuz95K9096jYMLj
-http://open.spotify.com/track/5qtwzv99vOr5UTwnTixn7j
+http://open.spotify.com/track/76o13WSKjdkBNU7A2I2FLy
+http://open.spotify.com/track/4ouIWkFspNZYFO87Gdufxb
+http://open.spotify.com/track/7EVpMNgGbQiWH8xsNJ3yam
+http://open.spotify.com/track/0VKWOWFx8QynNgryKouLGO
+http://open.spotify.com/track/3X3blxR2bCKnPWalYIrbxX

0 comments on commit a0d64b7

Please sign in to comment.