From: Audiodef O. <on...@au...> - 2012-06-29 20:30:48
|
Thanks for sharing that. That actually looks pretty straightforward and helped me understand how to write such things. Once I looked up some stuff and played around with it for a while, this is what I ended up with: main.liq: #!/usr/local/bin/liquidsoap -t set("log.file.path","/home/audiodef/radio/liquidradio.log") set("log.level",4) # Metadata elements are: # title, temporary, decoder, artist, kind, rid, on_air, tracknumber, # initial_uri, source, year, status, filename, comment, genre # initial_uri provides the URL currently being played from the playlist def append_artist(m) = artist = m["artist"] real_uri = m["initial_uri"] real_artist=get_process_output("/home/audiodef/radio/./get_artist.php #{real_uri}") if artist == "" then [("artist","Synthetronica Radio: #{real_artist}")] else [("artist","Synthetronica Radio: #{artist}")] end end def append_title(m) = title = m["title"] real_uri = m["initial_uri"] real_title=get_process_output("/home/audiodef/radio/./get_title.php #{real_uri}") if title == "" then [("title","#{real_title}")] else [("title","#{title}")] end end main_radio=mksafe(playlist(timeout=3600.,conservative=true,"http://synthetronica/radio/playlist/main_playlist")) main_radio = map_metadata(append_artist, main_radio) main_radio = map_metadata(append_title, main_radio) output.icecast(%vorbis(quality=0.6,samplerate=44100), host="localhost", port=8000, password="(password)", mount="radio.ogg", name="Synthetronica Radio", description="Eclectic Electronica", genre="Electronic", url="synthetronica", main_radio) get_title.php: #!/usr/bin/php <?php $argv = $_SERVER['argv']; require_once("db.php"); $query="select title from file where url='".$argv[1]."'"; if($mysqli->multi_query($query)){ do{ if($result=$mysqli->store_result()){ while($row = $result->fetch_row()){ printf($row[0]); } $result->free(); } }while($mysqli->next_result()); } ?> get_artist.php is similar. Can anyone tell me if, for any reason, I should be doing things differently? This appears to work, but maybe this isn't the best code for the result I'm looking for. What this does is look up the artist and title in my playlist database if the "artist" and "title" metadata fields are blank according to Liquidsoap's assessment. Damien On 06/29/12 00:12, liq...@ao... wrote: > On Thu, 28 Jun 2012 18:24:18 -0400, Audiodef Online > <on...@au...> wrote: > >> I think I've figured it out: >> >> #!/usr/local/bin/liquidsoap -t >> >> set("log.file.path","/home/audiodef/radio/liquidradio.log") >> set("log.level",4) >> >> main_radio=mksafe(playlist(timeout=3600.,conservative=true,"http://synthetronica/radio/main_playlist")) >> >> >> def append_artist(m) = >> artist = m["artist"] >> if artist == "" then [("artist","Synthetronica Radio")] else >> [("artist","Synthetronica Radio: #{artist}")] end >> end >> def append_title(m) = >> title = m["title"] >> if title == "" then [("title","Various Artists")] else >> [("title","#{title}")] end >> end >> >> main_radio = map_metadata(append_artist, main_radio) >> main_radio = map_metadata(append_title, main_radio) >> >> output.icecast(%vorbis(quality=0.6,samplerate=44100), >> host="localhost", port=8000, >> password="(password)", mount="radio.ogg", name="Synthetronica >> Radio", >> description="Eclectic Electronica", genre="Electronic", >> url="synthetronica", >> main_radio) >> >> It seems to me that all I need to do now is figure out how to call an >> external script from inside the defs, where the external script looks up >> the currently playing file in a database and returns the artist and >> title. Where do I get the currently playing file name? Is there an >> m["filename"]? >> >> Thanks, >> Damien > > > Hi Damien, > > My setup is somewhat unique in that for any given program, I would > have up to fifty episodes, but only one is played each day. Via > crontab, I would load each show with its unique episode (for example, > 'c', in code below 'today-special-mp3-32.pls'). For these 'special' > programs, I needed the day's unique title. The db field for special > programs is never blank. But if it were, I would use php to locate > any, and add an additional elsif below in the following code. > > > > #{content} is derived from a db search for the current show's title > field using a php system call: 'system("echo $title > > /usr/local/www/rcr/radio/current/special/mp3/title.txt");' > > This is rather clumsy code, but I only use it once daily, and it > works. If I needed a more elegant approach for multiple shows, I could > simply derive it for each entry, from db's 'title' field, but as I > said, this is a quick fix for me. > > > > This sounds a lot more complicated than it is. > > > > # === SP === > > > a = single("/usr/local/www/rcr/mp3/announce/TOHS.mp3") > > b = > single("/usr/local/www/rcr/mp3/announce/opener/opener-sp.mp3") > > c = playlist.safe(mode="normal", > "/usr/local/www/rcr/radio/current/special/mp3/today-special-mp3-32.pls") > > d = single("/usr/local/www/rcr/mp3/announce/CLOSER.mp3") > > e = playlist.safe(mode="normal", > "/usr/local/www/rcr/radio/current/mp3/sp-mp3-end.pls") > > > > > sp = sequence([a,b,c,d,e]) > > > > # Fill-in Title for ID3 Tag > > def fill_in(s) > > # the function f takes a list of pairs m representing the > metadata > # and it maps an anonymous function on each pair > # replacing empty title definitions by title=filename > > def f(m) > > print("\n\nFor metadata: #{m}\n\n") > list.map(fun (key_value) -> > > if key_value==("title","") then > > > if m["filename"] == > "/usr/local/www/rcr/mp3/announce/TOHS.mp3" then > ("title", "Rural Catholic Radio - from the > heartland, with love") > > elsif m["filename"] == > "/usr/local/www/rcr/mp3/announce/opener/opener-sp.mp3" then > ("title", "Welcome to this Special Program") > > elsif m["filename"] == > "/usr/local/www/rcr/radio/current/special/mp3/today-special-mp3-32.pls" then > > content = list.hd(get_process_lines("cat > /usr/local/www/rcr/radio/current/special/mp3/title.txt")) > ("title", "Special Program - #{content}") > > elsif m["filename"] == > "/usr/local/www/rcr/mp3/announce/CLOSER.mp3" then > ("title", "Thank you for listening to this > Special Program") > > elsif m["filename"] == > "/usr/local/www/rcr/radio/current/mp3/sp-mp3-end.pls" then > ("title", "Interlude - Music by Eric Genuis") > > else > content = list.hd(get_process_lines("cat > /usr/local/www/rcr/radio/current/special/mp3/title.txt")) > ("title", "Special Program - #{content}") > > end > > else key_value end, > m) > > end > > map_metadata(f,s) > > end > > > sp = fill_in(sp) > > Hth > >> >> On 06/28/12 20:47, Audiodef Online wrote: >>> Thanks! I understand the logic of that code, but this made me realize I >>> don't know how to make static metadata replacement work. I need to >>> understand that before proceeding with hooking into external scripts. >>> After spending some time looking around and experimenting, I've >>> modified >>> my script to this: >>> >>> #!/usr/local/bin/liquidsoap -t >>> >>> set("log.file.path","/home/audiodef/radio/liquidradio.log") >>> set("log.level",4) >>> >>> main_radio=mksafe(playlist(timeout=3600.,conservative=true,"http://synthetronica/radio/main_playlist")) >>> >>> >>> pattern = '$(if $(display_artist),"Synthetronica Radio","Synthetronica >>> Radio: $(artist)")' >>> main_radio=rewrite_metadata([("artist",pattern)],main_radio) >>> pattern = '$(if $(display_title),"Various Artists","$(title)")' >>> main_radio=rewrite_metadata([("title",pattern)],main_radio) >>> >>> output.icecast(%vorbis(quality=0.6,samplerate=44100), >>> host="localhost", port=8000, >>> password="(password)", mount="radio.ogg", name="Synthetronica >>> Radio", >>> description="Eclectic Electronica", genre="Electronic", >>> url="synthetronica", >>> main_radio) >>> >>> This works - technically. But it doesn't do what I want, because the >>> fields display_artist and display_title exist for many of the tracks in >>> my playlist, but are empty. How do I modify this script so that if >>> these >>> fields do not exist, or they do exist but are empty, my stream should >>> say "Synthetronica Radio - Various Artists" in Audacious (or whatever >>> media player)? >>> >>> Once I understand how to do this, I'll be ready to proceed to calling >>> external scripts. I would really appreciate any help on this part. >>> >>> Also, is there a page documenting all of the metadata fields? The only >>> reason I know about display_artist and display_title is because it was >>> in an example in the documentation. I haven't found these anywhere >>> else, >>> so I'm hoping I simply did not know where to look. >>> >>> Thanks! >>> Damien >>> >>> >>> >>> On 06/27/12 23:46, liq...@ao... wrote: >>>> If it's any help, I use the following to get the value of the current >>>> title from >>>> a database entry (where 'title.txt' is a returned value): >>>> >>>> >>>> elsif m["filename"] == >>>> "/usr/local/www/rcr/radio/current/special/mp3/today-special-mp3-32.pls" >>>> then >>>> >>>> content = list.hd(get_process_lines("cat >>>> /usr/local/www/rcr/radio/current/special/mp3/title.txt")) >>>> ("title", "Special Program - #{content}") >>>> >>>> Hth >>>> >>>> >>>> On Wed, 27 Jun 2012 17:10:16 -0400, Audiodef Online >>>> <on...@au...> wrote: >>>> >>>>> Thanks, Martin. >>>>> >>>>> But I have to confess to not knowing how to use this: >>>>> >>>>> (string)->[string] >>>>> >>>>> Perform a shell call and return the list of its output lines. >>>>> >>>>> (unlabeled) (string) >>>>> >>>>> I don't need hand-holding, but I learn best from examples. Is there >>>>> an example >>>>> somewhere I can read to see how it actually works in practice? >>>>> >>>>> Thanks, >>>>> Damien >>>>> >>>>> >>>>> On 06/27/12 20:32, Martin Konečný wrote: >>>>> >>>>> Look up "get_process_lines" function call. >>>>> >>>>> >>>>> http://savonet.sourceforge.net/doc-1.0.0/reference.html >>>>> >>>>> >>>>> >>>>> >>>>> O Wed, Jun 27, 2012 at 4:29 PM, Audiodef Online <on...@au...> >>>>> wrote: >>>>> >>>>> Is it possible to have a LS script execute an external script, >>>>> wait for >>>>> the external script to return a value, and use that value? >>>>> >>>>> Specifically, I would like my LS script to parse the stream's >>>>> metadata. >>>>> If the metadata has the literal string "unknown" (case >>>>> insensitive) as >>>>> the title of the track, then the LS script should execute a PHP >>>>> script >>>>> (via CGI, of course) and store the result of that script (which >>>>> would be >>>>> exactly one value - a string) and then set the metadata of the >>>>> current >>>>> track with the string retrieved from the PHP script. >>>>> >>>>> Can I do this? How would it be done? >>>>> >>>>> -- >>>>> My music: http://audiodef.com >>>>> Synthetronica: http://synthetronica.com >>>>> Male survivors of domestic violence: http://abusedmen.org >>>>> >>>>> >>>>> ------------------------------------------------------------------------------ >>>>> >>>>> >>>>> Live Security Virtual Conference >>>>> Exclusive live event will cover all the ways today's security and >>>>> threat landscape has changed and how IT managers can respond. >>>>> Discussions >>>>> will include endpoint security, mobile security and the latest in >>>>> malware >>>>> threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/ >>>>> _______________________________________________ >>>>> Savonet-users mailing list >>>>> Sav...@li... >>>>> https://lists.sourceforge.net/lists/listinfo/savonet-users >>>>> >>>>> >>>>> >>>> >>> >> >> > > -- My music:http://audiodef.com Synthetronica:http://synthetronica.com Male survivors of domestic violence:http://abusedmen.org |