def _get_list_podcasts(self, xml): tree = fromstring(xml) lis = tree.findall('li') podcasts = [] for p in lis: titulo = p.find('span/strong').text link = p.find('a').attrib['href'] url = p.find('span/a').attrib['href'] url_titulo = p.find('span/a').text busca_fecha = re.match('.*(\d\d\d\d)/(\d\d)/(\d\d).*', url) anio = int(busca_fecha.group(1)) mes = int(busca_fecha.group(2)) dia = int(busca_fecha.group(3)) nombre_archivo = link.split('/')[-1] fecha = datetime.date(anio, mes, dia) titulo = "%s" % (titulo,) podcast = Podcast() podcast.title = titulo podcast.date = fecha podcast.link = link podcast.description = url_titulo podcasts.append(self._get_p(podcast)) return podcasts
def add_subscription(): new_podcast = Podcast() new_podcast.name = request.json["name"] new_podcast.rss_feed_url = request.json["rss_feed_url"] db.session.add(new_podcast) db.session.commit() return jsonify(success=True)
def add_podcast_rssfeed(self, rssfeed): r = 0 if 'you2rss' in rssfeed: log.error("Not adding you2rss feed to you2rss!") return False print("Adding RSS feed: " + rssfeed) d = feedparser.parse(rssfeed) if d['status'] != 200: print("feedparser error: " + str(d['status'])) return False else: imageUrl = "" if 'href' in d.feed.image: imageUrl = d.feed.image['href'] publishedAt = timezone.datetime(2000, 12, 15) q = Podcast(title_text=d.feed.title, description_text=d.feed.description, thumbnail=imageUrl, rss_link=rssfeed, http_link=d.feed.link, pub_date=publishedAt, latest_pod=publishedAt) q.save() return q
def addEpisode(request): username = util.checkLoggedIn(request) if not username: return HttpResponseRedirect('/') error = "" if request.method == "POST": form = blogForms.newEpisodeForm(request.POST) title = request.POST['title'] showNotes = request.POST['showNotes'] episodeURL = '/podcasts/' + request.POST['episode'] size = request.POST['size'] audio_length = request.POST['duration'] if title and showNotes and episodeURL: published = datetime.datetime.now() if 'image' in request.FILES: image = request.FILES['image'] store = FileSystemStorage(paths.SITE_ROOT + '/images/') storedImage = store.save(image.name, image) imageURL = '/images/' + storedImage else: imageURL = None episode = Podcast(title = title, link = episodeURL, showNotes = showNotes, length = size, date = published, imageURL = imageURL, audio_length = audio_length) episode.save() return HttpResponseRedirect('/podcast') else: error = 'Something is amiss' else: form = blogForms.newEpisodeForm() # Renders the dashboard html page return render_to_response("dashboard/newEpisode.html", {'username':username, 'form':form, 'error':error}, context_instance =RequestContext(request))
def create_file(audiofiletype): audiofiletype = audiofiletype.lower() if audiofiletype == 'song': try: name = request.args.getlist('name')[0] duration = request.args.getlist('duration')[0] song = Song(name, duration) if not song.save(): return server_error return success except IndexError as e: print(e) print(request.args) return bad_request except Exception as e: print(e) return server_error elif audiofiletype == 'podcast': try: name = request.args.getlist('name')[0] duration = request.args.getlist('duration')[0] host = request.args.getlist('host')[0] participants = request.args.getlist('participants')[0] podcast = Podcast(name, duration, host, participants) if not podcast.save(): return server_error return success except IndexError as e: print(request.args) print(e) return bad_request except Exception as e: print(e) return server_error elif audiofiletype == 'audiobook': try: name = request.args.getlist('name')[0] duration = request.args.getlist('duration')[0] author = request.args.getlist('author')[0] narrator = request.args.getlist('narrator')[0] print(name, duration, author, narrator) audiobook = Audiobook(name, duration, author, narrator) if not audiobook.save(): return server_error return success except IndexError as e: print(e) print(request.args) return bad_request except Exception as e: print(e) return server_error else: return bad_request
def new_show(): # TODO: add podcast to database, redirect to stub page podcast = Podcast() podcast.url = request.form['url'] podcast.name = request.form['name'] db.session.add(podcast) db.session.commit() get_feed_info.delay(podcast.id) return redirect(url_for('show', show=podcast.id))
def create(): db.create_all() json_data = request.get_json() audio_file_type = json_data.get("audioFileType", None) audio_file_info = json_data.get("audioFileInfo", None) assert audio_file_type != None, "audioFileType is a required field" assert audio_file_type in Audio_File_Types, "audioFileType value is not supported" try: if audio_file_type == "Song": validate(instance=audio_file_info, schema=song_schema) db.session.add(Song(audio_file_info)) db.session.commit() elif audio_file_type == "Podcast": validate(instance=audio_file_info, schema=podcast_schema) db.session.add(Podcast(audio_file_info)) db.session.commit() else: validate(instance=audio_file_info, schema=audiobook_schema) db.session.add(Audiobook(audio_file_info)) db.session.commit() return jsonify({"message": "successfully inserted data"}), 200 except jsonschema.exceptions.ValidationError as e: return jsonify({"message": f"Invalid json: {e}"}), 400 except Exception as e: return jsonify({"message": f"{e}"}), 400
def create(audioFileType): if audioFileType == "song": upload_song = UploadSong(request) song = Song(name=upload_song.name, duration=upload_song.duration) db.session.add(song) db.session.commit() return song_schema.jsonify(song) if audioFileType == "podcast": upload_podcast = UploadPodcast(request) podcast = Podcast(name=upload_podcast.name, duration=upload_podcast.duration, host=upload_podcast.host, participants=upload_podcast.participants) db.session.add(podcast) db.session.commit() return podcast_schema.jsonify(podcast) if audioFileType == "audiobook": upload_audiobook = UploadAudiobook(request) audiobook = Audiobook(name=upload_audiobook.name, duration=upload_audiobook.duration, author=upload_audiobook.author, narrator=upload_audiobook.narrator) db.session.add(audiobook) db.session.commit() return audiobook_schema.jsonify(audiobook) return {"success!": "success"}
def populate_db(): """ Populates the database with the contents of the 'podcast_data.csv' file """ with open("./db/podcast_data_dump.csv", "r") as csvfile: reader = csv.DictReader(csvfile) for row in reader: p = Podcast(row["name"].decode('utf8'), row["author"], row["title"].decode('utf8'), row["image"], row["url"]) # if data has remote_id property then add to db if "remote_id" in row: p.remote_id = row["remote_id"] db_session.add(p) # commit changes to db db_session.commit() # close db session db_session.remove()
def subscribe_feed(podcasts, url): print("in!") podcast = Podcast(url) podcasts.update({podcast.name: podcast}) results = [] switch_to_bot = { "switch_pm_text": "订阅播客:" + podcast.name, "switch_pm_parameter": podcast.name, "cache_time": 0 } return results, switch_to_bot
def upload(): err_image = None err_audio = None img_folder = app.config['UPLOAD_IMAGE_FOLDER'] audio_folder = app.config['UPLOAD_AUDIO_FOLDER'] form = UploadPodcastForm() if form.validate_on_submit(): title = form.title.data image = form.image.data audio = form.audio.data description = form.description.data if not allowed_file(image.filename, IMAGE_ALLOWED_EXTENSIONS): err_image = 'Invalid image format, use ' + \ ', '.join(IMAGE_ALLOWED_EXTENSIONS) + ' instead.' elif not allowed_file(audio.filename, AUDIO_ALLOWED_EXTENSIONS): err_audio = 'Invalid audio format, use ' + \ ', '.join(AUDIO_ALLOWED_EXTENSIONS) + ' instead.' else: image_name = secure_filename(image.filename) img_path = os.path.join(img_folder, image_name) image.save(img_path) audio_name = secure_filename(audio.filename) audio_path = os.path.join(audio_folder, audio_name) audio.save(audio_path) new_podcast = Podcast( title=title, image=img_path, audio=audio_path, description=description, ) try: session.add(new_podcast) session.commit() flash('Uploaded') return redirect('/') except: session.rollback() return DATABASE_EXCEPTION try: return render_template('upload.html', form=form, err_image=err_image, err_audio=err_audio) except: abort(404)
def add_audio(audioFileType): title = request.json['title'] duration = request.json['duration'] if audioFileType == 'audiobook': author = request.json['author'] narrator = request.json['narrator'] new_audiobook = Audiobook(title, duration, author, narrator) new_audiobook.save() return audiobook_schema.jsonify(new_audiobook), 200 elif audioFileType == 'podcast': host = request.json['host'] participants = request.json['participants'] new_podcast = Podcast(title, duration, host, participants) new_podcast.save() return podcast_schema.jsonify(new_podcast), 200 elif audioFileType == 'song': new_song = Song(title, duration) new_song.save() return song_schema.jsonify(new_song), 200
def add_subscription(): new_podcast = Podcast() user_in_session = session['user'] username = db.session.query(Users).filter( Users.username == user_in_session).first() new_podcast.user_id = username.id new_podcast.podcast_API_id = request.json["podcast_id"] new_podcast.name = request.json["name"] new_podcast.rss_feed_url = request.json["rss_feed_url"] db.session.add(new_podcast) db.session.commit() return jsonify(success=True)
def create_audiofile( audiofile_type: schemas.AudioFileType, song: Optional[schemas.SongCreate] = None, podcast: Optional[schemas.PodcastCreate] = None, audiobook: Optional[schemas.AudiobookCreate] = None, ): if audiofile_type not in schemas.AudioFileType: raise HTTPException(status_code=400, detail="The request is invalid") if schemas.AudioFileType.song == audiofile_type: song.dict() db_audiofile = Song( name=song.name, duration=song.duration, uploaded_time=song.uploaded_time, ) if schemas.AudioFileType.podcast == audiofile_type: podcast.dict() db_audiofile = Podcast( name=podcast.name, duration=podcast.duration, uploaded_time=podcast.uploaded_time, host=podcast.host, participants=podcast.participants, ) if schemas.AudioFileType.audiobook == audiofile_type: db_audiofile = Audiobook( name=audiobook.name, author=audiobook.author, narrator=audiobook.narrator, duration=audiobook.duration, uploaded_time=audiobook.uploaded_time, ) db.session.add(db_audiofile) db.session.commit() db.session.refresh(db_audiofile) raise HTTPException(status_code=200, detail="Action is Successful") return db_audiofile
def refresh(): for rss in rss_links: parsed = podcastparser.parse(rss, urllib.request.urlopen(rss), 10) title = parsed.get('title') description = remove_html(parsed.get('description')) image = parsed.get('cover_url') link = parsed.get('link') podcast = Podcast.query.filter_by(link=parsed.get('link')).first() if (podcast is None): podcast = Podcast(title=title, description=description, image=image, link=link) db.session.add(podcast) db.session.commit() for episode in parsed.get('episodes'): episode_title = episode.get('title') episode_link = episode.get('link') episode_audio_url = episode.get('enclosures')[0]['url'] episode_time_published = episode.get('published') episode_length = episode.get('total_time') episode_podcast = podcast episode = Episode.query.filter_by( audio_url=episode_audio_url).first() if (episode is None): episode = Episode(title=episode_title, link=episode_link, audio_url=episode_audio_url, time_published=episode_time_published, length=episode_length, podcast=podcast) db.session.add(episode) db.session.commit()
async def podcast( podcast_cat : str, host_name: str, participants : List[str] = [], file: UploadFile = File(...), db: Session = Depends(get_db)): participant = jsonable_encoder(participants[0]) create_pod = {} create_pod["Name"]= file.filename create_pod["Podcast"] = podcast_cat create_pod["Duration"] = librosa.get_duration(filename= create_pod['Name']) create_pod["Uploaded_time"] = datetime.now() create_pod["Host"] = host_name create_pod["Participants"] = participant podcast = Podcast(**create_pod) db.add(podcast) db.commit() db.refresh(podcast) return podcast
def podcastfromdirectory(self, directory): name = directory log.info("Checking static podcast '" + name + "' from " + MAIN_DIR + directory) for podcast in Podcast.objects.all(): if podcast.title_text == name: log.info("Podcast " + name + " exists") return publishedAt = timezone.datetime(2000, 12, 15) q = Podcast(title_text=name, description_text="Add description", thumbnail="Add thumbnail", rss_link="http://www.hominem.se/you2rss/staticpod/" + urllib.quote(name), http_link=MAIN_DIR + directory + "/", pub_date=publishedAt, latest_pod=publishedAt, dynamic=False) q.save() q.rss_link = "http://www.hominem.se/you2rss/staticpod/" + str( q.id) + "/" q.save() self.update_static_pod(q)
def __init__(self, programa): log.debug("[PodcastFetch] programa: %s, hora: %s" % (programa, datetime.datetime.now())) self.programa = programa self.programa_id = Podcast.get_programa_id(programa) self.podcasts = None self._get_podcasts()
def add_pod(username): user = User.query.filter_by(username=username).first_or_404() form = AddPodcastForm() if form.validate_on_submit(): # save icon podicon = form.podicon.data filename = secure_filename(podicon.filename) podcast = Podcast(author=form.author.data, podname=form.podname.data, poddesc=form.poddesc.data, user_id=user.id, username=user.username, image_path=filename, it_own_name=form.it_own_name.data, it_own_email=form.it_own_email.data, it_cat=form.it_cat.data, it_subcat=form.it_subcat.data, it_sum=form.it_sum.data, it_subtitle=form.it_subtitle.data, it_keys=form.it_keys.data, it_explicit=form.it_explicit.data) podcast.buildtime = datetime.utcnow() db.session.add(podcast) db.session.commit() if os.path.exists(os.path.join(path, 'static/'+str(user.id)+'/'+str(podcast.id))): #podicon.save(os.path.join(path, 'static/'+str(user.id)+'/'+str(podcast.id), filename)) podicon.save(os.path.join(path, 'static/'+str(user.id)+'/'+str(podcast.id), filename)) elif os.path.exists(os.path.join(path, 'static/'+str(user.id))): os.mkdir(os.path.join(path, 'static/'+str(user.id)+'/'+str(podcast.id))) #podicon.save(os.path.join(path, 'static/'+str(user.id)+'/'+str(podcast.id), filename)) podicon.save(os.path.join(path, 'static/'+str(user.id)+'/'+str(podcast.id), filename)) else: os.mkdir(os.path.join(path, 'static/'+str(user.id))) os.mkdir(os.path.join(path, 'static/'+str(user.id)+'/'+str(podcast.id))) #podicon.save(os.path.join(path, 'static/'+str(user.id)+'/'+str(podcast.id), filename)) podicon.save(os.path.join(path, 'static/'+str(user.id)+'/'+str(podcast.id), filename)) # attempt to resize image to be square im = Image.open(os.path.join(path, 'static/'+str(user.id)+'/'+str(podcast.id), filename)) w,h = im.size rim = im.resize((min(w,h),min(w,h))) rim.save(os.path.join(path, 'static/'+str(user.id)+'/'+str(podcast.id), filename)) ######################################################################a # Add podcast link podcast.podlink = web_path +"/"+str(user.id)+"/"+str(podcast.id) # Create RSS rss = rss_lib.rss_create(podcast) # Save RSS rss_path = rss_lib.rss_save(rss,user,podcast) #podcast = Podcast.query.filter_by(id=pod_id).first_or_404() podcast.rsslink = rss_path db.session.commit() # commit updated rss link and podcast link ###################################################################### #flash('Congratulations, you added a podcast!') # return redirect(url_for('index')) return redirect(url_for('profile', pod_id=podcast.id, username=user.username)) return render_template('add_pod.html', title='Add Podcast', form=form)