Académique Documents
Professionnel Documents
Culture Documents
You should have received a copy of the GNU General Public License
along with this program. If not, see <http: licenses="" www.gnu.org="">.
"""
########################
#### SETTINGS BELOW ####
########################
# this is the path to your android/mp3 player music folder once mounted.
# the converted files will be placed here.
#
destination_root = r"f:\Music"
# this is the path to your android/mp3 player playlist folder. m3u files will
# place here.
#
playlist_root = r"f:\Music\Playlists"
# this is how many path levels including your source audio file are synced to the
# device. i.e. artist/album/audio file
#
path_depth = 3
####################
#### CODE BELOW ####
####################
tag_list =
["Author","Title","UserRating","UserServiceRating","WM/AlbumArtist","WM/AlbumTitle"
,
"WM/Category","WM/Composer","WM/Conductor","WM/ContentDistributor","WM/ContentGroup
Description",
"WM/EncodingTime","WM/Genre","WM/GenreID","WM/InitialKey","WM/Language","WM/Lyrics"
,"WM/MCDI",
"WM/MediaClassPrimaryID","WM/MediaClassSecondaryID","WM/Mood","WM/ParentalRating","
WM/Period",
"WM/ProtectionType","WM/Provider","WM/ProviderRating","WM/ProviderStyle","WM/Publis
her",
"WM/SubscriptionContentID","WM/SubTitle","WM/TrackNumber","WM/UniqueFileIdentifier"
,
"WM/WMCollectionGroupID","WM/WMCollectionID","WM/WMContentID","WM/Writer","WM/Year"
]
log = getLogger("Foobar.MP3PlayerSync")
log.setLevel(DEBUG)
lh = StreamHandler()
lh.setFormatter(Formatter("%(levelname)s|%(asctime)s|%(filename)s:%(lineno)d|%
(message)s"))
log.addHandler(lh)
prog_id = "Foobar2000.Application.0.7"
fb2k = EnsureDispatch(prog_id)
def main():
fb2k_playlists = [ i for i in fb2k.Playlists if i.Name in playlists ]
if fb2k_playlists:
for pl in fb2k_playlists:
sync_playlist(pl)
log.info("Completed Sync")
def sync_playlist(sync_playlist):
log.info("Syncing playlist '%s'..." % sync_playlist.Name)
tracks = sync_playlist.GetTracks()
m3u_lines = ["#EXTM3U"]
for t in tracks:
m3u_lines.append(t.FormatTitle("#EXTINF:%length_seconds%, %artist% - %title
%"))
source_path = urlparse(t.Path).netloc
m3u_lines.append(sync_file(source_path))
create_m3u(sync_playlist.Name, m3u_lines)
def sync_file(source_path):
parts_all = source_path.split(sep)
parts = parts_all[-path_depth:]
filenameext = parts[path_depth-1]
(filename, ext) = splitext(filenameext)
parts_new_path = [destination_root]
parts_new_path.extend(parts[0:path_depth-1])
destination_folder = sep.join(parts_new_path)
parts_new_path.append(filename + destination_ext)
destination_path = sep.join(parts_new_path)
if not exists(destination_folder):
log.info("Creating folder: '%s'..." % destination_folder)
makedirs(destination_folder)
if not exists(destination_path):
convert_file(source_path, destination_path)
return destination_path
of_m.setItemInfo(tag, if_m.getItemInfo(tag))
if __name__ == "__main__":
main()
</http:>