def removeFromPlaylist(video): OmniUtil.validStart() gdataResults = OmniUtil.gdataLoad(OmniUtil.BASE_PLAYLIST_FEED % OmniUtil.__urlParse__(selectPlaylist('Remove <%s> from which playlist?' % video)).query.split('=')[1]) if gdataResults: for i in gdataResults: if i['media$group']['yt$videoid']['$t'] == OmniUtil.__urlParse__(video).query.split('=')[1].split('&')[0]: for j in i['link']: if j['rel'] == 'self': requests.delete(j['href'], data = '', headers = OmniUtil.postLoad()) OmniUtil.displayNotification(OmniUtil.TITLE, 'Removed video from playlist', '', '') else: OmniUtil.cocoaMsgBox('Could not delete video from playlist', 'Sorry, but an error occured during the deletion process.', '%sWarning.png' % OmniUtil.ICONS)
def addToPlaylist(video): OmniUtil.validStart() if video[0] == "'": video = video[1:-1] postLoad = OmniUtil.postLoad() postLoad['Content-Length'] = '1' requests.post( OmniUtil.BASE_PLAYLIST_FEED % OmniUtil.__urlParse__( selectPlaylist( 'Add <%s> to which playlist?' % video)).query.split('=')[1], data= '<?xml version="1.0" encoding="UTF-8"?>\n<entry xmlns="http://www.w3.org/2005/Atom"\n\txmlns:yt="http://gdata.youtube.com/schemas/2007">\n<id>%s</id>\n<yt:position>1</yt:position>\n</entry>' % OmniUtil.__urlParse__(video).query.split('=')[1].split('&')[0], headers=postLoad) OmniUtil.displayNotification(OmniUtil.TITLE, 'Added video to playlist', '', '')
def removePlaylist(query): OmniUtil.validStart() playlistId = OmniUtil.__urlParse__(query).query.split('=')[1] query = '%s/%s' % (OmniUtil.BASE_USER_PLAYLIST, playlistId) if OmniUtil.cocoaYesNoBox('Deleting Playlist!', 'Are you sure you want to delete this playlist?', '%sWarning.png' % OmniUtil.ICONS): requests.delete(query, data = '', headers = OmniUtil.postLoad()) OmniUtil.displayNotification(OmniUtil.TITLE, 'Deleted Playlist', playlistId, '')
def addWatchLater(query): OmniUtil.validStart() query = OmniUtil.__urlParse__(query).query.split('v=')[-1].split('&')[0] OmniUtil.postLoad()['Content-Length'] = '1' requests.post(OmniUtil.BASE_WATCHLATER, data = '<?xml version="1.0" encoding="UTF-8"?>\n<entry xmlns="http://www.w3.org/2005/Atom"\nxmlns:yt="http://gdata.youtube.com/schemas/2007">\n<id>%s</id>\n<yt:position>1</yt:position>\n</entry>' % query, headers = OmniUtil.postLoad()) OmniUtil.displayNotification(OmniUtil.TITLE, 'Added to Watch Later', '', '')
def addFavorite(query): OmniUtil.validStart() query = OmniUtil.__urlParse__(query).query.split('v=')[-1].split('&')[0] OmniUtil.postLoad()['Content-Length'] = '1' requests.post(OmniUtil.BASE_FAVORITES, data = '<?xml version="1.0" encoding="UTF-8"?>\n<entry xmlns="http://www.w3.org/2005/Atom">\n<id>%s</id>\n</entry>' % query, headers = OmniUtil.postLoad()) OmniUtil.displayNotification(OmniUtil.TITLE, 'Added to Favorites', '', '')
def addToPlaylist(video): OmniUtil.validStart() if video[0] == "'": video = video[1:-1] postLoad = OmniUtil.postLoad() postLoad['Content-Length'] = '1' requests.post(OmniUtil.BASE_PLAYLIST_FEED % OmniUtil.__urlParse__(selectPlaylist('Add <%s> to which playlist?' % video)).query.split('=')[1], data = '<?xml version="1.0" encoding="UTF-8"?>\n<entry xmlns="http://www.w3.org/2005/Atom"\n\txmlns:yt="http://gdata.youtube.com/schemas/2007">\n<id>%s</id>\n<yt:position>1</yt:position>\n</entry>' % OmniUtil.__urlParse__(video).query.split('=')[1].split('&')[0], headers = postLoad) OmniUtil.displayNotification(OmniUtil.TITLE, 'Added video to playlist', '', '')
def removeWatchLater(query): OmniUtil.validStart() gdataResults = OmniUtil.gdataLoad(OmniUtil.BASE_WATCHLATER) if gdataResults: for i in gdataResults: if i['media$group']['yt$videoid']['$t'] == OmniUtil.__urlParse__(query).query.split('v=')[-1].split('&')[0]: query = i['id']['$t'].split(':')[-1] requests.delete('%s/%s' % (OmniUtil.BASE_FAVORITES, query), data = '', headers = OmniUtil.postLoad()) OmniUtil.displayNotification(OmniUtil.TITLE, 'Removed from Watch Later', '', '') else: OmniUtil.displayNotification(OmniUtil.TITLE, 'Could not remove from "Watch Later"', '<unkown error occured>', '')
def addFavorite(query): OmniUtil.validStart() query = OmniUtil.__urlParse__(query).query.split('v=')[-1].split('&')[0] OmniUtil.postLoad()['Content-Length'] = '1' requests.post( OmniUtil.BASE_FAVORITES, data= '<?xml version="1.0" encoding="UTF-8"?>\n<entry xmlns="http://www.w3.org/2005/Atom">\n<id>%s</id>\n</entry>' % query, headers=OmniUtil.postLoad()) OmniUtil.displayNotification(OmniUtil.TITLE, 'Added to Favorites', '', '')
def removePlaylist(query): OmniUtil.validStart() playlistId = OmniUtil.__urlParse__(query).query.split('=')[1] query = '%s/%s' % (OmniUtil.BASE_USER_PLAYLIST, playlistId) if OmniUtil.cocoaYesNoBox( 'Deleting Playlist!', 'Are you sure you want to delete this playlist?', '%sWarning.png' % OmniUtil.ICONS): requests.delete(query, data='', headers=OmniUtil.postLoad()) OmniUtil.displayNotification(OmniUtil.TITLE, 'Deleted Playlist', playlistId, '')
def addWatchLater(query): OmniUtil.validStart() query = OmniUtil.__urlParse__(query).query.split('v=')[-1].split('&')[0] OmniUtil.postLoad()['Content-Length'] = '1' requests.post( OmniUtil.BASE_WATCHLATER, data= '<?xml version="1.0" encoding="UTF-8"?>\n<entry xmlns="http://www.w3.org/2005/Atom"\nxmlns:yt="http://gdata.youtube.com/schemas/2007">\n<id>%s</id>\n<yt:position>1</yt:position>\n</entry>' % query, headers=OmniUtil.postLoad()) OmniUtil.displayNotification(OmniUtil.TITLE, 'Added to Watch Later', '', '')
def getPlaylistFeed(query): OmniUtil.validStart() feed = OmniUtil.Feedback() gdataResults = OmniUtil.gdataLoad(OmniUtil.BASE_PLAYLIST_FEED % OmniUtil.__urlParse__(query).query.split('=')[1]) if gdataResults: for i in gdataResults: feed.add_item(i['title']['$t'], '%s - %s' % (i['media$group']['media$credit'][0]['yt$display'], OmniUtil.secondsToHuman(int(i['media$group']['yt$duration']['seconds']))), 'http://www.youtube.com/watch?v=%s' % i['media$group']['yt$videoid']['$t'], '', '', '%sListBlock.png' % OmniUtil.ICONS) else: feed.add_item('No Results', 'No feed results for "%s" could be found' % query, '', '', '', '%sX.png' % OmniUtil.ICONS) return feed
def getChannelFeed(query): OmniUtil.validStart() feed = OmniUtil.Feedback() gdataResults = OmniUtil.gdataLoad(OmniUtil.BASE_USER_UPLOADS % OmniUtil.__urlParse__(query).path.split('/')[-1], param1 = {'orderby':'published'}) if gdataResults: for i in gdataResults: feed.add_item(i['title']['$t'], '%s - %s' % (i['media$group']['media$credit'][0]['yt$display'], OmniUtil.secondsToHuman(int(i['media$group']['yt$duration']['seconds']))), 'http://www.youtube.com/watch?v=%s' % i['media$group']['yt$videoid']['$t'], '', '', '%sListBlock.png' % OmniUtil.ICONS) else: feed.add_item('No Results', 'No feed results for "%s" could be found' % query, '', '', '', '%sX.png' % OmniUtil.ICONS) return feed
def removeFromPlaylist(video): OmniUtil.validStart() gdataResults = OmniUtil.gdataLoad( OmniUtil.BASE_PLAYLIST_FEED % OmniUtil.__urlParse__( selectPlaylist('Remove <%s> from which playlist?' % video)).query.split('=')[1]) if gdataResults: for i in gdataResults: if i['media$group']['yt$videoid']['$t'] == OmniUtil.__urlParse__( video).query.split('=')[1].split('&')[0]: for j in i['link']: if j['rel'] == 'self': requests.delete(j['href'], data='', headers=OmniUtil.postLoad()) OmniUtil.displayNotification( OmniUtil.TITLE, 'Removed video from playlist', '', '') else: OmniUtil.cocoaMsgBox( 'Could not delete video from playlist', 'Sorry, but an error occured during the deletion process.', '%sWarning.png' % OmniUtil.ICONS)
def removeWatchLater(query): OmniUtil.validStart() gdataResults = OmniUtil.gdataLoad(OmniUtil.BASE_WATCHLATER) if gdataResults: for i in gdataResults: if i['media$group']['yt$videoid']['$t'] == OmniUtil.__urlParse__( query).query.split('v=')[-1].split('&')[0]: query = i['id']['$t'].split(':')[-1] requests.delete('%s/%s' % (OmniUtil.BASE_FAVORITES, query), data='', headers=OmniUtil.postLoad()) OmniUtil.displayNotification(OmniUtil.TITLE, 'Removed from Watch Later', '', '') else: OmniUtil.displayNotification(OmniUtil.TITLE, 'Could not remove from "Watch Later"', '<unkown error occured>', '')
def getPlaylistFeed(query): OmniUtil.validStart() feed = OmniUtil.Feedback() gdataResults = OmniUtil.gdataLoad( OmniUtil.BASE_PLAYLIST_FEED % OmniUtil.__urlParse__(query).query.split('=')[1]) if gdataResults: for i in gdataResults: feed.add_item( i['title']['$t'], '%s - %s' % (i['media$group']['media$credit'][0]['yt$display'], OmniUtil.secondsToHuman( int(i['media$group']['yt$duration']['seconds']))), 'http://www.youtube.com/watch?v=%s' % i['media$group']['yt$videoid']['$t'], '', '', '%sListBlock.png' % OmniUtil.ICONS) else: feed.add_item('No Results', 'No feed results for "%s" could be found' % query, '', '', '', '%sX.png' % OmniUtil.ICONS) return feed
def getChannelFeed(query): OmniUtil.validStart() feed = OmniUtil.Feedback() gdataResults = OmniUtil.gdataLoad( OmniUtil.BASE_USER_UPLOADS % OmniUtil.__urlParse__(query).path.split('/')[-1], param1={'orderby': 'published'}) if gdataResults: for i in gdataResults: feed.add_item( i['title']['$t'], '%s - %s' % (i['media$group']['media$credit'][0]['yt$display'], OmniUtil.secondsToHuman( int(i['media$group']['yt$duration']['seconds']))), 'http://www.youtube.com/watch?v=%s' % i['media$group']['yt$videoid']['$t'], '', '', '%sListBlock.png' % OmniUtil.ICONS) else: feed.add_item('No Results', 'No feed results for "%s" could be found' % query, '', '', '', '%sX.png' % OmniUtil.ICONS) return feed