diff -Nru scope-youtube-0.0.4.5/debian/changelog scope-youtube-0.0.4.6/debian/changelog --- scope-youtube-0.0.4.5/debian/changelog 2012-10-07 21:11:18.000000000 +0000 +++ scope-youtube-0.0.4.6/debian/changelog 2013-01-03 12:34:46.000000000 +0000 @@ -1,3 +1,15 @@ +scope-youtube (0.0.4.6-1ubuntu1) quantal; urgency=low + + * Migrated to Python3 + * Added UMplayer to possible players + * Test internet connection to avoid errors + * Modified description + * Engine modifications: + * Removed self.scope > scope + * Removed self.mresults to json, dumps and load (working correctly) + + -- Lorenzo Carbonell Thu, 03 Jan 2013 13:31:32 +0100 + scope-youtube (0.0.4.5-1ubuntu1) quantal; urgency=low * Added stars diff -Nru scope-youtube-0.0.4.5/src/downloader.py scope-youtube-0.0.4.6/src/downloader.py --- scope-youtube-0.0.4.5/src/downloader.py 2012-10-07 16:07:17.000000000 +0000 +++ scope-youtube-0.0.4.6/src/downloader.py 2013-01-03 12:28:17.000000000 +0000 @@ -36,12 +36,14 @@ command = '/usr/bin/youtube-dl -F "%s"'%(url) result = run(command) formats = [] - if result.find('Available formats:')>-1: - ini = result.find('Available formats:')+19 - sol = result[ini:].replace('\t','') - for el in sol.split('\n'): - if el.find(':')>-1: - formats.append(el.split(':')) + if result is not None and len(result)>0: + result = result.decode() + if result.find('Available formats:')>-1: + ini = result.find('Available formats:')+19 + sol = result[ini:].replace('\t','') + for el in sol.split('\n'): + if el.find(':')>-1: + formats.append(el.split(':')) return formats def run(command): @@ -130,6 +132,6 @@ dformat = model[tree_iter][1] filename = cm.entry2.get_text()+'.'+dextension command = '/usr/bin/youtube-dl "%s" -f %s -o "%s"'%(url,dformat,filename) - print run(command) + print(run(command)) cm.destroy() exit(0) diff -Nru scope-youtube-0.0.4.5/src/preferences.py scope-youtube-0.0.4.6/src/preferences.py --- scope-youtube-0.0.4.5/src/preferences.py 2012-10-07 20:42:16.000000000 +0000 +++ scope-youtube-0.0.4.6/src/preferences.py 2013-01-03 10:02:53.000000000 +0000 @@ -32,6 +32,7 @@ VLC = ['vlc','/usr/bin/vlc','/usr/bin/vlc --one-instance "%s"'] MINITUBE = ['minitube','/usr/bin/minitube','/usr/bin/minitube "%s"'] SMPLAYER = ['smplayer','/usr/bin/smplayer','/usr/bin/smplayer "%s"'] +UMPLAYER = ['umplayer','/usr/bin/umplayer','/usr/bin/umplayer "%s"'] TOTEM = ['totem','/usr/bin/totem','/usr/bin/totem "%s"'] MIRO = ['miro','/usr/bin/miro','/usr/bin/miro "%s"'] DOWNLOAD = ['youtube-dl','/usr/bin/youtube-dl','/usr/share/yavol-scope-youtube/downloader.py "%s"'] @@ -104,5 +105,5 @@ if __name__ == "__main__": pf = Preferences() pf.save() - print pf.viewer + print(pf.viewer) exit(0) diff -Nru scope-youtube-0.0.4.5/src/preferences_dialog.py scope-youtube-0.0.4.6/src/preferences_dialog.py --- scope-youtube-0.0.4.5/src/preferences_dialog.py 2012-10-07 16:07:18.000000000 +0000 +++ scope-youtube-0.0.4.6/src/preferences_dialog.py 2013-01-03 10:07:32.000000000 +0000 @@ -51,7 +51,7 @@ self.vbox2 = Gtk.VBox(spacing = 5) self.vbox2.set_border_width(5) self.frame1.add(self.vbox2) - table1 = Gtk.Table(10,2,True) + table1 = Gtk.Table(11,2,True) self.vbox2.add(table1) # label1 = Gtk.Label.new(_('Select viewer')+':') @@ -75,6 +75,8 @@ table1.attach(self.radiobutton7,0,1,8,9) self.radiobutton8 = Gtk.RadioButton.new_with_label_from_widget(self.radiobutton0,_('Miro')) table1.attach(self.radiobutton8,0,1,9,10) + self.radiobutton9 = Gtk.RadioButton.new_with_label_from_widget(self.radiobutton0,_('Umplayer')) + table1.attach(self.radiobutton9,0,1,10,11) #*************************************************************** # download = Gio.File.new_for_path(preferences.DOWNLOAD[1]) @@ -84,6 +86,7 @@ minitube = Gio.File.new_for_path(preferences.MINITUBE[1]) smplayer = Gio.File.new_for_path(preferences.SMPLAYER[1]) miro = Gio.File.new_for_path(preferences.MIRO[1]) + umplayer = Gio.File.new_for_path(preferences.UMPLAYER[1]) if not download.query_exists(None): self.radiobutton1.set_sensitive(False) if not yviewer.query_exists(None): @@ -98,6 +101,8 @@ self.radiobutton7.set_sensitive(False) if not miro.query_exists(None): self.radiobutton8.set_sensitive(False) + if not umplayer.query_exists(None): + self.radiobutton9.set_sensitive(False) # self.load_preferences() @@ -157,6 +162,11 @@ self.radiobutton8.set_active(True) else: self.radiobutton0.set_active(True) + elif self.preferences.viewer == 'umplayer': + if self.radiobutton9.is_sensitive(): + self.radiobutton9.set_active(True) + else: + self.radiobutton0.set_active(True) def save_preferences(self): if self.radiobutton0.get_active() == True: @@ -177,6 +187,8 @@ viewer = 'smplayer' elif self.radiobutton8.get_active() == True: viewer = 'miro' + elif self.radiobutton9.get_active() == True: + viewer = 'umplayer' self.preferences.viewer = viewer self.preferences.save() diff -Nru scope-youtube-0.0.4.5/src/selectplayer.py scope-youtube-0.0.4.6/src/selectplayer.py --- scope-youtube-0.0.4.5/src/selectplayer.py 2012-10-07 16:07:18.000000000 +0000 +++ scope-youtube-0.0.4.6/src/selectplayer.py 2013-01-03 10:02:40.000000000 +0000 @@ -73,7 +73,7 @@ self.vbox2 = Gtk.VBox(spacing = 5) self.vbox2.set_border_width(5) self.frame1.add(self.vbox2) - table1 = Gtk.Table(9,2,True) + table1 = Gtk.Table(10,2,True) self.vbox2.add(table1) # label1 = Gtk.Label.new(_('Select viewer')+':') @@ -96,6 +96,8 @@ table1.attach(self.radiobutton6,0,1,7,8) self.radiobutton7 = Gtk.RadioButton.new_with_label_from_widget(self.radiobutton0,_('Miro')) table1.attach(self.radiobutton7,0,1,8,9) + self.radiobutton8 = Gtk.RadioButton.new_with_label_from_widget(self.radiobutton0,_('UMPlayer')) + table1.attach(self.radiobutton8,0,1,9,10) #*************************************************************** # download = Gio.File.new_for_path(preferences.DOWNLOAD[1]) @@ -105,6 +107,7 @@ smplayer = Gio.File.new_for_path(preferences.SMPLAYER[1]) yviewer = Gio.File.new_for_path(preferences.YVIEWER[1]) miro = Gio.File.new_for_path(preferences.MIRO[1]) + umplayer = Gio.File.new_for_path(preferences.UMPLAYER[1]) if not download.query_exists(None): self.radiobutton1.set_sensitive(False) if not yviewer.query_exists(None): @@ -119,6 +122,8 @@ self.radiobutton6.set_sensitive(False) if not miro.query_exists(None): self.radiobutton7.set_sensitive(False) + if not umplayer.query_exists(None): + self.radiobutton8.set_sensitive(False) # self.frame2 = Gtk.Frame() self.vbox1.add(self.frame2) @@ -206,10 +211,12 @@ command = preferences.SMPLAYER[2]%(url) elif cm.radiobutton7.get_active(): command = preferences.MIRO[2]%(url) + elif cm.radiobutton8.get_active(): + command = preferences.UMPLAYER[2]%(url) cm.hide() cm.destroy() if command: - print run(command) + print(run(command)) else: webbrowser.open(url) exit(0) diff -Nru scope-youtube-0.0.4.5/src/yavol-scope-youtube scope-youtube-0.0.4.6/src/yavol-scope-youtube --- scope-youtube-0.0.4.5/src/yavol-scope-youtube 2012-10-07 21:10:24.000000000 +0000 +++ scope-youtube-0.0.4.6/src/yavol-scope-youtube 2013-01-03 12:25:49.000000000 +0000 @@ -1,4 +1,4 @@ -#! /usr/bin/python +#!usr/bin/python3 # -*- coding: iso-8859-15 -*- # __author__='atareao' @@ -38,50 +38,59 @@ import preferences import socket import webbrowser +import json from comun import _ socket.setdefaulttimeout(5) BUS_NAME = 'net.launchpad.scope.yavol.youtube' +def s2f(texto): + try: + return float(texto) + except: + pass + return 0.0 class Daemon: def __init__ (self): - self.scope = Unity.Scope.new ('/net/launchpad/scope/yavol/youtube') - self.scope.search_in_global = False - self.scope.connect('search-changed', self.on_search_changed) - self.scope.connect('filters-changed', self.on_filters_changed) - self.scope.connect('activate-uri', self.on_activate_uri) - self.scope.connect('preview-uri', self.on_preview_uri) - self.scope.export() + scope = Unity.Scope.new ('/net/launchpad/scope/yavol/youtube') + scope.search_in_global = False + scope.connect('search-changed', self.on_search_changed) + scope.connect('filters-changed', self.on_filters_changed) + scope.connect('activate-uri', self.on_activate_uri) + scope.connect('preview-uri', self.on_preview_uri) + scope.export() self.preferences = preferences.Preferences() - self.mresults = [] def on_preview_uri(self, scope, uri): """Preview request handler""" preview = None - model = self.scope.props.results_model + model = scope.props.results_model iter = model.get_first_iter() - cont = 0 while not model.is_last(iter): if model.get_string(iter, 0) == uri: - title = model.get_string(iter, 4); - desc = model.get_string(iter, 5); + title = model.get_string(iter, 4) + desc = model.get_string(iter, 5) + if len(desc)>7: + desc = desc[6:] + result = json.loads(model.get_string(iter, 6)) preview = Unity.MoviePreview.new(title, '', desc, None) preview.connect('closed', self.on_preview_closed) - if len(self.mresults[cont]['thumbnail'])>2: - preview.props.image_source_uri = self.mresults[cont]['thumbnail'][2] - elif len(self.mresults[cont]['thumbnail'])>1: - preview.props.image_source_uri = self.mresults[cont]['thumbnail'][1] - elif len(self.mresults[cont]['thumbnail'])>0: - preview.props.image_source_uri = self.mresults[cont]['thumbnail'][0] + if len(result['thumbnail'])>2: + preview.props.image_source_uri = result['thumbnail'][2] + elif len(result['thumbnail'])>1: + preview.props.image_source_uri = result['thumbnail'][1] + elif len(result['thumbnail'])>0: + preview.props.image_source_uri = result['thumbnail'][0] else: preview.props.image_source_uri = model.get_string(iter, 1) # - preview.add_info(Unity.InfoHint.new("categories", _("Categories"), None, self.mresults[cont]['categories'])) - preview.add_info(Unity.InfoHint.new("license", _("License"), None, self.mresults[cont]['license'])) - preview.add_info(Unity.InfoHint.new("viewcount", _("View count"), None, str(self.mresults[cont]['viewcount']))) - preview.add_info(Unity.InfoHint.new("likes", _("Likes"), None, str(self.mresults[cont]['likes']))) - preview.add_info(Unity.InfoHint.new("dislikes", _("Dislikes"), None, str(self.mresults[cont]['dislikes']))) - preview.set_rating(self.mresults[cont]['rating'], self.mresults[cont]['rating']) + preview.add_info(Unity.InfoHint.new("categories", _("Categories"), None, result['categories'])) + preview.add_info(Unity.InfoHint.new("license", _("License"), None, result['license'])) + preview.add_info(Unity.InfoHint.new("viewcount", _("View count"), None, str(result['viewcount']))) + preview.add_info(Unity.InfoHint.new("likes", _("Likes"), None, str(result['likes']))) + preview.add_info(Unity.InfoHint.new("dislikes", _("Dislikes"), None, str(result['dislikes']))) + reviews = s2f(str(result['likes']))+s2f(str(result['dislikes'])) + preview.set_rating(s2f(result['rating'])/5.0, reviews) # play_video = Unity.PreviewAction.new("play-in-player", _("Play"), None) play_video.connect('activated', self.play_video) @@ -89,7 +98,6 @@ open_in_webbrowser = Unity.PreviewAction.new("open-in-webbrowser", _("Webbrowser"), None) open_in_webbrowser.connect('activated', self.on_open_in_webbrowser) preview.add_action(open_in_webbrowser) - cont += 1 iter = model.next(iter) if preview == None: print("Couldn't find model row for requested preview uri:", uri) @@ -111,13 +119,13 @@ try: pass except Exception as e: - print "Failed to send close signal to preview player:", e + print("Failed to send close signal to preview player:", e) def on_activate_uri (self, scope, uri): if uri.startswith('more'): page = int(uri.split('__')[2])+1 search = uri.split('__')[1] - results = self.scope.props.results_model + results = scope.props.results_model results.remove(results.get_iter_at_row(results.get_n_rows()-1)) self.update_results_model (search, results, page) return Unity.ActivationResponse(handled=Unity.HandledType.SHOW_DASH, goto_uri='') @@ -129,12 +137,8 @@ GLib.spawn_command_line_async(self.player[2] % uri[7:]) return Unity.ActivationResponse(handled=Unity.HandledType.HIDE_DASH, goto_uri='') - def get_search_string (self): - search = self.scope.props.active_search - return search.props.search_string if search else None - def on_filters_changed(self, scope): - self.scope.queue_search_changed(Unity.SearchType.DEFAULT) + scope.queue_search_changed(Unity.SearchType.DEFAULT) def on_search_changed (self, scope, search=None, search_type=0, cancellable=None): if search_type != 1: @@ -143,13 +147,12 @@ print('Search changed to %s' % search_string) model = search.props.results_model model.clear() - self.mresults = [] - self.update_results_model(search,model,1) + self.update_results_model(scope, search,model,1) if search_status: search_status.finished () - def update_results_model(self, search, model, page): - print type(search) + def update_results_model(self,scope, search, model, page): + print(type(search)) if search: if type(search) == Unity.LensSearch: search_string = search.props.search_string @@ -157,66 +160,58 @@ search_string = search else: search_string = None - if self.scope.get_filter('rating'): - select_rating = int(self.scope.get_filter('rating').props.rating*5) + else: + search_string = None + if scope.get_filter('rating'): + select_rating = int(scope.get_filter('rating').props.rating*5) else: select_rating = 0 - if self.scope.get_filter('order') and self.scope.get_filter('order').get_active_option() != None: - order_by = self.scope.get_filter('order').get_active_option().props.id + if scope.get_filter('order') and scope.get_filter('order').get_active_option() != None: + order_by = scope.get_filter('order').get_active_option().props.id else: order_by = 'viewCount' - if self.scope.get_filter('hd') and self.scope.get_filter('hd').get_active_option() != None: - if self.scope.get_filter('hd').get_active_option().props.id == 'true': + if scope.get_filter('hd') and scope.get_filter('hd').get_active_option() != None: + if scope.get_filter('hd').get_active_option().props.id == 'true': hd_option = True else: hd_option = False else: hd_option = False - if self.scope.get_filter('3d') and self.scope.get_filter('3d').get_active_option() != None: - if self.scope.get_filter('3d').get_active_option().props.id == 'true': + if scope.get_filter('3d') and scope.get_filter('3d').get_active_option() != None: + if scope.get_filter('3d').get_active_option().props.id == 'true': d3_option = True else: d3_option = False else: d3_option = False - if self.scope.get_filter('duration') and self.scope.get_filter('duration').get_active_option() != None: - duration_option = self.scope.get_filter('duration').get_active_option().props.id + if scope.get_filter('duration') and scope.get_filter('duration').get_active_option() != None: + duration_option = scope.get_filter('duration').get_active_option().props.id + print(duration_option) else: duration_option = None - if self.scope.get_filter('time') and self.scope.get_filter('time').get_active_option() != None: - from_time = self.scope.get_filter('time').get_active_option().props.id + if scope.get_filter('time') and scope.get_filter('time').get_active_option() != None: + from_time = scope.get_filter('time').get_active_option().props.id else: from_time = 'all_time' categories = [] try: - for option in self.scope.get_filter('categories').options: + for option in scope.get_filter('categories').options: if option.props.active: categories.append(option.props.id) except: categories = [] - print('search %s'%search_string) - print('categories %s'%categories) - print('Order by %s'%order_by) - print('From time %s'%from_time) - print('Rating %s'%select_rating) - self.player = self.preferences.get_active_viewer() - print('#########################################################') - print(self.player[0]) - print(self.player[1]) - print(self.player[2]) result = None for result in youtubeapi.searh_for_videos(search = search_string, page = page, categories = categories, orderby = order_by, time = from_time, rating = select_rating, duration = duration_option, hd = hd_option, d3 = d3_option): full_stars = result['rating'] empty_stars = 5 - full_stars - stars = (u"\u2605" * full_stars) + (u"\u2606" * empty_stars)+'\n' + stars = ("\u2605" * full_stars) + ("\u2606" * empty_stars)+'\n' comment =stars + result['description'] - model.append ('player:'+result['player'], result['icon'], 0,'text/html', result['title'], comment, result['player']) - self.mresults.append(result) + model.append ('player:'+result['player'], result['icon'], 0,'text/html', result['title'], comment, json.dumps(result)) if result: if not search: search = '' model.append ('more__'+search_string+'__'+str(page), 'add', 0,'text/html', 'More results', '', '') - model.flush_revision_queue () + model.flush_revision_queue() if search and type(search) == Unity.LensSearch: search.finished() @@ -234,7 +229,7 @@ result = result.unpack()[0] if result != 1 : - print >> sys.stderr, 'Failed to own name %s. Unity-Scope-YouTube is working.' % BUS_NAME + print ('Failed to own name %s. Unity-Scope-YouTube is working.' % BUS_NAME) raise SystemExit (1) daemon = Daemon() diff -Nru scope-youtube-0.0.4.5/src/youtubeapi.py scope-youtube-0.0.4.6/src/youtubeapi.py --- scope-youtube-0.0.4.5/src/youtubeapi.py 2012-10-07 19:25:21.000000000 +0000 +++ scope-youtube-0.0.4.6/src/youtubeapi.py 2013-01-03 11:53:47.000000000 +0000 @@ -1,4 +1,4 @@ -#! /usr/bin/python +#!/usr/bin/python # -*- coding: utf-8 -*- # __author__='atareao' @@ -24,10 +24,23 @@ # # # - +import sys import requests import json +if sys.version_info[0] == 3: + import urllib.request as urllib2 +else: + import urllib2 + + +def internet_on(): + try: + response=urllib2.urlopen('http://google.com',timeout=1) + return True + except: + pass + return False URL = 'http://gdata.youtube.com/feeds/api/standardfeeds/most_popular?v=2&alt=json' def read_from_url(url): @@ -42,6 +55,8 @@ RECORDS_PER_PAGE = 10 def searh_for_videos(search = None, page = 1, categories = [], orderby = 'viewCount', time = 'all_time', rating = 0, hd = False, duration = None, d3 = False): + if not internet_on(): + return [] ''' duration: short - Only include videos that are less than four minutes long. @@ -58,6 +73,8 @@ this_month (1 month) all_time ''' + if search is None: + search = '' if len(categories)>0: joined_categories = '/'.join(categories) url = 'https://gdata.youtube.com/feeds/api/videos/-/'+joined_categories @@ -77,7 +94,7 @@ print('Url: %s'%url) ans = read_from_url(url) results = [] - if 'feed' in ans.keys(): + if ans and 'feed' in ans.keys(): if 'entry' in ans['feed'].keys(): for item in ans['feed']['entry']: result = {} @@ -173,6 +190,6 @@ return results if __name__ == '__main__': - for result in searh_for_videos('Prueba',page=2,rating=4,categories = ['Tech'],hd=True): - print result['title'],result['player'],result['author'],result['thumbnail'] + for result in searh_for_videos(None,page=2,rating=4,categories = ['Tech'],hd=True): + print(result['title'],result['player'],result['author'],result['thumbnail']) exit(0)