Print podcasts and episodes

This commit is contained in:
Wiktor Zykubek 2023-06-18 17:37:10 +02:00
parent d02f7302a2
commit edc498c510
No known key found for this signature in database
GPG Key ID: 0DAA9DC01449FCA2
2 changed files with 62 additions and 19 deletions

27
form.ui
View File

@ -99,28 +99,37 @@
<attribute name="title"> <attribute name="title">
<string>Podcasty</string> <string>Podcasty</string>
</attribute> </attribute>
<widget class="QListWidget" name="podcastGroupsListWidget"> <widget class="QWidget" name="verticalLayoutWidget_2">
<property name="geometry"> <property name="geometry">
<rect> <rect>
<x>0</x> <x>-1</x>
<y>0</y> <y>-1</y>
<width>150</width> <width>151</width>
<height>400</height> <height>401</height>
</rect> </rect>
</property> </property>
<layout class="QVBoxLayout" name="verticalLayout_2">
<item>
<widget class="QListWidget" name="podcastGroupsListWidget"/>
</item>
<item>
<widget class="QListWidget" name="podcastListWidget">
<property name="minimumSize"> <property name="minimumSize">
<size> <size>
<width>150</width> <width>0</width>
<height>400</height> <height>195</height>
</size> </size>
</property> </property>
<property name="maximumSize"> <property name="maximumSize">
<size> <size>
<width>150</width> <width>16777215</width>
<height>400</height> <height>195</height>
</size> </size>
</property> </property>
</widget> </widget>
</item>
</layout>
</widget>
</widget> </widget>
</widget> </widget>
</item> </item>

View File

@ -30,7 +30,7 @@ class MainWindow(QMainWindow):
self.__stations = self.getData( self.__stations = self.getData(
"https://open.fm/radio/api/v2/ofm/stations_slug.json" "https://open.fm/radio/api/v2/ofm/stations_slug.json"
) )
self.__podcasts = self.getData( self.__podcasts_groups = self.getData(
"https://open.fm/api/podcasts/categories" "https://open.fm/api/podcasts/categories"
) )
self.__player = QMediaPlayer() self.__player = QMediaPlayer()
@ -41,6 +41,8 @@ class MainWindow(QMainWindow):
self.printPodcastGroups() self.printPodcastGroups()
self.ui.radioGroupsListWidget.itemClicked.connect(self.printRadioStations) self.ui.radioGroupsListWidget.itemClicked.connect(self.printRadioStations)
self.ui.podcastGroupsListWidget.itemClicked.connect(self.printPodcasts)
self.ui.podcastListWidget.itemClicked.connect(self.printPodcastEpisodes)
self.ui.stationsListWidget.itemClicked.connect(self.playRadio) self.ui.stationsListWidget.itemClicked.connect(self.playRadio)
self.ui.playbackToolButton.clicked.connect(self.togglePlayer) self.ui.playbackToolButton.clicked.connect(self.togglePlayer)
self.ui.volumeHorizontalSlider.valueChanged.connect(self.setVolume) self.ui.volumeHorizontalSlider.valueChanged.connect(self.setVolume)
@ -69,7 +71,7 @@ class MainWindow(QMainWindow):
def printPodcastGroups(self) -> None: def printPodcastGroups(self) -> None:
"""Print groups (categories) in podcastGroupsListWidget.""" """Print groups (categories) in podcastGroupsListWidget."""
self.ui.podcastGroupsListWidget.addItems( self.ui.podcastGroupsListWidget.addItems(
[e["name"] for e in self.__podcasts] [e["name"] for e in self.__podcasts_groups]
) )
def printRadioStations(self) -> None: def printRadioStations(self) -> None:
@ -89,6 +91,38 @@ class MainWindow(QMainWindow):
] ]
) )
def printPodcasts(self) -> None:
"""Print podcasts in podcastListWidget."""
group = self.ui.podcastGroupsListWidget.selectedItems()[0].text()
group_name = None
for e in self.__podcasts_groups:
if e["name"] == group:
group_name = e["slug"]
self.podcasts = self.getData(
f"https://open.fm/api/podcasts/category/{group_name}"
)["podcasts"]["content"]
self.ui.podcastListWidget.clear()
self.ui.podcastListWidget.addItems(
[e["title"] for e in self.podcasts]
)
def printPodcastEpisodes(self) -> None:
"""Print podcast episodes in stationsListWidget."""
podcast_name = self.ui.podcastListWidget.selectedItems()[0].text()
podcast_id = None
for e in self.podcasts:
if e["title"] == podcast_name:
podcast_id = e["id"]
episodes = self.getData(
f"https://open.fm/api/podcast/{podcast_id}/episodes"
)
self.ui.stationsListWidget.clear()
self.ui.stationsListWidget.addItems(
[e["title"] for e in episodes["content"]]
)
def setVolume(self, volume: int = None) -> None: def setVolume(self, volume: int = None) -> None:
"""Set playback volume to given number or slider value.""" """Set playback volume to given number or slider value."""
if not volume: if not volume: