Archive.org radio: Difference between revisions

From XPUB & Lens-Based wiki
No edit summary
m (moved Archive radio to Archive.org radio: clearer)
 
(6 intermediate revisions by the same user not shown)
Line 1: Line 1:
[[Feedparser]]
Play random tracks from archive.org's audio collection using [[Python]] and [[Feedparser]]


<source lang="python">
<source lang="python">
Line 16: Line 16:
for item in feed.entries:
for item in feed.entries:
     # pprint(item)
     # pprint(item)
     songurl = item['enclosures'][0]['href']
     try:
    print item.get('title')
        songurl = item['enclosures'][0]['href']
    print item.get('link')
        print item.get('title')
    os.system('mplayer -really-quiet "%s" 2> /dev/null' % songurl)
        print item.get('link')
 
        os.system('mplayer -really-quiet "%s" 2> /dev/null' % songurl)
    except KeyError:
        pass
     sleep(3)
     sleep(3)
     print
     print
   
</source>
</source>


Use Ctrl-C to go to the next song.
Regular Mplayer keys work as normal (left, right, up, down, space)
Ctrl-C twice to quit.
 
Use q, or ctrl-C to go to the next song.
Press Ctrl-C twice to quit.


[[Category: Cookbook]] [[Category: Audio]] [[Category: Python]] [[Category: RSS]]
[[Category: Cookbook]] [[Category: Audio]] [[Category: Python]] [[Category: RSS]] [[Category: Feedparser]]

Latest revision as of 15:03, 23 June 2011

Play random tracks from archive.org's audio collection using Python and Feedparser

#!/usr/bin/env python
#-*- coding:utf-8 -*-
  
import feedparser, os
from pprint import pprint
from time import sleep
from random import shuffle

feedurl = "http://www.archive.org/services/collection-rss.php?collection=audio_music"
feed = feedparser.parse(feedurl)
shuffle(feed.entries)

for item in feed.entries:
    # pprint(item)
    try:
        songurl = item['enclosures'][0]['href']
        print item.get('title')
        print item.get('link')
        os.system('mplayer -really-quiet "%s" 2> /dev/null' % songurl)
    except KeyError:
        pass
    sleep(3)
    print

Regular Mplayer keys work as normal (left, right, up, down, space)

Use q, or ctrl-C to go to the next song. Press Ctrl-C twice to quit.