From: Dylan Lloyd Date: Fri, 21 Jan 2011 04:01:58 +0000 (-0500) Subject: Now stores user data in ~/.i_like_pandora.config X-Git-Url: https://disinclined.org/git/?a=commitdiff_plain;h=c781e8de3d210801af58a05160e0fff12ff0b0b6;p=i_like_pandora.git Now stores user data in ~/.i_like_pandora.config Removed the option to edit the youtube-dl options because ConfigParser also uses the same syntax youtube-dl uses for it's output template option. The option is still easily edited in i_like_pandora.py in the default_options dictionary located at the top. Added a .i_like_pandora.config file to be easily moved into ~/ after changing the username, download_folder, and anything else desired. The file will work with everything missing except the username and download_folder. Updated README. --- diff --git a/.i_like_pandora.config b/.i_like_pandora.config new file mode 100644 index 0000000..5e0f651 --- /dev/null +++ b/.i_like_pandora.config @@ -0,0 +1,18 @@ +[settings] + +# Copy or move this file into ~/.i_like_pandora.config (your home folder). Lines that start with a # are ignored as comments. + +# Your username can be found by clicking "Your Profile" from http://pandora.com. You will be taken to a URL containing your username: http://pandora.com/people/ +username: my_username + +# This is the folder your music will be downloaded to. It will not be created for you. +download_folder: /home/user/pandora_music + +# On OSX this should likely be set to False, on Ubuntu, set True. Read the README for more information. +notifications: True + +# This is the default icon used for notifications if a thumbnail is unable to be fetched (which would be unusual). +default_icon: /usr/share/icons/gnome/48x48/mimetypes/gnome-mime-application-x-shockwave-flash.png + +# The following is the path to the youtube-dl executable. +youtube-dl: /usr/bin/youtube-dl diff --git a/README b/README index 63fc829..29d12db 100644 --- a/README +++ b/README @@ -1,11 +1,12 @@ -This script searches for each of your liked pandora songs and downloads the first YouTube result for "Title Artist" (some music is not avaiblable). +This script searches for each of your liked Pandora songs and downloads the first YouTube result for "Title Artist" (some music is not avaiblable). Your Pandora listening activity must be public for this script to work. You can edit your privacy settings here: http://www.pandora.com/privacysettings -This script allows you to quickly come back to all the songs you've forgotten you loved. A good way to keep up to date with your Pandora favorites is to add this script into cron and have it run daily. Remember to edit the settings in the first part of the script. +Remember to set your username and download directory in a settings file at ~/.i_like_pandora.config. A sample file should be at ./.i_like_pandora.config and available here: +http://github.com/nospampleasemam/i_like_pandora/ -You can edit your crontab with the command "crontab -e". When using this script via cron, a display must be specified to send the notifications to. Here is an example: +A good way to keep up to date with your Pandora favorites is to add this script into cron and have it run daily. You can edit your crontab with the command "crontab -e". When using this script via cron, a display must be specified to send the notifications to. Here is an example: $ crontab -e @hourly env DISPLAY=:0 python ~/path/to/likes_pandora.py @@ -26,9 +27,6 @@ See http://www.github.com/nospampleasemam/youtube_backup for more information an LICENSING ------- -This source (written by Dylan Lloyd is subject to the following copyright: - -The original source and the derived work contained here is subject to the following license: Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: diff --git a/likes_pandora.py b/likes_pandora.py index 1e838ea..181cda7 100755 --- a/likes_pandora.py +++ b/likes_pandora.py @@ -4,20 +4,40 @@ __author__ = ("Dylan Lloyd ") __license__ = "BSD" -# SETTINGS +default_options = { + 'notifications' : 'true', + # NOTIFICATIONS must be a string due to issues noted here: + # http://bugs.python.org/issue974019 + # ConfigParser.getboolean fails when falling back to the default value + # if the value type is bool. + 'youtube-dl' : '/usr/bin/youtube-dl', + 'default_icon' : '/usr/share/icons/gnome/48x48/mimetypes/gnome-mime-application-x-shockwave-flash.png', + 'youtube-dl_options' : '--no-progress --ignore-errors --continue --max-quality=22 -o "%(stitle)s---%(id)s.%(ext)s"' +} -USER = 'alphabethos' # pandora account name http://pandora.com/people/ -DIR = '/home/dylan/pandora/' # where to download the videos - will not be automatically created -YT_DL = '/usr/bin/youtube-dl' # Path to youtube-dl -NOTIFICATIONS = True # False -DEFAULT_ICON ='/usr/share/icons/gnome/48x48/mimetypes/gnome-mime-application-x-shockwave-flash.png' # for notifications -YT_OPT = '--no-progress --ignore-errors --continue --max-quality=22 -o "%(stitle)s---%(id)s.%(ext)s"' -# END OF SETTINGS +import ConfigParser # This module has been renamed to configparser in python 3.0 +import sys +import os + +CONFIG_FILE= os.path.join(os.path.expanduser('~'), '.i_like_pandora.config') +config = ConfigParser.ConfigParser(default_options) +loaded_files = config.read(CONFIG_FILE) # config.read returns an empty array if it fails. +if len(loaded_files) == 0: + print 'Can\'t find a configuration file at', CONFIG_FILE + sys.exit() +try: + USER = config.get('settings', 'username') + DIR = os.path.expanduser(config.get('settings', 'download_folder')) + NOTIFICATIONS = config.getboolean('settings', 'notifications') + YT_DL = config.get('settings', 'youtube-dl') + DEFAULT_ICON = config.get('settings', 'default_icon') +except: + print 'There is a formatting error in the configuration file at', CONFIG_FILE + sys.exit() from BeautifulSoup import BeautifulSoup import urllib import urllib2 -import os import re import copy import shlex, subprocess @@ -63,7 +83,10 @@ def fetch_tracks(stations): search_strings.append(search_string) i += 1 else: - pass ## ERROR + # This would mean something strange has happened: there + # aren't the same number of titles and artist names on a + # station page. + pass return search_strings def search_youtube(search_strings): @@ -141,11 +164,10 @@ def fetch_videos(video_list): note = pynotify.Notification(title, 'video downloaded', thumbnail) note.show() - def main(): stations = fetch_stations(USER) if len(stations) == 0: - print 'are you sure your pandora profile is public?' + print 'Are you sure your pandora profile is public? Can\'t seem to find any stations listed with your account.' search_strings = fetch_tracks(stations) videos = search_youtube(search_strings) videos = check_for_existing(videos)