Package: ibroadcast
iBroadcast Python clientThis Python package provides a client for working with youriBroadcastmusic collection.SetupStable versionTo install the latest release into your local environment:pip install ibroadcastDevelopment versionTo install the latest development version from source:git clone https://github.com/ctrueden/ibroadcast-python
cd ibroadcast-python
pip install -e .UsageConnectTo connect to iBroadcast, create anibroadcast.iBroadcastobject with your
login credentials:>>>importibroadcast>>>username='chuckles@example.com'>>>password='HappyClown123'>>>ib=ibroadcast.iBroadcast(username,password)Query tracksTrack data can be found inib.tracks.Here is an example that lists tracks from the year 1984:>>>frompprintimportpprint>>>tracks_from_1984=[trackfor(trackid,track)inib.tracks.items()iftrack['year']==1984]>>>pprint(tracks_from_1984)[{'album_id':49436760,'artist_id':17407280,'artwork_id':1892638,'enid':0,'file':'/128/a8b/567/150924731','genre':'Pop','length':205,'path':'music/Artists/Kansas/(1984) The Best of Kansas','plays':1,'rating':0,'replay_gain':'0.5','size':3572231,'title':'Dust in the Wind','track':4,'trashed':False,'type':'audio/mpeg3','uid':'','uploaded_on':'2020-12-10','uploaded_time':'16:09:59','year':1984},{'album_id':49438358,'artist_id':17407663,'artwork_id':465315,'enid':0,'file':'/128/962/d79/150926596','genre':'New Wave, Post-Punk, Rock, Funk','length':307,'path':'music/Artists/Talking Heads/(1984) Stop Making Sense','plays':1,'rating':0,'replay_gain':'0.8','size':6510922,'title':'Girlfriend Is Better','track':5,'trashed':False,'type':'audio/mpeg3','uid':'','uploaded_on':'2020-12-10','uploaded_time':'16:14:56','year':1984}]Query albumsAlbum data can be found inib.albums.Here is an example that lists albums from the year 1984:>>>albums_from_1984=[albumfor(albumid,album)inib.albums.items()ifalbum['year']==1984]>>>pprint(albums_from_1984)[{'artist_id':17407663,'disc':1,'name':'Stop Making Sense','rating':0,'tracks':[189817292],'trashed':False,'year':1984},{'artist_id':17407280,'disc':1,'name':'The Best of Kansas','rating':0,'tracks':[189815191],'trashed':False,'year':1984}]Query artistsArtist data can be found inib.artists.Here is an example that lists artists with more than 170 tracks:>>>[artist['name']forartistinib.artists.values()iflen(artist['tracks'])>=170]['Scooter','Megadeth','Bad Religion','Metallica','Green Day']Query playlistsPlaylist data can be found inib.playlists.Here is an example that lists the names of all playlists:>>>[playlist['name']forplaylistinib.playlists.values()]['Jonathan Hall','Army of Hardcore','Most Recent Uploads','Recently Played','Stand Up','Roads Untraveled','The Storm','Thumbs Up']Here's an example that lists the track names of a particular playlist:>>>deftrack2string(ib,track):...title=track['title']...artistid=track['artist_id']...artist=ib.artist(artistid)...returnf"{artist['name']}-{title}"...>>>thumbsup=next(plforplinib.playlists.values()ifpl['name']=='Thumbs Up')>>>fortrackidinthumbsup['tracks']:...track=ib.track(trackid)...print(track2string(ib,track))...OzzyOsbourne-IDon't KnowELLEGARDEN-Mr.FeatherTheDreaming-BecomeLikeYouRMB-Everything(Can't Hide version)LinkinPark-TheCatalystBreatheCarolina-BlackoutLadyGaga-SwineAdamLambert-FeelingGoodVirtualRiot-EnergyDrinkJimYosef-LinkMDK-HyperBeamHybrid-IKnowQuery tagsTag data can be found inib.tags.Here is an example that lists all tracks tagged "favorites" from 2010 or later:>>>favorite_trackids=next(tag['tracks']fortaginib.tags.values()iftag['name']=='favorites')>>>fortrackidinfavorite_trackids:...track=ib.track(trackid)...year=track['year']...ifyear<2010:continue...print(f"[{year}]{track2string(ib,track)}")...[2010]BadReligion-OnlyRain[2016]GreenDay-StillBreathing[2012]TheOffspring-DirtyMagic[2012]ImagineDragons-Radioactive[2013]AllTimeLow-Fool's Holiday[2013]MichaelBublé-It's a Beautiful Day[2010]KerryEllis-DefyingGravity[2010]GleeCast-DefyingGravity[2013]KristenAnderson‐Lopez&RobertLopez-LetItGo[2014]TheGlitchMobfeat.AjaVolkman-OurDemons[2012]GreatBigSea-RunRunaway[2010]AndrewLippa-Happy/SadAvailable iBroadcast API methods>>>help(ib)HelponiBroadcastinmoduleibroadcastobject:classiBroadcast(builtins.object)|iBroadcast(username,password,log=None,client='ibroadcast-python',version='1.1.0')||ClassformakingiBroadcastrequests.||Adaptedfromibroadcast-uploader.pyat<https://project.ibroadcast.com/>.||Methodsdefinedhere:||__init__(self,username,password,log=None,client='ibroadcast-python',version='1.1.0')|Initializeself.Seehelp(type(self))foraccuratesignature.||addtracks(self,playlistid,trackids)|Addtrackstothegivenplaylist.||Unlikesettracks,thisoperationwillappendto,notoverwrite,|theplaylist's tracks.||:paramplaylistid:IDoftheplaylisttoupdate.|:paramtrackids:ListofIDsforthetrackstobeadded.||Raises:|ServerErroronproblemupdatingtheplaylist||album(self,albumid)|GetthealbumobjectwiththegivenID.||:paramalbumid:IDofthealbumtoretrieve.|:return:Thealbumobject.||artist(self,artistid)|GettheartistobjectwiththegivenID.||:paramartistid:IDoftheartisttoretrieve.|:return:Theartistobject.||createplaylist(self,name,description='',sharable=False,mood=None)|Createaplaylist.||:paramname:Nameoftheplaylisttocreate.|:paramdescription:Descriptionoftheplaylist.|:paramsharable:Whethertomaketheplaylistsharableandpubliclyviewable.|:parammood:Moodtouseforautopopulatingtracks:|None,Party,Dance,Workout,Relaxed,orChill.|:return:IDofnewlycreatedplaylist.||Raises:|ServerErroronproblemcreatingtheplaylist||createtag(self,tagname)|Createatag.||:paramtagname:Nameofthetagtocreate.|:return:IDofnewlycreatedtag.||Raises:|ServerErroronproblemcreatingthetag||deleteplaylist(self,playlistid)|Deleteaplaylist.||:paramplaylistid:IDoftheplaylisttodelete.||Raises:|ServerErroronproblemdeletingtheplaylist||extensions(self)|Getfileextensionsforsupportedaudioformats.||gettags(self,trackid)|Getthetagsforthegiventrack.||:paramtrackid:IDofthetrackinquestion.|:return:ListoftagIDs.||istagged(self,tagid,trackid)|Getwhetherthespecifiedtrackhasthegiventag.||:paramtagid:IDofthetaginquestion.|:paramtrackid:IDofthetrackinquestion.|:return:Trueiffthetrackistaggedwiththattag.||isuploaded(self,filepath)|GetwhetheragivenfileisalreadyuploadedtotheiBroadcastserver.||:paramfilepath:Pathtothefiletocheck.||Raises:|ServerErroronproblemdownloadingremoteMD5checksums||playlist(self,playlistid)|GettheplaylistobjectwiththegivenID.||:paramplaylistid:IDoftheplaylisttoretrieve.|:return:Theplaylistobject.||refresh(self)|Downloadlibrarydata:albums,artists,tracks,etc.||Raises:|ServerErroronproblemcompletingtherequest||settracks(self,playlistid,trackids)|Updatethegivenplaylisttoconsistofthespecifiedtracks.||Unlikeaddtracks,thisoperationwilloverwrite,notappendto,|theplaylist's tracks.||:paramplaylistid:IDoftheplaylisttoupdate.|:paramtrackids:ListofIDsfortheplaylisttracks.||Raises:|ServerErroronproblemupdatingtheplaylist||tag(self,tagid)|GetthetagobjectwiththegivenID.||:paramtagid:IDofthetagtoretrieve.|:return:Thetagobject.||tagtracks(self,tagid,trackids,untag=False)|Applyorremovethegiventagtothespecifiedtracks.||:paramtagid:IDofthetagtoapply.|:paramtrackids:ListofIDsforthetrackstotag.|:paramuntag:Iftrue,removethetagratherthanapplyingit.||Raises:|ServerErroronproblemtagging/untaggingthetracks||token(self)|Gettheauthenticationtokenforthecurrentsession.||track(self,trackid)|GetthetrackobjectwiththegivenID.||:paramtrackid:IDofthetracktoretrieve.|:return:Thetrackobject.||trash(self,trackids)|Movethegiventrackstothetrash.||:paramtrackids:ListofIDsforthetrackstotag.||Raises:|ServerErroronproblemtrashingthetracks|||upload(self,filepath,label=None,force=False)|UploadthegivenfiletoiBroadcast,ifitisn't there already.||:paramfilepath:Pathtothefileforupload.|:paramlabel:Human-readablefilestring(e.g.,withoutproblematic|specialcharacters)tousewhenloggingmessagesabout|thisoperation,orNonetousethefilepathdirectly.|:paramforce:Uploadthefileevenifchecksumisalreadypresent.|:return:TrackIDoftheuploadedfile,orNoneifnouploadoccurred.||Raises:|ServerErroronproblemcompletingtherequest||user_id(self)|Gettheuser_idforthecurrentsession.Getting helpFile an issue in theissue tracker.ContributingPRs welcome! ^.~Testing changesThis project has no unit tests, but there are integration tests.
They require a valid username and password to iBroadcast.
All of the integration tests are read-only.$pythontests/integration.py
INFO:root:PleaseenteriBroadcastcredentials:
Username:chuckles@example.com
Password:
INFO:root:Logginginaschuckles@example.com...
INFO:root:ok
INFO:root:Loginsuccessful-user_id:12345INFO:root:Downloadinglibrarydata...
INFO:root:Checked995albumstotaling5951tracks.
.INFO:root:Checked1790artiststotaling5951tracks.
...INFO:root:DownloadingMD5checksums...
INFO:root:Returninglistofmd5checksumsfromserver
.INFO:root:Checked8playliststotaling1691tracks.
.INFO:root:Checked17tagstotaling2208tracks.
INFO:root:Checked5951tracks.
..
----------------------------------------------------------------------
Ran10testsin0.567s

OK