]> gitweb.maison.local Git - podcast-rf.git/commitdiff
First attempt to clean things
authorlionel G <lionel@stargate.enneade.fdn.org>
Wed, 4 May 2016 14:44:17 +0000 (16:44 +0200)
committerlionel G <lionel@stargate.enneade.fdn.org>
Wed, 4 May 2016 14:44:17 +0000 (16:44 +0200)
podcast.py

index 573db040cda683a0fc6be5c4589ba11bf0b52761..64d4c8940daf04470ccb80300870abe0552c6fec 100755 (executable)
@@ -4,37 +4,15 @@
 
 import pycurl,sys,taglib,signal,os
 
+# Based on the old 'download.py' that was used for one show
 
+# TODO :
+# - lire les .xml dans rss/ et afficher la liste des <title> disponibles
+# - ajouter les options en ligne de commande pour choisir l'émission
+# - touch des fichiers télécharger dans archives/emissions/xx
+# - commande pour rafraichir les fichiers xml en fonction des *.url
 
-#<item>
-#<title>Le moment Meurice 28.10.2015</title>
-#<link>http://www.radiofrance.fr/</link>
-#<description>durée : 00:05:12 - SI TU ECOUTES J'ANNULE TOUT - par : Guillaume MEURICE</description>
-#<author>podcast@radiofrance.com</author>
-#<category >News &amp; Politics </category>
-#<enclosure url="http://rf.proxycast.org/1089658063113166848/13942-28.10.2015-ITEMA_20827962-4.mp3" length="6033408" type="audio/mpeg"  />
-#<guid >http://media.radiofrance-podcast.net/podcast09/13942-28.10.2015-ITEMA_20827962-4.mp3</guid>
-#<pubDate>Wed, 28 Oct 2015 17:30:00 +0100</pubDate>
-#<podcastRF:businessReference>23173</podcastRF:businessReference>
-#<podcastRF:magnetothequeID>2015F23173S0301</podcastRF:magnetothequeID>
-#<podcastRF:stepID>11341456</podcastRF:stepID>
-#<itunes:author>Guillaume MEURICE</itunes:author>
-#<itunes:explicit>no</itunes:explicit>
-#<itunes:keywords>Le,moment,Meurice,28.10.2015</itunes:keywords>
-#<itunes:subtitle>Émission du 28.10.2015</itunes:subtitle>
-#<itunes:summary>durée : 00:05:12 - par : Guillaume MEURICE</itunes:summary>
-#<itunes:duration>00:05:12</itunes:duration>
-#</item>
-
-
-# Seul nous intéresse :
-    # title             as titre
-    # description       as description
-    # guid              as guid
-    # itunes:subtitle   as subtitle
-    # itunes:duration   as duration
-    # pubDate           as pudDate (Fri, 30 Oct 2015 17:50:00 +0100)
-
+# Classe toute bête pour stocker les propriétés d'un mp3
 class item:
     titre = None
     description = None
@@ -42,19 +20,25 @@ class item:
     pudDate = None
     duration = None
 
+    # Ci-dessous : est-ce vraiment utile si on ne fait rien à l'init ?
     def __init__(self):
         pass
 
+# Classe emission : il faut lui passer l'emission issue de la ligne de commande
 class emmission:
     __currentNode__ = None
     __itemsList__ = None
 
-    def __init__(self):
-        self.readXml()
+    def __init__(self, xmlfile):
+        self.readXml(xmlfile)
 
-    def readXml(self):
+    def readXml(self, xmlfile):
         from xml.dom.minidom import parse
-        self.doc = parse('rss_13942.xml')
+        try:
+          self.doc = parse(xmlfile)
+        except:
+          print("XML file not found")
+          sys.exit(1)
 
     def getRootElement(self):
         if self.__currentNode__ == None:
@@ -85,11 +69,12 @@ class emmission:
     def getText(self, node):
         return node.childNodes[0].nodeValue
 
+# Ca fait quoi cette fonction ?
 def signal_handler(signal, frame):
     sys.stdout.write("\n")
     sys.exit(0)
-    
 
+# Ecrire les id3
 def tagid3(file,jour,mois,annee):
 # {'ALBUM': ['Le moment Meurice'],
 #  OU
@@ -106,7 +91,7 @@ def tagid3(file,jour,mois,annee):
 # 'TITLE': ['Le moment Meurice 13.11.2015'],
 #  OU
 # 'TITLE': ['Chasse au pinson 11.11.2015'],
-# 'LENGTH': ['00h05m17s']} 
+# 'LENGTH': ['00h05m17s']}
 
 
     retval = 1
@@ -131,11 +116,11 @@ if __name__ == "__main__":
 #    fenetre.move(0,0)
 #    fenetre.addch('*')   # prévoit l'écriture de '*' à la position du curseur
 #    fenetre.refresh()    # écrit réellement ce qui a été prévu par addch() et addstr()
-#    time.sleep(2)        # attend deux secondes avant de...
+#    time.sleep(2)        # attend deux secondes
 
 
-    x=emmission()
-    items=x.getitems()
+    x = emmission()
+    items = x.getitems()
     nb_items = len(items)
     j = 0
 
@@ -158,7 +143,7 @@ if __name__ == "__main__":
                 with open(name, 'wb') as f:
                   c = pycurl.Curl()
                   c.setopt(c.URL, str(i.guid))
-                  c.setopt(c.WRITEDATA, f) 
+                  c.setopt(c.WRITEDATA, f)
                   c.setopt(c.MAXREDIRS, 5)
                   c.setopt(c.NOPROGRESS, 1)
                   c.setopt(c.CONNECTTIMEOUT, 30)
@@ -190,4 +175,3 @@ if __name__ == "__main__":
 #                c.perform()
 #                c.close()
 #    sys.stdout.write("\nDone.\n")
-