Package: talklib
talklibA package to automate processing of shows/segments airing on the TLSkip to ExamplesTHIS README IS INTENDED TO ASSIST TL STAFF IN INSTALLING AND USING THIS PACKAGEUse this module to process the following types of shows/segments:Shows and segments we receive via RSS feedShows such as New York Times, Wall Street Journal,  etc.Segments such as Health in a Heartbeat, Academic Minute, etc.Segments we receive via "permalink"Such as PNS, Cirrus, etc.Segments downloaded locally ahead of timeSuch as Sound Beat, Animal Airwaves, etc.Requirements-PythonUse Python 3.10.1 or above.-FFmpegYou need Windows binaries for FFmpeg & FFprobe installed on the PC and added to the PATH:To repeat,this package will not work without FFmpeg and FFprobe.FFmpeg and FFprobe should be two separate binaries.-TwilioTwilio is used for SMS and phone call notifications.Access our TL Twilio info (token, etc.) bylogging into Twilio.Seebelowfor how to disable Twilio.-Environment VariablesSeveral global variables used here are pulled from environment variables. This gives the module more portability, and keeps sensitive info separated.The entire list of these is in the ev.py file. Make sure to set all of these on your PC(s). They are case-sensitive!InstallationOpen a terminal/command promptRunpip install talklib. That's it!Depending on your OS, instead ofpipyou may need to usepip3This will install the package globally. If you're a TL user just trying to install the package for everyday use, that's likely what you want to do. If you want to install it locally (for testing, etc.), see thedevelopmentsection below.If you already have it installed and need to update it to the newest version, runpip install --upgrade talklibAbout WireReadyBefore we begin, a general note:We run most of our Python scripts via WireReady (WR)The "Run" command in WR defaults to running from a different directory AND a different drive letter. This causes confusion.WR also does not run.pyfiles by default.These are some of the reasons why we do not run.pyfiles directly from WR.Instead, we tell WR to run a Batch script (.batfile) which in turn will run the Python script (.pyfile).Ensure the Batch & Python scripts are in the same directory.A sample.batfile (Example.bat) is included in this repo.PLEASE NOTE: the.batfile will run all Python files in the folder. This is one reason it is best to separate your Python files into different folders, each with its own.batfile.Here is what an example directory structure should look like:D:\wireready
    \Washington Post
        -WP.bat
        -WP.pyYou would tell WR to run theWP.batfile, which would run theWP.pyfile.UsageSkip to ExamplesTLShowis the main class to use.Import the class to your script like this:from talklib import TLShowThis is also fine:from talklib.show import TLShowCreate an instance like this:example = TLShow()Available Attributeshere is a list of all the attributes, along with their type and whether they are required.showstringrequiredThis is the name of the programMostly used for notifications, etc.show_filenamestringrequiredthe filename of the programdo NOT include a trailing dash-OR a file extension.wav. use the base name onlyurlstringrequired for all RSS or permalink showsURL for the RSS feed OR the permalinkensure there is not a trailing forward slash/at the end of the URLcorrect: 'https://somesite.org/wpfeed.rss'incorrect: 'https://somesite.org/wpfeed.rss/'is_localbooleanrequiredfor "local" showstells the module whether this is a local showmust be set toTrueif it is a local showdefault isFalselocal_filestringrequired for "local" showspath to the local file as such:D:\path\to\the\show.wavyou will probably not have a hardcoded path here. Usually, you will be running a short algorithm to determine the path. Please see theMISCrepo for some examples.is_permalinkbooleanrequired for "permalink" showsmust be set toTruefor permalink showsdefault isFalseremove_yesterdaybooleanoptionalwhether or not you want to remove yesterday's files (if any exists)if set toTrue, it will delete any file matching the show_filename attribute you set.default isFalse.include_datebooleanoptionalwhether or not you want to include today's date in the filenameif set toTrue, the date will be appended as such:WP-MMDDYY.wavif not set, or set toFalse, the resulting filename will be:WP.wavGenerally, for TL programs, if it is a daily show, like the New York Times, etc., you need the date in the filename, as this is what WireReady will match.the default isFalsecheck_if_aboveandcheck_if_belownumberoptionalthese are for checking whether the length of the program (in minutes!) falls outside a rangeused strictly for notification purposesif these are not set, the checks will not be runagain, these values are inminutes, not secondscurrently, if you set one of these, you must set both of them. All or nothing.remove_sourcebooleanoptionalwhether you want to remove/delete the original source file after processingapplies only to local showsdefault isFalsenotificationsobjectoptionalthis is its own object with the following attributes:syslog_enabletwilio_enableemail_enableto disable any one of these, set them like this:object.notifications.twilio_enable = Falsedefault for all of them isTruemoreexamplesbelowffmpegobjectthis is its own object with various attributes. The ones you might want to change arebreakawayandcompression_levelbreakawayif you only want to convert/output the audio file up to a certain point, set this to the number of seconds at which point you want it to stop.change it like this:object.ffmpeg.breakaway = 120. This will cut the audio at 2 minutes.again, this number is in seconds (not minutes)perhaps the only time you need to set this is for shows like PNS where there is an expected "breakaway" time.default is to convert the entire filecompression_levelsets the level for FFmpeg's compression/normalizationthis is the EBU R128 LUFS "integrated loudness" standardchange it like this:object.ffmpeg.compression_level = 18the smaller the number, the more compression is applied (17 is more compressed than 18)the max is 5 (do not set to 1, 2, 3, or 4)!be careful with this!default is 21Notes about formatting:if you're new to Python, here're some remindersstringmust be enclosed in quotes (single or double; Python doesn't care)booleaneither True or Falsedo not enclose in quotesmust be capitalizedcorrect: Trueincorrect: truenumberin our case, these can be either type int OR float, meaning either whole numbers OR decimal numbers are allowedOK: 5also OK: 5.4do not enclose in quotesMethodsrun()requiredexecutes the script with the attributes you setshould be the last line in your scriptthis should be the only method/function you call directly from an outside script. Even if your IDE shows you all the available methods, please ignore them as most of them are not (yet) designed to be called directly.ExamplesRSS ExampleThe minimum attributes you must set areshow,show_filename, andurl.Here is an example script:fromtalklibimportTLShowSD=TLShow()SD.show='Skywalker Daily News'SD.show_filename='SDN'SD.url='https://somesite.org/sdn-feed.rss'# these are optionalSD.remove_yesterday=TrueSD.check_if_above=59SD.check_if_below=55SD.run()Local Example"Local" shows are shows whose files we already have downloaded ahead of time.The minimum attributes you must set are:show,show_filename,is_local, andlocal_file.Here is an example script:fromtalklibimportTLShowMWB=TLShow()MWB.show='Magical World of Bees'MWB.show_filename='MWB'MWB.is_local=TrueMWB.local_file='D:Production\path\to\the\file.wav'# these are optionalMWB.remove_source=TrueMBW.twilio_enable=FalseMWB.run()Permalink Example"Permalink" shows are shows whose audio URL does not change, E.G. PNS & CirrusThe minimum attributes you must set are:show,show_filename,url, andis_permalink.Here is an example script:fromtalklibimportTLShowWK=TLShow()WK.show='Who Knows'WK.show_filename='WhoKnows'WK.url='https://somesite.org/who-knows-static'WK.is_permalink=True# these are optionalWK.notifications=FalseWK.include_date=TrueWK.run()Misc. ExamplesHere are some examples of how to access/modify certain attributes.Disable TwilioTo disable Twilio notifications, simply add a line like this:fromtalklibimportTLShowSD=TLShow()SD.show='Skywalker Daily News'SD.show_filename='SDN'SD.url='https://somesite.org/sdn-feed.rss'SD.notifications.twilio_enable=FalseSD.run()Adjust FFmpeg compressionTo adjust the level of compression applied with FFmppeg, add a line like this:fromtalklibimportTLShowSD=TLShow()SD.show='Skywalker Daily News'SD.show_filename='SDN'SD.url='https://somesite.org/sdn-feed.rss'SD.ffmpeg.compression_level=18SD.run()DevelopmentClone this repositorygit clone https://github.com/talkinglibrary/talklib.gitcd into the foldercd talklibCreate a virtual environmentpy -m venv venvdepending on your OS, instead ofpyyou may need to usepythonorpython3Activate virtual environmentOn Windows:venv\Scripts\activateOn Mac:source venv/bin/activateUpdate pippy -m pip install --upgrade pipdepending on your OS, instead ofpipyou may need to runpip3Install the package into your virtual environmentpip install -e .Run PytestpytestThe tests can take a while to run. Watch the terminal output for progress.If the tests fail, you may have installed something incorrectly.You must be connected to the internet to run the tests